MT#5879 Save state before switch to jsson getting of template info

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 12 years ago committed by Victor Seva
parent bf5d8ccf66
commit 174367338b

@ -19,11 +19,11 @@
<script type="text/javascript" src="/js/libs/svg-edit/embedapi.js"></script>
<script type="text/javascript" src="/js/background.js"></script>
<script type="text/javascript">
var svgCanvas = null;
var svgCanvasEmbed = null;
function init_embed() {
var svgEditFrameName = 'svgedit';
var frame = document.getElementById(svgEditFrameName);
svgCanvas = new EmbeddedSVGEdit(frame);
svgCanvasEmbed = new EmbeddedSVGEdit(frame);
// Hide main button, as we will be controlling new/load/save etc from the host document
var doc;
doc = frame.contentDocument;
@ -35,11 +35,11 @@ function init_embed() {
//mainButton.style.display = 'none';
}
function setSvgStringToEditor( svgParsedString ){
svgCanvas.setSvgString( svgParsedString )(
svgCanvasEmbed.setSvgString( svgParsedString )(
function(data,error){
if(error){
}else{
svgCanvas.zoomChanged('', 'canvas');
svgCanvasEmbed.zoomChanged('', 'canvas');
}
}
);
@ -130,15 +130,18 @@ function refreshTemplateList ( contract_id ){
function(){ mainWrapperInit(); }
);
}
function getSvgString(){
return svgCanvasEmbed.frame.contentWindow.svgCanvas.getSvgString();
}
function savePreviewedAndShowParsed( data ){
var svgString = svgCanvas.getSvgString(handleShowSvgParsedData);
var svgString = getSvgString();
var q = uriForAction( data, 'invoice_template_previewed' );
alert('svgString='+svgString+'; q='+q+';');
//alert('svgString='+svgString+'; q='+q+';');
//save
$.post( q, { template: svgString } )
.done( function( httpResponse ){
// & show template
alert('httpResponse='+httpResponse+';');
//alert('httpResponse='+httpResponse+';');
setSvgStringToPreview( httpResponse, q )
//refresh list after saving
@ -146,45 +149,8 @@ function savePreviewedAndShowParsed( data ){
} );
}
function handleShowSvgParsedData(svgString, error) {
if (error)
{
alert('error ' + error);
}
else
{
return svgString;
/*
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');
if ($.browser.msie) {
previewIframe.src = q;
}else{
//new Image();
var previewDoc = previewIframe.contentWindow.document;
var pages = new Array();
pages = svgParsedString.match(/(<svg[\r\n\t\s\S\w\W]*?(?:\/svg>))/gi );
if(!pages){
pages = new Array();
}
alert('images='+previewDoc.images.length+';pages='+pages.length);
if(pages.length > 0 ){
previewIframe.src = '';
previewDoc.body.innerHTML = '<html><body>'+svgParsedString+'</body></html>';
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);
}
}
});*/
}
}
function saveTemplate( contract_id, tt_id ) {
var svgString = svgCanvas.getSvgString();
var svgString = getSvgString();
var q = uriForAction( data, 'invoice_template_saved' );
$.post( q, { template: encodeURIComponent( svgString ) })
.done( function( httpResponse ) {
@ -280,6 +246,11 @@ function saveTemplate( contract_id, tt_id ) {
[%#It is reliable and easy to implement solution, but requires additional modules. For now populate small form with jquery.%]
[%# USE FillInForm %]
<div style="visibility:visible;" id="invoice_template_form">
<script>
function getTtIdVal(){
return $('form[name=invoice_template] input[name=tt_id]').val();
}
</script>
<form name="invoice_template" id="invoice_template" action="[%- c.uri_for_action('/customer/invoice_template', [contract.id]) -%]">
<input type="hidden" name="tt_id" value="">
<div class="ngcp-separator"></div>
@ -287,7 +258,7 @@ function saveTemplate( contract_id, tt_id ) {
<a class="btn btn-primary btn-large" onclick="
savePreviewedAndShowParsed({
contract_id:'[%contract.id%]',
tt_id: $('form[name=invoice_template] input[name=tt_id]').val()
tt_id: getTtIdVal(),
});void(0);">[% c.loc('Refresh Preview')%] <i class="icon-refresh"></i></a>
</span>
<span>
@ -303,7 +274,7 @@ function saveTemplate( contract_id, tt_id ) {
tt_viewmode: 'raw',
tt_sourcestate: '[%initial%]',
contract_id: '[%contract.id%]',
tt_id: $('form[name=invoice_template] input[name=tt_id]').val()
tt_id: getTtIdVal(),
});" width="550px" height="750px" style="border-width:0px;"></iframe><iframe
src="[%- c.uri_for_action('/customer/invoice_template', [contract.id]) -%]/svg/parsed/[%- initial -%]" id="svgpreview"
width="600px" height="750px" style="border-width:0px;"></iframe>

@ -33,7 +33,7 @@
<tr class="sw_action_row">
<td>[% template.get_column('is_active') %]</td>
<td>[% template.get_column('type') %]</td>
<td>=[%template.get_column('id')%]:[%- c.uri_for_action("/customer/invoice_template_delete", [contract.id, template.get_column('id')]) -%]= [%# template.get_column('name') %]</td>
<td>=[%- c.uri_for_action("/customer/invoice_template_delete", [contract.id, template.get_column('id')]) -%]= [%# template.get_column('name') %]</td>
<td class="ngcp-actions-column">
<div class="sw_actions">

Loading…
Cancel
Save