From d1f80725774e32cb6703d44d4de9a111bad6b95f Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Fri, 16 Oct 2015 01:07:25 +0200 Subject: [PATCH] MT#15821 datatable custom mRender js functions +fix for profile package "initial balance" default value +fix for clearing the reseller id when editing billing profiles (related to MT#15399) Change-Id: I53954dd12061fa5ebc4bde7c1769a502e6f862fe --- lib/NGCP/Panel/Controller/Billing.pm | 12 +++++++----- lib/NGCP/Panel/Field/DataTable.pm | 2 ++ lib/NGCP/Panel/Field/ProfileNetwork.pm | 2 ++ lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm | 1 + lib/NGCP/Panel/Utils/Voucher.pm | 2 +- share/templates/helpers/datatables.tt | 7 ++++++- share/templates/helpers/datatables_field.tt | 10 +++++++--- share/templates/helpers/datatables_multifield.tt | 7 ++++++- 8 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Billing.pm b/lib/NGCP/Panel/Controller/Billing.pm index 243a3c5ec0..8117ecf21d 100644 --- a/lib/NGCP/Panel/Controller/Billing.pm +++ b/lib/NGCP/Panel/Controller/Billing.pm @@ -159,13 +159,15 @@ sub process_edit :Private { ); if($posted && $form->validated) { try { - if($c->user->is_superuser) { - $form->values->{reseller_id} = $form->values->{reseller}{id}; - } else { - $form->values->{reseller_id} = $c->user->reseller_id; + if (exists $form->values->{reseller}) { + if($c->user->is_superuser) { + $form->values->{reseller_id} = $form->values->{reseller}{id}; + } else { + $form->values->{reseller_id} = $c->user->reseller_id; + } + delete $form->values->{reseller}; } $form->values->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; - delete $form->values->{reseller}; my $old_prepaid = $c->stash->{profile_result}->prepaid; my $schema = $c->model('DB'); diff --git a/lib/NGCP/Panel/Field/DataTable.pm b/lib/NGCP/Panel/Field/DataTable.pm index 0bec3341d2..d17274f94c 100644 --- a/lib/NGCP/Panel/Field/DataTable.pm +++ b/lib/NGCP/Panel/Field/DataTable.pm @@ -13,6 +13,7 @@ has 'template' => ( isa => 'Str', has 'ajax_src' => ( isa => 'Str', is => 'rw', default => '/emptyajax' ); has 'table_fields' => ( isa => 'ArrayRef', is => 'rw' ); has 'table_titles' => ( isa => 'ArrayRef', is => 'rw' ); +has 'custom_renderers' => ( isa => 'HashRef', is => 'rw' ); has 'no_ordering' => ( isa => 'Bool', is => 'rw' ); has 'language_file' => (isa => 'Str', is => 'rw', default => 'dataTables.default.js' ); @@ -37,6 +38,7 @@ sub render_element { ajax_src => $self->ajax_src, table_fields => $self->table_fields, table_titles => $self->table_titles, + custom_renderers => $self->custom_renderers, no_ordering => $self->no_ordering, errors => $self->errors, language_file => $self->language_file, diff --git a/lib/NGCP/Panel/Field/ProfileNetwork.pm b/lib/NGCP/Panel/Field/ProfileNetwork.pm index c662ce5719..ef535f6701 100644 --- a/lib/NGCP/Panel/Field/ProfileNetwork.pm +++ b/lib/NGCP/Panel/Field/ProfileNetwork.pm @@ -12,6 +12,7 @@ has_field 'profile_id' => ( ajax_src => '/billing/ajax', table_titles => ['#', 'Reseller', 'Profile'], table_fields => ['id', 'reseller_name', 'name'], + custom_renderers => { name => 'function ( data, type, full ) { if(data.length > 13) data = data.substring(0,10) + \'...\'; return data; }'} ); has_field 'network_id' => ( @@ -24,6 +25,7 @@ has_field 'network_id' => ( ajax_src => '/network/ajax', table_titles => ['#', 'Reseller', 'Network'], table_fields => ['id', 'reseller_name', 'name'], + custom_renderers => { name => 'function ( data, type, full ) { if(data.length > 13) data = data.substring(0,10) + \'...\'; return data; }'} ); 1; diff --git a/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm b/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm index c540725c0f..b9e7185715 100644 --- a/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm +++ b/lib/NGCP/Panel/Form/ProfilePackage/Reseller.pm @@ -49,6 +49,7 @@ has_field 'initial_balance' => ( title => ['The initial balance (in cents) that will be set for the very first balance interval.'] }, default => 0, + required => 1, ); has_field 'initial_profiles' => ( diff --git a/lib/NGCP/Panel/Utils/Voucher.pm b/lib/NGCP/Panel/Utils/Voucher.pm index 8c3e1b6490..c6e5035b8d 100644 --- a/lib/NGCP/Panel/Utils/Voucher.pm +++ b/lib/NGCP/Panel/Utils/Voucher.pm @@ -146,7 +146,7 @@ sub check_topup { return 0 unless &{$err_code}("Unknown profile package ID $package_id."); } $entities->{package} = $package if defined $entities; - if(defined $reseller_id && $reseller_id != $package->reseller_id) { + if ($package->reseller_id && $package->reseller_id != $contract->contact->reseller_id) { return 0 unless &{$err_code}('Profile package belongs to another reseller.'); } } diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index 26e73e92c8..faf13c49eb 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -87,7 +87,12 @@ $(document).ready(function() { "mRender": function ( data, type, full ) { if(data == null) return ''; - return String(data).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');//" + [% IF custom_renderers.${f} -%] + var renderCustom = [% custom_renderers.${f} -%]; + [% ELSE -%] + var renderCustom = function(data, type, full) { return data; }; + [% END -%] + return String(renderCustom(data, type, full)).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');//" } }, [% END -%] diff --git a/share/templates/helpers/datatables_field.tt b/share/templates/helpers/datatables_field.tt index 713386b927..987180cad9 100644 --- a/share/templates/helpers/datatables_field.tt +++ b/share/templates/helpers/datatables_field.tt @@ -35,13 +35,17 @@ $(document).ready(function() { [% FOREACH f IN table_fields -%] [%index = loop.count - 1%] [%IF table_titles.${index} %] - [% f = f.replace('\.','_');%] { - "mData": "[% f %]", + "mData": "[% f.replace('\.','_') %]", "mRender": function ( data, type, full ) { if(data == null) return ''; - return String(data).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); + [% IF custom_renderers.${f} -%] + var renderCustom = [% custom_renderers.${f} -%]; + [% ELSE -%] + var renderCustom = function(data, type, full) { return data; }; + [% END -%] + return String(renderCustom(data, type, full)).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } }, [% END -%] diff --git a/share/templates/helpers/datatables_multifield.tt b/share/templates/helpers/datatables_multifield.tt index d8410db40a..e663ae92c6 100644 --- a/share/templates/helpers/datatables_multifield.tt +++ b/share/templates/helpers/datatables_multifield.tt @@ -49,7 +49,12 @@ $(document).ready(function() { "mRender": function ( data, type, full ) { if(data == null) return ''; - return String(data).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); + [% IF custom_renderers.${f} -%] + var renderCustom = [% custom_renderers.${f} -%]; + [% ELSE -%] + var renderCustom = function(data, type, full) { return data; }; + [% END -%] + return String(renderCustom(data, type, full)).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } }, [% END -%]