MT#5879 Datatables is shown now for invoice data but search doesn't work. Anyway switch now to invoices generation and will return to datatables later.
Done: 1.Form separated for future possible load through ajax. 2.Activity switch in invoice templates tableipeshinskaya/InvoiceTemplate5
parent
26142a1431
commit
f6fe84df61
@ -0,0 +1,124 @@
|
||||
//constructor
|
||||
var svgCanvasEmbed = null;
|
||||
function init_embed() {
|
||||
var svgEditFrameName = 'svgedit';
|
||||
var frame = document.getElementById(svgEditFrameName);
|
||||
svgCanvasEmbed = new EmbeddedSVGEdit(frame);
|
||||
// Hide main button, as we will be controlling new/load/save etc from the host document
|
||||
var doc = frame.contentDocument;
|
||||
if (!doc)
|
||||
{
|
||||
doc = frame.contentWindow.document;
|
||||
}
|
||||
//var mainButton = doc.getElementById('main_button');
|
||||
//mainButton.style.display = 'none';
|
||||
}
|
||||
//private
|
||||
function getSvgString(){
|
||||
return svgCanvasEmbed.frame.contentWindow.svgCanvas.getSvgString();
|
||||
}
|
||||
function setSvgStringToEditor( svgParsedString ){
|
||||
//alert('setSvgStringToEditor: '+svgParsedString);
|
||||
svgCanvasEmbed.setSvgString( svgParsedString )(
|
||||
function(data,error){
|
||||
if(error){
|
||||
}else{
|
||||
svgCanvasEmbed.zoomChanged('', 'canvas');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
function setSvgStringToPreview( svgParsedString, q, data ) {
|
||||
var previewIframe = document.getElementById('svgpreview');
|
||||
//alert('setSvgStringToPreview: svgParsedString='+svgParsedString+';');
|
||||
if ($.browser.msie) {
|
||||
//we need to repeat query to server for msie if we don't want send template string via GET method
|
||||
if(!q){
|
||||
var dataPreview = data;
|
||||
dataPreview.tt_viewmode = 'parsed';
|
||||
dataPreview.tt_type = 'svg';
|
||||
dataPreview.tt_sourcestate = dataPreview.tt_sourcestate || 'saved';
|
||||
q = uriForAction( dataPreview, 'invoice_template' );
|
||||
}
|
||||
previewIframe.src = q;
|
||||
}else{
|
||||
previewIframe.src = "data:text/html," + encodeURIComponent(svgParsedString);
|
||||
}
|
||||
}
|
||||
function fetchSvgToEditor( data ) {
|
||||
var q = uriForAction( data, 'invoice_template' );
|
||||
//alert('fetchSvgToEditor: q='+q+';');
|
||||
$.ajax({
|
||||
url: q,
|
||||
}).done( function ( httpResponse ){
|
||||
setSvgStringToEditor( httpResponse );
|
||||
});
|
||||
}
|
||||
function refreshTemplateList ( contract_id ){
|
||||
fetch_into(
|
||||
'collapse_invoice_template_list',
|
||||
uriForAction( {'contract_id': contract_id}, 'invoice_template_list' ),
|
||||
'',
|
||||
function(){ mainWrapperInit(); }
|
||||
);
|
||||
}
|
||||
//public
|
||||
function fetchInvoiceTemplateData( data ){
|
||||
//params spec: tt_type=[svg|html]/tt_viewmode[parsed|raw]/tt_sourcestate[saved|previewed|default]/tt_output_type[svg|pdf|html|json|svgzip|pdfzip|htmlzip]/tt_id
|
||||
//tt_output_type=svg really outputs text/html mimetype. But it will be couple of <svg> tags (<svg> per page).
|
||||
data.tt_output_type = 'json';
|
||||
var q = uriForAction( data, 'invoice_template' );
|
||||
//alert('fetchInvoiceTemplateData: q='+q+';');
|
||||
$.ajax({
|
||||
url: q,
|
||||
datatype: "json",
|
||||
//}).done( function( jsonres ){
|
||||
}).done( function( templatedata ){
|
||||
//alert(templatedata);
|
||||
//alert(templatedata.aaData);
|
||||
if(templatedata.aaData){
|
||||
if( templatedata.aaData.template ){
|
||||
setSvgStringToEditor( templatedata.aaData.template.raw );
|
||||
setSvgStringToPreview( templatedata.aaData.template.parsed );
|
||||
}
|
||||
if( templatedata.aaData.form ){
|
||||
$('form[name=invoice_template]').loadJSON(templatedata.aaData.form);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function savePreviewedAndShowParsed( data ){
|
||||
var svgString = getSvgString();
|
||||
var q = uriForAction( data, 'invoice_template_previewed' );
|
||||
//alert('savePreviewedAndShowParsed: svgString='+svgString+'; q='+q+';');
|
||||
//alert('savePreviewedAndShowParsed: q='+q+';');
|
||||
//save
|
||||
q=formToUri(q);
|
||||
$.post( q, { template: svgString } )
|
||||
.done( function( httpResponse ){
|
||||
// & show template
|
||||
//alert('savePreviewedAndShowParsed: httpResponse='+httpResponse+';');
|
||||
setSvgStringToPreview( httpResponse, q )
|
||||
//refresh list after saving
|
||||
refreshTemplateList( data.contract_id );
|
||||
} );
|
||||
}
|
||||
function saveTemplate( data ) {
|
||||
var svgString = getSvgString();
|
||||
data.tt_sourcestate='saved';
|
||||
data.tt_output_type = 'json';
|
||||
var q = uriForAction( data, 'invoice_template_saved' );
|
||||
q=formToUri(q);
|
||||
alert('saveTemplate: q='+q+';');
|
||||
$.ajax( {
|
||||
url: q,
|
||||
type: "POST",
|
||||
datatype: 'json',
|
||||
data: { template: svgString },
|
||||
} ).done( function( jsonResponse ) {
|
||||
if(jsonResponse.aaData && jsonResponse.aaData.form){
|
||||
$('form[name=invoice_template]').loadJSON(jsonResponse.aaData.form);
|
||||
}
|
||||
refreshTemplateList( data.contract_id );
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
[%#It can be separated later to form template and loaded with ajax and fillinform template::toolkit plugin. %]
|
||||
[%#It is reliable and easy to implement solution, but requires additional modules. For now populate small form with jquery.%]
|
||||
[%# USE FillInForm %]
|
||||
<script>
|
||||
function getTtIdVal(){
|
||||
return $('form[name=invoice_template] input[name=tt_id]').val();
|
||||
}
|
||||
function formToUri(q){
|
||||
return q+'?'+$('form[name=invoice_template]').serialize()
|
||||
}
|
||||
|
||||
</script>
|
||||
<form name="invoice_template" id="invoice_template" action="[%- c.uri_for_action('/customer/invoice_template', [contract.id]) -%]" class="form-horizontal" enctype="multipart/form-data" method="post">
|
||||
<input type="hidden" name="tt_id" value="">
|
||||
<div class="ngcp-separator"></div>
|
||||
[% IF write_access -%]
|
||||
<span>
|
||||
<a class="btn btn-primary btn-large" onclick="fetchInvoiceTemplateData({
|
||||
tt_sourcestate: 'default',
|
||||
contract_id: '[%contract.id%]',
|
||||
});void(0);">[% c.loc('Create from scratch')%] <i class="icon-edit"></i></a>
|
||||
</span>
|
||||
<div class="ngcp-separator"></div>
|
||||
[% END -%]
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="name">[%c.loc('Template name')%]</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="name" id="name" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="ngcp-separator"></div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="is_active">[%c.loc('Active')%]</label>
|
||||
<div class="controls" class="checkbox">
|
||||
<input type="checkbox" name="is_active" id="is_active" value="1" />
|
||||
</div>
|
||||
</div>
|
||||
<span>
|
||||
<a class="btn btn-primary btn-large" onclick="
|
||||
savePreviewedAndShowParsed({
|
||||
contract_id:'[%contract.id%]',
|
||||
tt_id: getTtIdVal(),
|
||||
});void(0);">[% c.loc('Refresh Preview')%] <i class="icon-refresh"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
<a class="btn btn-primary btn-large" onclick="
|
||||
//alert('tt_id='+getTtIdVal()+';');
|
||||
saveTemplate({
|
||||
contract_id:'[%contract.id%]',
|
||||
tt_id: getTtIdVal(),
|
||||
});void(0);">[% c.loc('Save template')%] <i class="icon-disk"></i></a>
|
||||
</span>
|
||||
<div class="ngcp-separator"></div>
|
||||
|
||||
[%initial = 'default'%]
|
||||
<iframe
|
||||
type="text/html"
|
||||
src="/js/libs/svg-edit/svg-editor.htm" id="svgedit" onload="
|
||||
init_embed();
|
||||
fetchSvgToEditor({
|
||||
tt_viewmode: 'raw',
|
||||
tt_sourcestate: '[%initial%]',
|
||||
contract_id: '[%contract.id%]',
|
||||
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>
|
||||
</div>
|
||||
</form>
|
||||
Loading…
Reference in new issue