From d8a55f5909c7ee34fb2ce1d6585ca03c077caa27 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Tue, 11 Mar 2014 17:51:23 +0100 Subject: [PATCH] MT#5879 Mainly template changes to generate multipage document. now is generated, but with errors. Added rows as allowed attribute for stash(template => 'customer/details.tt'); $c->stash(contract => $contract_first); $c->stash(contract_rs => $contract_rs); - #$zonecalls_rs = [$zonecalls_rs->all()]; - #my @array = @$zonecalls_rs; + + #FAKE FAKE FAKE FAKE + $zonecalls_rs = [$zonecalls_rs->all()]; + my @array = @$zonecalls_rs; ##@array = (@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array); - #$zonecalls_rs = [@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array]; + $zonecalls_rs = [@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array]; ##$zonecalls_rs = [ 1..100 ]; + my $i = 1; + $zonecalls_rs = [map{[$i++,$_]}@$zonecalls_rs]; - #use irka; - #use Data::Dumper; - #irka::loglong(Dumper($zonecalls_rs) ); - - $c->stash(zonecalls_rs => $zonecalls_rs->all() ); + $c->stash(zonecalls_rs => $zonecalls_rs ); $c->stash(billing_mapping => $billing_mapping ); } @@ -837,8 +837,8 @@ sub calls :Chained('base') :PathPart('calls') :Args(0) { ); #my @array = $zonecalls_rs->all(); #s$zonecalls_rs = [@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array,@array]; - $c->stash(zonecalls_rs => $zonecalls_rs); - #$c->stash(zonecalls_rs => [1..100] ); + #$c->stash(zonecalls_rs => $zonecalls_rs); + $c->stash(zonecalls_rs => [1..100] ); } $c->stash(template => 'customer/calls.tt'); } @@ -970,7 +970,8 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args { #prepare response #mess,mess,mess here if($in->{tt_output_type} eq 'svg'){ - $c->response->content_type('image/svg+xml'); + $c->response->content_type('text/html'); +# $c->response->content_type('image/svg+xml'); }elsif($in->{tt_output_type} eq 'pdf'){ $c->response->content_type('application/pdf'); }elsif($in->{tt_output_type} eq 'html'){ diff --git a/share/static/js/libs/svg-edit/sanitize.js b/share/static/js/libs/svg-edit/sanitize.js index 3fe901e065..417941cc82 100644 --- a/share/static/js/libs/svg-edit/sanitize.js +++ b/share/static/js/libs/svg-edit/sanitize.js @@ -36,7 +36,7 @@ var svgWhiteList_ = { "feGaussianBlur": ["class", "color-interpolation-filters", "id", "requiredFeatures", "stdDeviation"], "filter": ["class", "color-interpolation-filters", "filterRes", "filterUnits", "height", "id", "primitiveUnits", "requiredFeatures", "width", "x", "xlink:href", "y"], "foreignObject": ["class", "font-size", "height", "id", "opacity", "requiredFeatures", "style", "transform", "width", "x", "y"], - "g": ["class", "clip-path", "clip-rule", "id", "display", "fill", "fill-opacity", "fill-rule", "filter", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "font-family", "font-size", "font-style", "font-weight", "text-anchor"], + "g": ["class", "clip-path", "clip-rule", "id", "display", "fill", "fill-opacity", "fill-rule", "filter", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "font-family", "font-size", "font-style", "font-weight", "text-anchor", "rows"], "image": ["class", "clip-path", "clip-rule", "filter", "height", "id", "mask", "opacity", "requiredFeatures", "style", "systemLanguage", "transform", "width", "x", "xlink:href", "xlink:title", "y"], "line": ["class", "clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "x1", "x2", "y1", "y2"], "linearGradient": ["class", "id", "gradientTransform", "gradientUnits", "requiredFeatures", "spreadMethod", "systemLanguage", "x1", "x2", "xlink:href", "y1", "y2"], diff --git a/share/static/js/libs/svg-edit/svgcanvas.js b/share/static/js/libs/svg-edit/svgcanvas.js index aa568b96a7..cc58ad57e7 100644 --- a/share/static/js/libs/svg-edit/svgcanvas.js +++ b/share/static/js/libs/svg-edit/svgcanvas.js @@ -4119,9 +4119,9 @@ this.svgToString = function(elem, indent) { if (elem.id === 'svgcontent') { //alert('QQQQQ'); //alert(svgroot.outerSvgTag); - if( svgroot.outerSvgTag ) + if( svgroot.outerSvgTagStart ) { - out.push(svgroot.outerSvgTag); + out.push(svgroot.outerSvgTagStart); }else{ out.push("<"); out.push(elem.nodeName); @@ -4194,7 +4194,6 @@ this.svgToString = function(elem, indent) { } - } else { out.push("<"); out.push(elem.nodeName); // Skip empty defs @@ -4278,7 +4277,12 @@ this.svgToString = function(elem, indent) { out.push("\n"); for (i = 0; i < indent; i++) {out.push(' ');} } - out.push(""); + if( elem.id === 'svgcontent' && svgroot.outerSvgTagEnd ) + { + out.push(svgroot.outerSvgTagEnd); + }else{ + out.push(""); + } } else { out.push("/>"); } @@ -4760,7 +4764,8 @@ this.setSvgString = function(xmlString) { svgroot.appendChild(svgcontent); //var startre=; //svgroot.outerSvgTag = outerSvgTag; - svgroot.outerSvgTag = xmlString.match(/\]*\>/); + svgroot.outerSvgTagStart = xmlString.match(/^(?:[\n\r\t\s]|.)*?(?:\]*\>/); + svgroot.outerSvgTagEnd = xmlString.match(/<\/svg>(?:[\n\r\t\s]|.)*$/); //console.log(outerSvgTag[0]); //alert(outerSvgTag[0]); //alert('svgroot.innerHTML='+svgroot.outerHTML); diff --git a/share/templates/customer/calls.tt b/share/templates/customer/calls.tt index ba5ca81e8e..58700eda5d 100644 --- a/share/templates/customer/calls.tt +++ b/share/templates/customer/calls.tt @@ -27,6 +27,7 @@ [%# Dumper.dump_html(zonecalls_rs.as_query)%] [% FOR call IN zonecalls_rs -%] + [%IF call.1; call = call.1; END%] [% total_number = total_number + call.get_column('number') %] [% total_duration = total_duration + call.get_column('duration') %] [% total_free_time = total_free_time + call.get_column('free_time') %] @@ -86,7 +87,7 @@ function init_embed() { } function loadSvg(params) { - //alert('[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+params); + alert('[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+params); background( '[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+params,'', function(httpResponse){ //alert(httpResponse); @@ -109,14 +110,58 @@ function handleShowSvgParsedData(data, error) { else { //alert('Congratulations. Your SVG string is back in the host page, do with it what you will\n\n' + data); - //alert(encodeURIComponent(data));//works in ie - background('[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+'/svg/parsed/previewed','template='+encodeURIComponent(data), + //alert(encodeURIComponent(data)); + var q = '[%- c.uri_for_action("/customer/calls_svg", [contract.id]) -%]'+'/svg/parsed/previewed'; + //alert(q); + //alert(data); + background( q ,'template='+encodeURIComponent(data), function(httpResponse){ //alert(httpResponse); - var img = document.getElementById('svgpreview'); //new Image(); - img.src = "data:image/svg+xml," + encodeURIComponent(httpResponse); - alert(img.outerHTML); - alert(img.html()); + var previewIframe = document.getElementById('svgpreview'); //new Image(); + + var previewDoc = previewIframe.contentWindow.document; + //if(previewIframe.contentDocument) { + // doc = previewIframe.contentDocument; + //} else { + // doc = previewIframe.contentWindow.document; + //} + //previewIframe.contentWindow.document.body.innerHTML=''; + //alert(doc); + + + var pages = new Array(); + pages = httpResponse.match(/())/gi ); + if(!pages){ + pages = new Array(); + } + alert('images='+previewDoc.images.length+';pages='+pages.length); + if(pages.length > 0 ){ + previewIframe.src = ''; + previewDoc.body.innerHTML = ''+httpResponse+''; + alert(previewDoc.body.innerHTML); + /* + var i; + for( i = 0; i < previewDoc.images.length; i++ ){ + var img = previewDoc.images[i]; + img.parentElement.remove(img); + } + + for( i = 0; i < pages.length; i++ ){ + img = previewDoc.createElement('img'); + //alert(img); + //img.width=215; + //img.heith=297; + img.src = "data:image/svg+xml," + encodeURIComponent(pages[i]); + } + alert('images='+previewDoc.images.length); + alert(previewDoc.body.innerHTML); + */ + }else{ + previewIframe.src = "data:image/svg+xml," + encodeURIComponent(httpResponse); + } + //alert(img.outerHTML); + //alert(img.html()); + } ); } diff --git a/share/templates/customer/calls_svg.tt b/share/templates/customer/calls_svg.tt index 14df645a3e..ce1323e7e1 100644 --- a/share/templates/customer/calls_svg.tt +++ b/share/templates/customer/calls_svg.tt @@ -1,5 +1,6 @@ + - + + TitlePage @@ -51,7 +52,8 @@ g { - Zone + # + Zone Number Duration Free time @@ -60,7 +62,9 @@ g { - Example zone + 1 + + Example zone 0 0.000 0.0 @@ -76,6 +80,7 @@ g { 0.00 + @@ -84,30 +89,106 @@ g { + - - + + + MidPage - + + + + + # + Zone + Number + Duration + Free time + Cost + + + + + 1 + + Example zone + 0 + 0.000 + 0.0 + 0.00 + + + + + Total: + 0 + 0.000 + 0.0 + 0.00 + + + + - + + + - + + + + LastPage - + + + + + + # + Zone + Number + Duration + Free time + Cost + + + + + 1 + + Example zone + 0 + 0.000 + 0.0 + 0.00 + + + + + Total: + 0 + 0.000 + 0.0 + 0.00 + + + + - + + + + Background @@ -118,14 +199,17 @@ g { Page {page} + + + - + - + + - + diff --git a/share/templates/customer/calls_template.tt b/share/templates/customer/calls_template.tt index 3d232e137b..f053b2d45d 100644 --- a/share/templates/customer/calls_template.tt +++ b/share/templates/customer/calls_template.tt @@ -1,5 +1,6 @@ [%USE Dumper%] [%USE Math%] + [%MACRO row_y_re(tt_type) BLOCK -%] [% IF tt_type == 'svg' -%] [% y_re = '(?s)(]*\s+y\s?=.*?)(\d+)(.*)' -%] @@ -24,7 +25,6 @@ [%page_rows_re%] [%END%] - [%MACRO get_row(data, rowtype) BLOCK -%] [%#use this macro until no symbolic references in tt %] [%#data can be empty, if we just need y - it doesn't depend on data %] @@ -75,8 +75,8 @@ [%END -%] [%END -%] - [%MACRO get_page_rows_number(pagetype, tt_type, row_vertical_interval) BLOCK-%] + in before get_page_rows_number [%#doesn't work %] [% page_rows_re = page_rows_re(tt_type) %] @@ -88,24 +88,28 @@ [% page = get_page(pagetype) %] [% matches = page.match( page_rows_re ) -%] - [%#page=Dumper.dump(page)%] - [%#page_rows_re=Dumper.dump(page_rows_re)%] - [%#matches=Dumper.dump(matches)%] + [%#page=Dumper.dump(page)%]=== + [%#page_rows_re=Dumper.dump(page_rows_re)%]=== + [%#matches=Dumper.dump(matches)%]=== + [% rows = matches.0 || matches.1 %] [%#IF !rows%] [%# all_g_y_re = page_y_re(tt_type) %] [%# matches = page.match( page_rows_re ) -%] [%#END%] - [%IF !rows ; rows = 10; END%] + [%#IF ! rows %][%# rows = 10%][%#END%] [%rows = Math.int(rows)%] [%rows%] [%END -%] - [%MACRO show_pages(zonecalls_rs, pagetype, pagenum_in) BLOCK-%] [% allrowsnumber = zonecalls_rs.size() %] - [% titlerows = get_page_rows_number('titlepage','svg') || 10 %] - [% midrows = get_page_rows_number('midpage','svg') || 30 %] + [% titlerows = get_page_rows_number('titlepage','svg') %] + titlerows=[%titlerows%]=== + [%IF titlerows== 0 ; titlerows = 10; END%] + [% midrows = get_page_rows_number('midpage','svg') %] + [%IF midrows == 0 ; midrows = 30 ; END%] + [% midrows = 2%] [% allmidpages = ( (allrowsnumber - titlerows) / midrows )|format('%d') %] [% allmidrows = allmidpages * midrows %] [% lastrows = allrowsnumber - allmidrows - titlerows %] @@ -117,18 +121,17 @@ [% document_footer()%] [%END-%] [%IF ( pagetype == 'mid' || pagetype=='all' ) && allmidrows %] - [% allmidpages = allmidrows / midrows %] - [% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. ${allmidpages} ] %] + [% pages = pagenum_in ? [ pagenum_in ] : [ 1 .. allmidpages ] %] [%FOREACH pagenum IN pages %] - [% pagerowsstart = titlerows + midrows*(pagenum - 1)%] - [% pagerowsend = titlerows + midrows*pagenum%] + [% pagerowsstart = titlerows + midrows * ( pagenum - 1 )%] + [% pagerowsend = titlerows + midrows * pagenum%] [% document_header()%] - [% midpage( zonecalls_rs.slice(pagerowsstart, pagerowsend )) -%] + [% midpage( zonecalls_rs.slice( pagerowsstart, pagerowsend )) -%] [% bgpage() -%] [% document_footer()%] [%END-%] [%END-%] - [%IF ( pagetype == 'last' || pagetype=='all' ) %] + [%IF ( pagetype == 'last' || pagetype=='all' )%] [% document_header()%] [% lastpage( zonecalls_rs.slice(lastrows) ) -%] [% bgpage() -%]