1. Complete embedding bitmap images
2. Change Work with layers - always show currently selecetd, apply initial display to others. Select first on start automatically.
3. Change preview work to fetch from server scheme, to enable preview in Explorer. Maybe should be applied only to Explorer?
ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 11 years ago committed by Victor Seva
parent c966c842de
commit db24de1c0d

@ -871,19 +871,11 @@ sub invoice_template_aux_embedImage :Chained('list_customer') :PathPart('auxembe
$c->log->debug('invoice_template_aux_handleImageUpload');
my($validator,$backend,$in,$out);
#$upload->basename;
#$upload->copy_to;
#$upload->fh;
#$upload->filename;
#$upload->headers;
#$upload->link_to;
#$upload->size;
#$upload->slurp;
#$upload->tempname;
#$upload->type;
#todo
#mime-type and type checking in form
$in = $c->request->parameters;
$in->{svg_file} = $c->request->upload('svg_file');
#$in->{}
if($in->{svg_file}) {
my $ft = File::Type->new();
$out->{image_content} = $in->{svg_file}->slurp;
@ -891,31 +883,10 @@ sub invoice_template_aux_embedImage :Chained('list_customer') :PathPart('auxembe
$out->{image_content_base64} = encode_base64($out->{image_content}, '');
}
$c->log->debug('mime-type '.$out->{image_content_mimetype});
#$c->response->body($in->{svg_file}->slurp);
$c->stash(out => $out);
$c->stash(in => $in);
$c->stash(template => 'customer/invoice_template_aux_embedimage.tt');
$c->detach( $c->view('SVG') );
#$c->log->debug('filename='.);
#$type = $_REQUEST['type'];
#if (!in_array($type, array('load_svg', 'import_svg', 'import_img'))) {
# exit;
#}
#require('allowedMimeTypes.php');
#$file = $_FILES['svg_file']['tmp_name'];
#$output = file_get_contents($file);
#$prefix = '';
#// Make Data URL prefix for import image
#if ($type == 'import_img') {
# $info = getimagesize($file);
# if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) {
# exit;
# }
# $prefix = 'data:' . $info['mime'] . ';base64,';
#}
}
sub invoice_data :Chained('base') :PathPart('invoice') :CaptureArgs(0) {
@ -938,55 +909,15 @@ sub invoice_data :Chained('base') :PathPart('invoice') :CaptureArgs(0) {
$invoice_details = [map{[$i++,$_]} (@$invoice_details) x 21];
$c->stash(invoice_details => $invoice_details );
}
#method separated as some day
sub invoice_template_list :Chained('invoice_data') :PathPart('') :CaptureArgs(0) {
my ($self, $c) = @_;
$c->log->debug('invoice_template_list');
my($validator,$backend,$in,$out);
#this is just copy-paste from method above
#of course we are chained and we can put in and out to stash
#input
$in->{contract_id} = $c->stash->{contract}->id;
#output
$out={};
#storage
#pass scheme here is ugly, and should be moved somehow to DB::Base
$backend = NGCP::Panel::Model::DB::InvoiceTemplate->new( schema => $c->model('DB') );
#input checking & simple preprocessing
$validator = NGCP::Panel::Form::Customer::InvoiceTemplate->new(backend => $backend);
# $form->schema( $c->model('DB::InvoiceTemplate')->schema );
#to common form package ? removing is necessary due to FormHandler param presence evaluation - it is based on key presence, not on defined/not defined value
#in future this method should be called by ControllerBase
$validator->remove_undef_in($in);
#really, we don't need a form here at all
#just use as already implemented fields checking and defaults applying
#$validator->setup_form(
$validator->process(
posted => 1,
params => $in,
);
#$validator->validate_form();
#multi return...
$c->log->debug("validated=".$validator->validated.";\n");
if(!$validator->validated){
return;
}
my $in_validated = $validator->fif;
#dirty hack 1
#really model logic should recieve validated input, but raw input also should be saved somewhere
$in = $in_validated;
#think about it more
#$out->{invoice_template_list} = $backend->getCustomerInvoiceTemplateList( %$in );
$c->stash( invoice_template_list => $backend->getCustomerInvoiceTemplateList( %$in )->all );
}
sub invoice :Chained('invoice_template_list') :PathPart('') :Args(0) {
my ($self, $c) = @_;
$c->stash(template => 'customer/invoice.tt');
@ -1013,15 +944,16 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#output
$out={};
#storage
#pass scheme here is ugly, and should be moved somehow to DB::Base
$backend = NGCP::Panel::Model::DB::InvoiceTemplate->new( schema => $c->model('DB') );
#input checking & simple preprocessing
$validator = NGCP::Panel::Form::Customer::InvoiceTemplate->new;
# $form->schema( $c->model('DB::InvoiceTemplate')->schema );
#to common form package ? removing is necessary due to FormHandler param presence evaluation - it is based on key presence, not on defined/not defined value
foreach ( keys %$in) { if(!( defined $in->{$_} )){ delete $in->{$_}; } };
#storage
#pass scheme here is ugly, and should be moved somehow to DB::Base
$backend = NGCP::Panel::Model::DB::InvoiceTemplate->new( schema => $c->model('DB') );
#really, we don't need a form here at all
#just use as already implemented fields checking and defaults applying
@ -1140,8 +1072,10 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#preShowCustomTemplate prerpocessing
{
#preShowInvoice
#even better - to template filters
#also to model
$out->{tt_string}=~s/(?:{\s*)?<!--{|}-->(?:\s*})?//gs;
$out->{tt_string}=~s/(<g .*?(id *=["' ]+(?:title|bg|mid)page["' ]+)?.*?)(?:display="none")(?(2)(?:.*?>)($2.*?>))/$1$3/gs;
}
if( ($in->{tt_output_type} eq 'svg') || ( $in->{tt_output_type} eq 'html') ){
@ -1204,9 +1138,7 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#my $cmd = "/tmp/wkhtmltox/bin/wkhtmltopdf $filename - ";
my $cmd = "rsvg-convert -f pdf ".join(" ", @pagefiles);
$c->log->debug($cmd);
#`chmod ugo+rwx $filename`;
#binmode(STDOUT);
#binmode(STDIN);
#$out->{tt_string} = `$cmd`;
@ -1220,7 +1152,6 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
}
$c->response->body($out->{tt_string});
return;
#$out->{tt_string} = `cat $filename `;
}

@ -934,10 +934,12 @@ TO-DOS
var selLayerNames = $('#selLayerNames').empty();
var drawing = svgCanvas.getCurrentDrawing();
var currentLayerName = drawing.getCurrentLayerName();
var layer = svgCanvas.getCurrentDrawing().getNumLayers();
var layersNum = svgCanvas.getCurrentDrawing().getNumLayers();
var icon = $.getSvgIcon('eye');
// we get the layers in the reverse z-order (the layer rendered on top is listed first)
while (layer--) {
var layer = 0;
//while (layer--) {
for (layer=0; layer < layersNum; layer++) {
var name = drawing.getLayerName(layer);
var layerTr = $('<tr class="layer">').toggleClass('layersel', name === currentLayerName);
var layerVis = $('<td class="layervis">').toggleClass('layerinvis', !drawing.getLayerVisibility(name));
@ -956,6 +958,14 @@ TO-DOS
$('#layerlist tr.layer').removeClass('layersel');
$(this.parentNode).addClass('layersel');
svgCanvas.setCurrentLayer(this.textContent);
var applyLayerEyeVisibility = function(){
var row = $(this.parentNode).prevAll().length;
var name = $('#layerlist tr.layer:eq(' + row + ') td.layername').text();
var vis = !$(this).hasClass('layerinvis');
svgCanvas.setLayerVisibility(name, vis);
};
$('#layerlist td.layervis').each(applyLayerEyeVisibility);
svgCanvas.setLayerVisibility(this.textContent, true);
evt.preventDefault();
})
.mouseover(function() {
@ -964,6 +974,7 @@ TO-DOS
.mouseout(function() {
toggleHighlightLayer();
});
$('#layerlist td.layername').first().mouseup();
$('#layerlist td.layervis').click(function() {
var row = $(this.parentNode).prevAll().length;
var name = $('#layerlist tr.layer:eq(' + row + ') td.layername').text();

@ -55,7 +55,10 @@ function handleShowSvgParsedData(svgString, error) {
var q = '[%- c.uri_for_action("/customer/invoice_template", [contract.id]) -%]'+'/svg/parsed/previewed';
$.post( q, { template: svgString })
.done( function( svgParsedString ) {
var previewIframe = document.getElementById('svgpreview'); //new Image();
var previewIframe = document.getElementById('svgpreview');
previewIframe.src = q;
/*
//new Image();
var previewDoc = previewIframe.contentWindow.document;
var pages = new Array();
pages = svgParsedString.match(/(<svg[\r\n\t\s\S\w\W]*?(?:\/svg>))/gi );
@ -66,10 +69,13 @@ function handleShowSvgParsedData(svgString, error) {
if(pages.length > 0 ){
previewIframe.src = '';
previewDoc.body.innerHTML = '<html><body>'+svgParsedString+'</body></html>';
alert(previewDoc.body.innerHTML);
previewIframe.src = "data:text/html," + encodeURIComponent(svgParsedString);
//previewDoc.body.innerHTML = '<html><body>'+svgParsedString+'</body></html>';
//alert(previewDoc.body.innerHTML);
}else{
previewIframe.src = "data:image/svg+xml," + encodeURIComponent(svgParsedString);
}
*/
});
}
}

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<script>
window.parent.window.svgEditor.processFile("data:[%out.image_content_mimetype%];base64,[%out.image_content_base64%]", "[%in.type%]");
window.parent.window.svgEditor.processFile("[%IF 'import_img' == in.type%]data:[%out.image_content_mimetype%];base64,[%END%][%out.image_content_base64%]", "[%in.type%]");
</script>
</head><body></body>
</html>

@ -67,12 +67,11 @@ g, text, tspan {
<!--{[%MACRO titlepage(callsdata, page) BLOCK-%]}-->
<!--page-->
<g y="0" x="0" width="215" height="297" id="titlepage">
<g y="0" x="0" width="215" height="297" id="titlepage" display="none">
<title>TitlePage</title>
<rect x="0" y="0" width="214.6" height="296.6" stroke-width="0.1" stroke="#FF0000" fill="#FFFFFF" id="totalborder"/>
<g y="10" x="10" width="100" height="30" transform="translate(10, 10)" >
<text x="2" y="5" font-family="'BoisterBlack'" >Test1 class text</text>
<text x="2" y="10" font-family="Serif">Test2 class text</text>
@ -148,7 +147,7 @@ g, text, tspan {
<!--{[%MACRO midpage(callsdata, page) BLOCK-%]}-->
<!--page-->
<g id="midpage">
<g id="midpage" display="none">
<title>MidPage</title>
<g y="15" x="10" width="195" height="150" id="midpage_invoicedetails" transform="translate(10, 15)" rows="15">
@ -195,7 +194,7 @@ g, text, tspan {
<!--{[%MACRO lastpage(callsdata, page) BLOCK-%]}-->
<!--page-->
<g id="lastpage">
<g id="lastpage" display="none">
<title>LastPage</title>
<g y="15" x="10" width="195" height="150" id="lastpage_invoicedetails" transform="translate(10, 15)">
@ -244,6 +243,7 @@ g, text, tspan {
<!--page-->
<g id="bgpage">
<title>Background</title>
<rect x="0" y="0" width="214.6" height="296.6" stroke-width="0.1" stroke="#FF0000" fill="#FFFFFF" id="totalborder"/>
<g y="270" x="5" width="205" height="18" transform="translate(5, 270)" class="address" id="bgpage_companyaddress_sipwise">
<rect x="0" y="0" width="205" height="18" stroke-width="0.25" fill="#FFFFFF" id="bgpage_companyaddress_sipwise__border"/>
<text x="2" y="5" id="bgpage_companyaddress_sipwise__company" class="company">{<!--{[%}-->provider.company<!--{%]}-->}</text>
@ -256,13 +256,11 @@ g, text, tspan {
<!--/page-->
<!--{[%END-%]}-->
<!--{[%MACRO document_footer BLOCK-%]}-->
<!--/pageSet-->
</svg>
<!--{[%END-%]}-->
<!--{[%# show_pages(invoice_details,'title')-%]}-->
<!--{[%# show_pages('mid',3)-%]}-->
<!--{[%# show_pages('last')-%]}-->

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Loading…
Cancel
Save