MT#5879 Changes according to Andreas letter.

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 12 years ago committed by Victor Seva
parent 088ca06ea7
commit 63c52f3180

@ -759,7 +759,7 @@ sub template_list :Chained('template_base') :PathPart('list') :Args(0) {
my ($self, $c) = @_;
$c->log->debug('template_list');
$c->forward( 'template_list_data' );
$c->stash( template => 'invoice/template_list.tt' );
$c->stash( template => 'invoice/template_list_alt.tt' );
$c->detach($c->view('SVG'));#just no wrapper - maybe there is some other way?
}
@ -768,6 +768,14 @@ sub template :Chained('template_base') :PathPart('') :Args(0) {
$c->forward('template_list_data');
$c->stash(template => 'invoice/template.tt');
}
sub template_alt :Chained('template_base') :PathPart('') :Args(1) {
my ($self, $c) = @_;
my $in={};
(undef,undef,$in->{tt_id}) = @_;
#for form hidden too. And for template_view.
$c->stash(tt_id => $in->{tt_id});
$c->stash(template => 'invoice/template_alt.tt');
}
sub template_view :Chained('template_base') :PathPart('view') :Args {
my ($self, $c) = @_;
@ -780,6 +788,8 @@ sub template_view :Chained('template_base') :PathPart('view') :Args {
#input
(undef,undef,@$in{qw/tt_type tt_viewmode tt_sourcestate tt_output_type tt_id/}) = @_ ;
$in->{provider_id} = $c->stash->{provider}->id;
$in->{tt_id} //= $c->request->parameters->{tt_id};
$in->{tt_id} //= $c->stash->{tt_id};
#$in->{client_id} = ;
$in->{tt_string} = $c->request->body_parameters->{template} || '';
foreach(qw/name is_active/){$in->{$_} = $c->request->parameters->{$_};}

@ -314,7 +314,11 @@ sub _handle_reseller_status_change {
sub details :Chained('base') :PathPart('details') :Args(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
my ($self, $c) = @_;
$c->stash(provider => $c->stash->{reseller}->first);
#didn't find a way to make it correct with chain
$c->forward('/invoice/template_list_data');
$c->stash(template => 'reseller/details.tt');
return;
}

@ -74,7 +74,8 @@ sub convertSvg2Pdf{
binmode B;
local $/ = undef;
$out->{tt_string_pdf} = <B>;
close B;
$c->log->error("Pipe: close: !=$!; ?=$?;");
close B or ($? == 0 ) or $c->log->error("Error closing rsvg pipe: close: $!;");
}
}
sub preprocessInvoiceTemplateSvg{

@ -1,5 +1,9 @@
//constructor
var svgCanvasEmbed = null;
var svgEditor = null;
function setNoSaveWarning(){
svgCanvasEmbed.frame.contentWindow.svgCanvas.undoMgr.resetUndoStack();
}
function init_embed() {
var svgEditFrameName = 'svgedit';
var frame = document.getElementById(svgEditFrameName);
@ -12,6 +16,7 @@ function init_embed() {
}
var mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none';
svgEditor = frame.contentWindow.svgEditor;
}
//private
function getSvgString(){
@ -24,12 +29,16 @@ function setSvgStringToEditor( svgParsedString ){
if(error){
}else{
svgCanvasEmbed.zoomChanged('', 'canvas');
setNoSaveWarning();
}
}
);
}
function setSvgStringToPreview( svgParsedString, q, data ) {
var previewIframe = document.getElementById('svgpreview');
var previewIframe = document.getElementById('svgpreview');
if(!previewIframe){
return;
}
//alert('setSvgStringToPreview: svgParsedString='+svgParsedString+';data='+data+';');
if ($.browser.msie) {
//we need to repeat query to server for msie if we don't want send template string via GET method
@ -109,7 +118,7 @@ function clearTemplateForm(data){
data.tt_sourcestate = 'default';
fetchInvoiceTemplateData(data, 1);//1 = no show form again, just clear it up to default state
}
function savePreviewedAndShowParsed( data ){
function savePreviewed( data, callback ){
var svgString = getSvgString();
var q = uriForAction( data, 'template_previewed' );
//alert('savePreviewedAndShowParsed: svgString='+svgString+'; q='+q+';');
@ -119,14 +128,43 @@ function savePreviewedAndShowParsed( data ){
$.post( q, { template: svgString } )
.done( function( httpResponse ){
// & show template
//alert('savePreviewedAndShowParsed: httpResponse='+httpResponse+';');
setSvgStringToPreview( httpResponse, q, data )
//alert('savePreviewed: httpResponse='+httpResponse+';');
//alert('savePreviewed: callback='+callback+'; typeof='+(typeof callback)+';');
//setSvgStringToPreview( httpResponse, q, data )
if(typeof callback == 'function'){
//alert('savePreviewed.1: callback='+callback+'; typeof='+(typeof callback)+';');
callback(httpResponse, q, data);
}else{
eval(callback);
}
//$('#load_previewed_control').css('display', 'inline' );
//refresh list after saving - there is nothin that can be cahnged in templates list after preview refresh
//refreshAjaxList( 'template', data );
} );
}
function saveTemplate( data ) {
function savePreviewedAndShowParsed( data ){
savePreviewed(data, setSvgStringToPreview );
//var svgString = getSvgString();
//var q = uriForAction( data, '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, data )
// //$('#load_previewed_control').css('display', 'inline' );
// //refresh list after saving - there is nothin that can be cahnged in templates list after preview refresh
// //refreshAjaxList( 'template', data );
//} );
}
function saveTemplate( data, callback ) {
var svgString = getSvgString();
data.tt_sourcestate='saved';
data.tt_output_type = 'json';
@ -143,6 +181,13 @@ function saveTemplate( data ) {
$('form[name=template_editor]').loadJSON(jsonResponse.aaData.form);
}
$('#load_saved_control').css('display', 'inline' );
if(typeof callback == 'function'){
//alert('saveTemplate.1: callback='+callback+'; typeof='+(typeof callback)+';');
callback(jsonResponse, q, data);
}else{
eval(callback);
}
setNoSaveWarning();
//refreshAjaxList( 'template', data );
});
}

@ -28,7 +28,7 @@
[% MACRO modal_script BLOCK %]
<script>
var modalFormScript = function (repeat) {
var modalFormScript = function (formitem,repeat) {
$('#mod_edit').modal({keyboard: false, backdrop: 'static'});
$('.mod_close').click(function(event) {
[%IF m.close_target_direct%]
@ -58,7 +58,7 @@
processModalFormAjax($(this).parents('form'),function(status,form){
//alert('in callback: status='+status);
if( status == 'error' ){
modalFormScript();
modalFormScript(formitem);
}
if( status != 'error' ){
//form object is necessary to compose uri for refresh

@ -22,7 +22,7 @@
<a class="btn btn-primary btn-large" href="[% c.uri_for('/back') %]"><i class="icon-arrow-left"></i> [% c.loc('Back') %]</a>
</span>
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for_action('invoice/template', [provider.id]) %]">[% c.loc('Invoice Template')%] <i class="icon-edit"></i></a>
<a class="btn btn-primary btn-large" href="[% c.uri_for_action('invoice/template_alt', [provider.id]) %]">[% c.loc('Invoice Template')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-large" onclick="javascript:$(this).css('outline', 'none');generateInvoiceForm();void(0);">[% c.loc('Generate invoice')%] <i class="icon-edit"></i></a>

@ -0,0 +1,52 @@
[% USE Dumper %]
[% USE format %]
[% money_format = format('%.2f') %]
[% write_access = 1 %]
[%PROCESS 'helpers/datatables_vars.tt'
no_auto_helper = 1
-%]
[%PROCESS 'helpers/modal.tt' -%]
[%mf_helper = {
ajax_load => 1,
ajax_list_refresh => 'template',
}%]
[%modal_script( m = mf_helper )%]
[% site_config.title = c.loc('Invoice template for [_1]', provider.name ) -%]
<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" src="/js/jquery.loadJSON.js"></script>
<script type="text/javascript" src="/js/jquery.serializeObject.js"></script>
<script type="text/javascript" src="/js/modalAjax.js"></script>
<script type="text/javascript" src="/js/invoice_template.js"></script>
[%PROCESS "invoice/uri_wrapper_js.tt"%]
<div class="row">
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for('/back') %]"><i class="icon-arrow-left"></i> [% c.loc('Back') %]</a>
</span>
<span>
<a class="btn btn-primary btn-large" href="[%- c.uri_for_action("/invoice/invoice_list", [provider.id]) -%]">[% c.loc('Invoices')%] <i class="icon-edit"></i></a>
</span>
</div>
[% IF reseller.first.status != "active" -%]
[%messages.unshift( c.loc('Reseller is <b>[_1]</b>', reseller.first.status) ); %]
[% END -%]
<div class="row" id="messages">
[%PROCESS 'helpers/ajax_messages.tt' -%]
</div>
<div class="ngcp-separator"></div>
[% back_created = 1 -%]
<div id="template_editor_form">
[%PROCESS 'invoice/template_editor_form_alt.tt' %]
</div>

@ -0,0 +1,106 @@
[%# USE FillInForm %]
<script>
function formToUri(q){
return q+'?'+$('form[id=template_editor]').serialize();
}
function formSerialize(){
return $('form[id=template_editor]').serialize();
}
function getTtIdVal(){
return $('form[id=template_editor] :input[name=tt_id]').val();
}
</script>
<form name="template_editor" id="template_editor" action="[%- c.uri_for_action('/invoice/template_view', [provider.id]) -%]" class="form-horizontal" enctype="multipart/form-data" method="post">
<input type="hidden" name="tt_id" value="[%tt_id%]">
<input type="hidden" name="provider_id" value="[%provider.id%]">
<span>
<a class="btn btn-primary btn-small" href="javascript:
var previewWindow = window.open('','_blank');
previewWindow.blur;
saveTemplate({
provider_id:'[%provider.id%]',
tt_id: getTtIdVal(),
},
function(httpResponse, q, data) {
previewWindow.location.href = uriForAction({
tt_sourcestate: 'saved',
tt_output_type : 'pdf',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',});
previewWindow.focus;
}
);
void(0);">[% c.loc('Preview')%] <i class="icon-edit"></i></a>
</span>
<span id="load_saved_control">
<a class="btn btn-secondary btn-small" data-confirm="[%c.loc('Overwrite changes');%]" href="javascript:fetchInvoiceTemplateData({
tt_sourcestate: 'saved',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',
});void(0);" cancel-hide="1">[% c.loc('Discard Changes')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-small" onclick="
//alert('tt_id='+getTtIdVal()+';');
saveTemplate({
provider_id: '[%provider.id%]',
tt_id: getTtIdVal(),
});void(0);">[% c.loc('Save template')%] <i class="icon-disk"></i></a>
</span>
[%IF viewmode == 'development' %]
<div class="ngcp-separator"></div>
<span>
<a class="btn btn-secondary btn-small" data-confirm="[%c.loc('Overwrite changes');%]" href="javascript:fetchInvoiceTemplateData({
tt_sourcestate: 'default',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',
});void(0);" cancel-hide="1">[% c.loc('Load default')%] <i class="icon-edit"></i></a>
</span>
<span id="load_previewed_control" style="display:none;visibility:hidden;">
<a class="btn btn-secondary btn-small" data-confirm="[%c.loc('Overwrite changes');%]" href="javascript:fetchInvoiceTemplateData({
tt_sourcestate: 'previewed',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',
});void(0);" cancel-hide="1">[% c.loc('Load previewed')%] <i class="icon-edit"></i></a>
</span>
<div class="ngcp-separator"></div>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'previewed',
tt_output_type : 'svg',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',
}),'_blank');void(0);">[% c.loc('Previewed SVG')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'saved',
tt_output_type : 'svg',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',
}),'_blank');void(0);">[% c.loc('Saved SVG')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-small" href="javascript:window.open(uriForAction({
tt_sourcestate: 'saved',
tt_output_type : 'pdf',
tt_id: getTtIdVal(),
provider_id: '[%provider.id%]',
}),'_blank');void(0);">[% c.loc('Saved PDF')%] <i class="icon-edit"></i></a>
</span>
[%END%]
[%initial = 'saved'%]
<div class="ngcp-separator"></div>
<iframe
type="text/html"
src="/js/libs/svg-edit/svg-editor.htm" id="svgedit" onload="
init_embed();
fetchSvgToEditor({
tt_viewmode: 'raw',
tt_sourcestate: '[%initial%]',
provider_id: '[%provider.id%]',
tt_id: getTtIdVal(),
});" width="1300px" height="1500px" style="border-width:0px;"></iframe>
</div>
</form>

