diff --git a/lib/NGCP/Panel/Controller/Reseller.pm b/lib/NGCP/Panel/Controller/Reseller.pm index 44405110c3..480225f218 100644 --- a/lib/NGCP/Panel/Controller/Reseller.pm +++ b/lib/NGCP/Panel/Controller/Reseller.pm @@ -452,7 +452,6 @@ sub invoice_details :Chained('base') :PathPart('invoice') :CaptureArgs(0) { $invoice_details = [map{[$i++,$_]} (@$invoice_details) x 21]; $c->stash( invoice_details => $invoice_details ); $c->stash( invoice_details_raw => $invoice_details_raw ); - #$c->stash( invoice_template_form => $form ); } sub invoice_details_ajax :Chained('base') :PathPart('invoice/details/ajax') :Args(0) { my ($self, $c) = @_; @@ -466,7 +465,7 @@ sub invoice_details_ajax :Chained('base') :PathPart('invoice/details/ajax') :Arg NGCP::Panel::Utils::Datatables::process($c, $c->stash->{invoice_details_raw}, $dt_columns ); $c->detach( $c->view("JSON") ); } -sub invoice_template_form :Chained('base') :PathPart('invoice/template/form') :Args(0) { +sub invoice_template_info :Chained('base') :PathPart('invoice/template/info') :Args(0) { my ($self, $c) = @_; $c->log->debug($c->action); my($validator,$backend,$in,$out); @@ -492,8 +491,8 @@ sub invoice_template_form :Chained('base') :PathPart('invoice/template/form') :A $validator->remove_undef_in($in); #need to think how to automate it - maybe through form showing param through args? what about args for uri_for_action? #join('/',$c->controller,$c->action) - $validator->action( $c->uri_for_action('reseller/invoice_template_form',[$in->{contract_id}]) ); - $validator->name( 'invoice_template' );#from parameters + $validator->action( $c->uri_for_action('reseller/invoice_template_info',[$in->{contract_id}]) ); + $validator->name( 'invoice_template_info' );#from parameters #my $posted = 0; my $posted = exists $in->{submitid}; $c->log->debug("posted=$posted;"); @@ -506,7 +505,6 @@ sub invoice_template_form :Chained('base') :PathPart('invoice/template/form') :A ); my $in_validated = $validator->fif; if($posted){ - #$c->forward('invoice_template_save'); if($validator->validated) { try { $backend->storeInvoiceTemplateInfo(%$in_validated); @@ -532,7 +530,7 @@ sub invoice_template_form :Chained('base') :PathPart('invoice/template/form') :A $c->stash( m => {create_flag => !$in->{tt_id}} ); $c->stash( form => $validator ); #$c->stash( template => 'helpers/ajax_form_modal.tt' ); - $c->stash( template => 'invoice/invoice_template_form_modal.tt' ); + $c->stash( template => 'invoice/invoice_template_info_form.tt' ); $c->response->headers->header( 'X-Form-Status' => 'error' ); } }else{ @@ -541,7 +539,7 @@ sub invoice_template_form :Chained('base') :PathPart('invoice/template/form') :A $c->stash( m => {create_flag => !$in->{tt_id}} ); $c->stash( form => $validator ); #$c->stash( template => 'helpers/ajax_form_modal.tt' ); - $c->stash( template => 'invoice/invoice_template_form_modal.tt' ); + $c->stash( template => 'invoice/invoice_template_info_form.tt' ); } $c->detach( $c->view("SVG") );#to the sake of nowrapper } @@ -743,6 +741,7 @@ sub invoice_template :Chained('invoice_details') :PathPart('template') :Args { $out->{json} = { tt_data => { tt_id => $out->{tt_data}->get_column('id'), + base64_previewed => ( $out->{tt_data}->get_column('base64_previewed') ? 1 : 0), }, }; foreach(qw/name is_active/){ diff --git a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm index bf2e23db5a..585a93a1df 100644 --- a/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm +++ b/lib/NGCP/Panel/Model/DB/InvoiceTemplate.pm @@ -92,8 +92,8 @@ sub storeCustomerInvoiceTemplate{ $tt_record_created = $self->schema->resultset('invoice_templates')->create({ reseller_id => $contract_id, type => $tt_type, - is_active => $is_active, - name => $name, +# is_active => $is_active, +# name => $name, 'base64_'.$tt_sourcestate => $$tt_string, }); if($tt_record_created){ @@ -103,14 +103,14 @@ sub storeCustomerInvoiceTemplate{ my $conditions = $self->getDefaultConditions(\%params); $tt_record_updated = $self->schema->resultset('invoice_templates')->search($conditions); $tt_record_updated->update({ - is_active => $is_active, - name => $name, +# is_active => $is_active, +# name => $name, 'base64_'.$tt_sourcestate => $$tt_string, }); } - if($is_active && $tt_id){ - $self->deactivateOtherTemplates($contract_id,$tt_id); - } +# if($is_active && $tt_id){ +# $self->deactivateOtherTemplates($contract_id,$tt_id); +# } }); return { tt_id => $tt_id }; } diff --git a/share/static/css/main.css b/share/static/css/main.css index a4ae6d300a..259ae8682c 100644 --- a/share/static/css/main.css +++ b/share/static/css/main.css @@ -276,6 +276,11 @@ div.ngcp_dt_top_elements > div:first-child + div + div > div { text-align: center; } +.ngcp_current_edit td { + background: #dff0d8 !important; + background-color: #dff0d8 !important; +} + /* --------- sw_actions (Action Buttons) ------------*/ diff --git a/share/static/js/invoice_template.js b/share/static/js/invoice_template.js index ac375c56c9..efe34e66ae 100644 --- a/share/static/js/invoice_template.js +++ b/share/static/js/invoice_template.js @@ -54,27 +54,8 @@ function fetchSvgToEditor( data ) { setSvgStringToEditor( httpResponse ); }); } -function refreshAccordionAjaxList ( item, data ){ - alert('refreshAccordionAjaxList: q='+uriForAction( data, item + '_list' )+';item='+item); - var target = $('#'+ item + '_list'); - if(target){ - fetch_into( - item + '_list', - uriForAction( data, item + '_list' ), - '', - function(){ mainWrapperInit(); } - ); - } -} -function refreshMessagesAjax ( ){ - alert('refreshMessagesAjax: q='+uriForAction( {}, 'messages' )); - fetch_into( - 'messages', - uriForAction( {}, 'messages' ) - ); -} //public -function fetchInvoiceTemplateData( data ){ +function fetchInvoiceTemplateData( data, noshowform ){ //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 tags ( per page). data.tt_output_type = 'json'; @@ -92,13 +73,27 @@ function fetchInvoiceTemplateData( data ){ setSvgStringToEditor( templatedata.aaData.template.raw ); setSvgStringToPreview( templatedata.aaData.template.parsed ); } + $('#load_previewed_control').css('display', 'none' ); if( templatedata.aaData.form ){ - $('form[name=invoice_template]').loadJSON(templatedata.aaData.form); + $('form[name=invoice_template_editor]').loadJSON(templatedata.aaData.form); + if(templatedata.aaData.form.base64_previewed){ + $('#load_previewed_control').css('display', 'inline' ); + } + } + if( !noshowform ){ + $('#invoice_template_editor_form').css('display','block'); } - $('#invoice_template_form').css('display','block');//document.getElementById('invoice_template_form');; } }); } +function clearTemplateForm(data){ + $('#invoice_template_editor_form').css('display','none'); + if(!data){ + data = {}; + } + data.tt_sourcestate = 'default'; + fetchInvoiceTemplateData(data, 1); +} function savePreviewedAndShowParsed( data ){ var svgString = getSvgString(); var q = uriForAction( data, 'invoice_template_previewed' ); @@ -112,7 +107,7 @@ function savePreviewedAndShowParsed( data ){ //alert('savePreviewedAndShowParsed: httpResponse='+httpResponse+';'); setSvgStringToPreview( httpResponse, q ) //refresh list after saving - refreshAccordionAjaxList( 'invoice_template', data ); + refreshAjaxList( 'invoice_template', data ); } ); } function saveTemplate( data ) { @@ -129,58 +124,8 @@ function saveTemplate( data ) { data: { template: svgString }, } ).done( function( jsonResponse ) { if(jsonResponse.aaData && jsonResponse.aaData.form){ - $('form[name=invoice_template]').loadJSON(jsonResponse.aaData.form); + $('form[name=invoice_template_editor]').loadJSON(jsonResponse.aaData.form); } - refreshAccordionAjaxList( 'invoice_template', data ); + refreshAjaxList( 'invoice_template', data ); }); } -function processModalFormAjax( form, callback ) { - //preventDefault(); - alert(form.attr('action')+'?'+form.serialize()); - var item = form.attr('id'); - $.ajax( { - url: form.attr('action'), - type: "POST", - data: form.serialize(), - } ).done( function( responseText, textStatus, request ) { - /* - var headers = request.getAllResponseHeaders(); - var i =0; - alert('headers='+headers); - for(i=0; i 1, -}%] + ajax_load => 1, + ajax_list_refresh => 'invoice_template', + }%] [%modal_script( m = mf_helper )%] [% site_config.title = c.loc('Invoice template for [_1]', reseller.first.name) -%] @@ -19,6 +20,8 @@ + + -
@@ -66,7 +66,7 @@ var uriForAction = function( data, type ){ - [% c.loc('Create invoices template')%] + [% c.loc('Create invoices template')%]
@@ -129,12 +129,12 @@ var uriForAction = function( data, type ){ - -
+
diff --git a/share/templates/invoice/invoice_template_form.tt b/share/templates/invoice/invoice_template_editor_form.tt similarity index 64% rename from share/templates/invoice/invoice_template_form.tt rename to share/templates/invoice/invoice_template_editor_form.tt index 9928018f39..cd3ca3519b 100644 --- a/share/templates/invoice/invoice_template_form.tt +++ b/share/templates/invoice/invoice_template_editor_form.tt @@ -3,27 +3,18 @@ [%# USE FillInForm %] -
+ - - [% c.loc('Load default')%] - [% c.loc('Save template')%]
- + + [% c.loc('Load default')%] + + [%initial = 'default'%] +