From e93c68c58cad96708187bdd8825a7db2e1494d31 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Fri, 11 Oct 2013 10:39:03 +0200 Subject: [PATCH] MT#4025 Manage customer sound-sets in details view --- lib/NGCP/Panel/Controller/Customer.pm | 2 ++ lib/NGCP/Panel/Controller/Sound.pm | 31 ++++++---------------- lib/NGCP/Panel/Utils/Sounds.pm | 37 ++++++++++++++++++++++++++ share/templates/customer/details.tt | 38 +++++++++++++++++++++++++++ share/templates/helpers/datatables.tt | 4 +++ 5 files changed, 89 insertions(+), 23 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 2c0c28b391..95aa8d1786 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -18,6 +18,7 @@ use NGCP::Panel::Utils::Message; use NGCP::Panel::Utils::Navigation; use NGCP::Panel::Utils::DateTime; use NGCP::Panel::Utils::Subscriber; +use NGCP::Panel::Utils::Sounds; use Template; =head1 NAME @@ -179,6 +180,7 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { sub details :Chained('base') :PathPart('details') :Args(0) { my ($self, $c) = @_; + NGCP::Panel::Utils::Sounds::stash_soundset_list(c => $c, contract => $c->stash->{contract}); $c->stash->{contact_hash} = { $c->stash->{contract}->contact->get_inflated_columns }; } diff --git a/lib/NGCP/Panel/Controller/Sound.pm b/lib/NGCP/Panel/Controller/Sound.pm index a388b859f0..af07a7afe2 100644 --- a/lib/NGCP/Panel/Controller/Sound.pm +++ b/lib/NGCP/Panel/Controller/Sound.pm @@ -48,6 +48,7 @@ sub auto :Private { unless($product) { $c->detach('/denied_page'); } + $c->stash->{contract_rs} = $contract_select_rs; } return 1; @@ -56,30 +57,14 @@ sub auto :Private { sub sets_list :Chained('/') :PathPart('sound') :CaptureArgs(0) { my ( $self, $c ) = @_; - my $sets_rs = $c->model('DB')->resultset('voip_sound_sets'); - - my $dt_fields = [ - { name => 'id', search => 1, title => '#' }, - { name => 'name', search => 1, title => 'Name' }, - { name => 'description', search => 1, title => 'Description' }, - ]; - - if($c->user->roles eq "admin") { - splice @{ $dt_fields }, 1, 0, - { name => 'reseller.name', search => 1, title => 'Reseller' }; - splice @{ $dt_fields }, 2, 0, - { name => 'contract.contact.email', search => 1, title => 'Customer' }; - } elsif($c->user->roles eq "reseller") { - splice @{ $dt_fields }, 1, 0, - { name => 'contract.contact.email', search => 1, title => 'Customer' }; - $sets_rs = $sets_rs->search({ reseller_id => $c->user->reseller_id }); - } elsif($c->user->roles eq "subscriberadmin") { - $sets_rs = $sets_rs->search({ contract_id => $c->user->account_id }); + if($c->stash->{contract_rs}) { + NGCP::Panel::Utils::Sounds::stash_soundset_list( + c => $c, + contract => $c->stash->{contract_rs}->first + ); + } else { + NGCP::Panel::Utils::Sounds::stash_soundset_list(c => $c); } - - $c->stash->{soundset_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, $dt_fields); - - $c->stash(sets_rs => $sets_rs); $c->stash(template => 'sound/list.tt'); } diff --git a/lib/NGCP/Panel/Utils/Sounds.pm b/lib/NGCP/Panel/Utils/Sounds.pm index 2ecec00a1a..277c5214f8 100644 --- a/lib/NGCP/Panel/Utils/Sounds.pm +++ b/lib/NGCP/Panel/Utils/Sounds.pm @@ -47,6 +47,43 @@ sub transcode_data { return $out; } +sub stash_soundset_list { + my (%params) = @_; + + my $c = $params{c}; + my $contract = $params{contract}; + + my $sets_rs = $c->model('DB')->resultset('voip_sound_sets'); + if($contract) { + $sets_rs = $sets_rs->search({ contract_id => $contract->id }); + } + + my $dt_fields = [ + { name => 'id', search => 1, title => '#' }, + { name => 'name', search => 1, title => 'Name' }, + { name => 'description', search => 1, title => 'Description' }, + ]; + + if($c->user->roles eq "admin") { + splice @{ $dt_fields }, 1, 0, + { name => 'reseller.name', search => 1, title => 'Reseller' }; + splice @{ $dt_fields }, 2, 0, + { name => 'contract.contact.email', search => 1, title => 'Customer' }; + } elsif($c->user->roles eq "reseller") { + splice @{ $dt_fields }, 1, 0, + { name => 'contract.contact.email', search => 1, title => 'Customer' }; + $sets_rs = $sets_rs->search({ reseller_id => $c->user->reseller_id }); + } elsif($c->user->roles eq "subscriberadmin" && !$contract) { + $sets_rs = $sets_rs->search({ contract_id => $c->user->account_id }); + } + + $c->stash->{soundset_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, $dt_fields); + + $c->stash(sets_rs => $sets_rs); + + return; +} + 1; # vim: set tabstop=4 expandtab: diff --git a/share/templates/customer/details.tt b/share/templates/customer/details.tt index 591972f765..4ecd4dce32 100644 --- a/share/templates/customer/details.tt +++ b/share/templates/customer/details.tt @@ -296,6 +296,44 @@ [% END -%] + [% IF + c.config.features.cloudpbx && + (c.user.roles == 'admin' || c.user.roles == 'reseller' || c.user.roles == 'subscriberadmin') + -%] +
+ +
+
+ +[% + helper.name = 'Sound Sets'; + helper.dt_columns = soundset_dt_columns; + helper.ajax_uri = c.uri_for('/sound/ajax'); + + UNLESS c.user.read_only; + helper.dt_buttons = [ + { name = 'Edit', uri = "/sound/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, + { name = 'Delete', uri = "/sound/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, + { name = 'Files', uri = "/sound/'+full.id+'/handles", class = 'btn-small btn-tertiary', icon = 'icon-list' }, + ]; + helper.top_buttons = [ + { name = 'Create Sound Set', uri = c.uri_for('/sound/create'), icon = 'icon-star', accordion_button = 1 }, + ]; + ELSE; + helper.dt_buttons = [ + { name = 'Files', uri = "/sound/'+full.id+'/handles", class = 'btn-small btn-tertiary', icon = 'icon-list' }, + ]; + END; + + PROCESS 'helpers/datatables.tt'; +%] +
+
+
+ [% END -%] +
Contract Balance diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index 5787283782..5ad40fee21 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -156,7 +156,11 @@ $(document).ready(function() { [% ELSE -%] + [% IF button.accordion_button == 1 && loop.count == 1 -%] + [% button.name %] + [% ELSIF loop.count == 1-%] [% button.name %] + [% END -%] [% END -%] [% END -%]