@ -0,0 +1,54 @@
[% USE Dumper %]
[% USE format %]
[% money_format = format('%.2f') %]
[% IF !c.user.read_only && (c.user.roles == 'admin' || c.user.roles == 'reseller') -%]
[% write_access = 1 %]
[%END%]
<script>
var staticContainerId='template_list';
</script>
[%IF template_list.size %]
<table class="table table-bordered table-striped table-highlight table-hover">
<thead>
<tr>
<th>[% c.loc('Active') %]</th>
<th>[% c.loc('Id') %]</th>
<th>[% c.loc('Name') %]</th>
<th>[% c.loc('Type') %]</th>
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
[% FOR template IN template_list -%]
[%# Dumper.dump_html(template_list.as_query)%]
[%# Dumper.dump_html(template)%]
<tr class="sw_action_row" data-id="[%template.get_column('id')%]">
<td style="font-size: 20px;">[%IF template.get_column('is_active') > 0; '✓'; END%]</td><!--✓-->
<td>[% template.get_column('id') %]</td>
<td>[% template.get_column('name') %]</td>
<td>[% template.get_column('type') %]</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
[% IF write_access -%]
<a class="btn btn-small btn-primary"
onclick="fetch_into('template_info_form', '[%- c.uri_for_action("/invoice/template_info", [provider.id]) -%]','item=template_info&tt_id=[%template.get_column('id')%]',function(){modalFormScript();});void(0);
">
<i class="icon-edit"></i> [% c.loc('Edit template info') %]
</a>
<a class="btn btn-small btn-primary" href="[%- c.uri_for_action("/invoice/template_alt", [reseller.first.id, template.get_column('id')]) -%]">
<i class="icon-edit"></i> [% c.loc('Edit template') %]
</a>
<a class="btn btn-small btn-secondary ngcp-noback-button" data-confirm="Delete"
href="javascript:fetch_into(staticContainerId, '[%- c.uri_for_action("/invoice/template_delete", [provider.id, template.get_column('id')]) -%]','',function(){ refreshMessagesAjax();mainWrapperInit();});void(0);" cancel-hide="1">
<i class="icon-trash"></i> [% c.loc('Delete') %]
</a>
[%END%]
</div>
</td>
</tr>
[%END%]
</tbody>
</table>
[%END%]

@ -0,0 +1,38 @@
<script type="text/javascript">
var uriForAction = function( data, type ){
//we can think about getting URIs via ajax )
//also we can think about more regular wrapper for all uri used in datatables
var q_template;
switch(type){
case 'template_previewed':
//q_template = '[%- c.uri_for_action("/invoice/template_view", ['provider_id','svg','parsed','previewed','svg','tt_id']) -%]';
q_template = '[%- c.uri_for_action("/invoice/template_view", ['provider_id']) -%]'+'/svg/parsed/previewed/svg/tt_id';
break;
case 'template_saved':
//q_template = '[%- c.uri_for_action("/invoice/template_view", ['provider_id','svg','parsed','saved','svg','tt_id']) -%]';
q_template = '[%- c.uri_for_action("/invoice/template_view", ['provider_id']) -%]'+'/svg/parsed/saved/tt_output_type/tt_id';
break;
case 'template_list':
q_template = '[%- c.uri_for_action("/invoice/template_list", ['provider_id']) -%]';
break;
case 'messages':
q_template = '[%- c.uri_for_action("/invoice/messages") -%]';
break;
case 'template':
default:
//q_template = '[%- c.uri_for_action("/invoice/template_view", ['provider_id','tt_type','tt_viewmode','tt_sourcestate','tt_output_type','tt_id']) -%]';
q_template = '[%- c.uri_for_action("/invoice/template_view", ['provider_id']) -%]'+'/tt_type/tt_viewmode/tt_sourcestate/tt_output_type/tt_id';
break;
}
if(!data.tt_id){data.tt_id = '';}
if(!data.tt_type){data.tt_type = 'svg';}
if(!data.tt_output_type){data.tt_output_type = 'svg';}
if(!data.tt_viewmode){data.tt_viewmode = 'both';}
var params = ['provider_id','tt_id','tt_type','tt_output_type','tt_viewmode','tt_sourcestate'];
params.forEach(function(key){
q_template=q_template.replace(key,data[key]);
});
q_template=q_template.replace(/\/+$/,'');
return q_template;
}
</script>

@ -4,9 +4,6 @@
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for('/back') %]"><i class="icon-arrow-left"></i> [% c.loc('Back') %]</a>
</span>
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for_action('invoice/template', [reseller.first.id]) %]">[% c.loc('Invoice Template')%] <i class="icon-edit"></i></a>
</span>
<span>
<a class="btn btn-primary btn-large" href="[% c.uri_for_action('invoice/invoice_list', [reseller.first.id]) %]">[% c.loc('Invoices')%] <i class="icon-edit"></i></a>
</span>
@ -273,6 +270,37 @@
</div>
</div>
[% IF branding_edit_flag != 1 -%]
[%PROCESS 'helpers/modal.tt' -%]
[%mf_helper = {
ajax_load => 1,
ajax_list_refresh => 'template',
}%]
[%modal_script( m = mf_helper )%]
[%END%]
<script type="text/javascript" src="/js/background.js"></script>
<script type="text/javascript" src="/js/modalAjax.js"></script>
<script type="text/javascript" src="/js/jquery.serializeObject.js"></script>
[%PROCESS "invoice/uri_wrapper_js.tt"%]
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#invoice_template" href="#collapse_template_list">[% c.loc('Invoice Templates') %]</a>
</div>
<div class="accordion-body collapse" id="collapse_template_list">
<div class="ngcp-separator"></div>
<a class="btn btn-primary btn-large" onclick="$(this).css('outline', 'none');fetch_into('template_info_form', '[%- c.uri_for_action("/invoice/template_info", [provider.id]) -%]','item=template_info',function(){modalFormScript();});void(0);">[% c.loc('Create invoices template')%] <i class="icon-edit"></i></a>
<div class="ngcp-separator"></div>
<div class="accordion-inner" style="overflow:auto; height:300px;" id="template_list">
[%PROCESS 'invoice/template_list_alt.tt' %]
</div>
</div>
</div>
</div>
<div id="template_info_form">
</div>
[% IF branding_edit_flag == 1 -%]

Loading…
Cancel
Save