MT#5879 Save some intermediate state. Started to implement fields checks, format a little calls.tt.

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 12 years ago committed by Victor Seva
parent 792b6a5328
commit a1cf4235ef

@ -16,6 +16,7 @@ use NGCP::Panel::Form::Customer::PbxGroup;
use NGCP::Panel::Form::Customer::PbxFieldDevice;
use NGCP::Panel::Form::Customer::PbxFieldDeviceEdit;
use NGCP::Panel::Form::Customer::PbxFieldDeviceSync;
use NGCP::Panel::Form::Customer::InvoiceTemplate;
use NGCP::Panel::Utils::Message;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::DateTime;
@ -840,17 +841,30 @@ sub loglong{
print $log Dumper($str);
close $log;
}
sub calls_svg :Chained('base') :PathPart('calls/template') :Args {
my ($self, $c, $tt_type, $tt_viewmode ) = @_;
my ($self, $c, $in);
($self,$c,@$in{qw/tt_type tt_viewmode tt_sourcestate/}) = @_;
#die();
#$c->view('SVG');
#handle request
$tt_viewmode //= '';
# my $tt_viewmode //= '';
# my $tt_state //= 'saved';
# my $tt_type //= 'svg';
my $invoicetemplate = $c->request->body_parameters->{template} || '';
$c->log->debug("1.invoicetemplate is empty=".($invoicetemplate?0:1).";viewbox=".($invoicetemplate !~/^<svg.*?viewbox.*?>/is ).";\n");
#$c->log->debug("1.invoicetemplate is empty=".($invoicetemplate?0:1).";viewbox=".($invoicetemplate !~/^<svg.*?viewbox.*?>/is ).";\n");
$c->log->debug("1.invoicetemplate is empty=".($invoicetemplate?0:1).";viewbox=".($invoicetemplate !~/^<svg.*?viewbox.*?>/is ).";\n");
my $form = NGCP::Panel::Form::Customer::InvoiceTemplate->new;
$form->process(
posted => 1,
params => $in,
action => $c->uri_for_action("/customer/calls_svg", [$c->stash->{contract}->id]),
);
$form->validate();
if(!$invoicetemplate){
#getCustomerActiveInvoiceTemplateFromDB.
}
@ -885,8 +899,8 @@ sub calls_svg :Chained('base') :PathPart('calls/template') :Args {
#prepare response
$c->response->content_type('image/svg+xml');
$c->log->debug("tt_viewmode=$tt_viewmode;\n");
if($tt_viewmode eq 'raw'){
$c->log->debug("tt_viewmode=".$in->{tt_viewmode}.";\n");
if($in->{tt_viewmode} eq 'raw'){
#$c->stash->{VIEW_NO_TT_PROCESS} = 1;
$c->response->body($invoicetemplate);
return;

@ -0,0 +1,69 @@
package NGCP::Panel::Form::Customer::InvoiceTemplate;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
enum 'TemplateType' => [ qw/svg/ ];#html
enum 'TemplateViewMode' => [ qw/raw parsed/ ];
enum 'TemplateSourceState' => [ qw/saved previewed/ ];
no Moose::Util::TypeConstraints;
#while use only for validation, no rendering is necessary
#use HTML::FormHandler::Widget::Block::Bootstrap;
#looks as often repeated
#has '+widget_wrapper' => ( default => 'Bootstrap' );
#sub build_form_element_class { [qw/form-horizontal/] }
#Attempt to use Moose to validation
#has 'sort_order' => (
# is => 'ro',
# isa => enum([qw[ ascending descending ]]),
#);
has_field 'tt_type' => (
# is => 'rw',
# isa => enum([qw[ svg ]]),#html
type => 'Text',
required => 0,
#apply => [ 'enum' ],
#apply => [ { check => [qw/svg/] } ],
apply => [ 'TemplateType' ],
);
has_field 'tt_viewmode' => (
type => 'Text',
required => 0,
);
has_field 'tt_sourcestate' => (
type => 'Text',
required => 1,
);
1;
=head1 NAME
NGCP::Panel::Form::InvoiceTemplate
=head1 DESCRIPTION
Form to modify a invoice template.
=head1 METHODS
=head1 AUTHOR
Irina Peshinskaya
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# vim: set tabstop=4 expandtab:

@ -5,6 +5,7 @@ use warnings;
use Sipwise::Base;
use DBIx::Class::Exception;
use NGCP::Panel::Utils::DateTime;
#use NGCP::Panel::Utils::DateTime;
sub getDefault{
my %params = @_;
@ -14,4 +15,24 @@ sub getDefault{
return ${$params{invoicetemplate}} = $c->view('SVG')->getTemplateContent($c, 'customer/calls_svg.tt');
}
sub getCustomerTemplate{
my %params = @_;
my $c = $params{c};
my $contract_id = $params{contract_id} || $c->stash->{contract}->id;
my $tt_state = $params{tt_state} || 'saved';
my $result;
my $template_record = $c->model('DB')->resultset('invoice_template')->search({
reseller_id => $contract_id,
is_active => 1,
})->first;
#here may be base64 decoding
if('saved' eq $tt_state){
$result = \$template_record->get_column('base64_'.$tt_state);
}
return $result;
}
1;

@ -1,7 +1,7 @@
function background(uri,q,callback) {
var xmlHttpReq = false;
alert(uri);
alert(q);
//alert(uri);
//alert(q);
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();

@ -85,19 +85,23 @@ function init_embed() {
mainButton.style.display = 'none';
}
function handleSvgData(data, error) {
if (error)
{
alert('error ' + error);
}
else
{
//alert('Congratulations. Your SVG string is back in the host page, do with it what you will\n\n' + data);
return data;
}
function loadSvg(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);
svgCanvas.setSvgString(httpResponse);
}
);
//'/customer/[%contract.id%]/calls/svg'
//var svgexample = '<svg width="640" height="480" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><g><title>Layer 1</title><rect stroke-width="5" stroke="#000000" fill="#FF0000" id="svg_1" height="35" width="51" y="35" x="32"/><ellipse ry="15" rx="24" stroke-width="5" stroke="#000000" fill="#0000ff" id="svg_2" cy="60" cx="66"/></g></svg>';
//svgCanvas.setSvgString(svgexample);
}
function showSvgDataParsed(data, error) {
function showSvgParsed(){
svgCanvas.getSvgString()(handleShowSvgParsedData);
}
function handleShowSvgParsedData(data, error) {
if (error)
{
alert('error ' + error);
@ -111,37 +115,32 @@ function showSvgDataParsed(data, error) {
//alert(httpResponse);
var img = document.getElementById('svgpreview'); //new Image();
img.src = "data:image/svg+xml," + encodeURIComponent(httpResponse);
});
}
);
}
}
function loadSvg(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);
svgCanvas.setSvgString(httpResponse);
}
);
//'/customer/[%contract.id%]/calls/svg'
//var svgexample = '<svg width="640" height="480" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><g><title>Layer 1</title><rect stroke-width="5" stroke="#000000" fill="#FF0000" id="svg_1" height="35" width="51" y="35" x="32"/><ellipse ry="15" rx="24" stroke-width="5" stroke="#000000" fill="#0000ff" id="svg_2" cy="60" cx="66"/></g></svg>';
//svgCanvas.setSvgString(svgexample);
}
function saveSvg() {
svgCanvas.getSvgString()(handleSvgData);
}
function showSvgParsed(){
svgCanvas.getSvgString()(showSvgDataParsed);
function handleSaveSvgData(data, error) {
if (error)
{
alert('error ' + error);
}
else
{
//alert('Congratulations. Your SVG string is back in the host page, do with it what you will\n\n' + data);
return data;
}
}
</script>
<button onclick="loadSvg('/svg/raw');">Reload invoice template</button>
<button onclick="loadSvg('/svg/raw/saved');">Load saved invoice template</button>
<button onclick="loadSvg('/svg/raw/previewed');">Load previewed template</button>
<button onclick="showSvgParsed();">Refresh Preview</button>
<button onclick="saveSvg();">Save template</button>
<br/>
<iframe type="text/html" src="/js/libs/svg-edit/svg-editor.htm" width="550px" height="600px" left="50px" id="svgedit" onload="init_embed();loadSvg('/svg/raw');" class="display:inline;"></iframe><iframe src="[%- c.uri_for_action('/customer/calls_svg', [contract.id]) -%]" width="550px" height="600px" id="svgpreview" class="display:inline;"><canvas id="svgpreview_canvas" width="200" height="200"></canvas>
[%initial = 'saved'%]
<iframe type="text/html" src="/js/libs/svg-edit/svg-editor.htm" width="600px" height="600px" id="svgedit" onload="init_embed();loadSvg('/svg/raw/[%- initial -%]');" class="display:inline;"></iframe><iframe src="[%- c.uri_for_action('/customer/calls_svg', [contract.id]) -%]/svg/parsed/[%- initial -%]" width="550px" height="600px" id="svgpreview" class="display:inline;"><canvas id="svgpreview_canvas" width="200" height="200"></canvas>

Loading…
Cancel
Save