diff --git a/lib/admin/Controller/sound.pm b/lib/admin/Controller/sound.pm index 1a9bbe2..9a856e3 100644 --- a/lib/admin/Controller/sound.pm +++ b/lib/admin/Controller/sound.pm @@ -22,43 +22,30 @@ Edit sound sets. sub base : Chained('/') PathPrefix CaptureArgs(0) { my ($self, $c) = @_; - return unless ( $c->stash->{sets} = $c->forward ('load_sets')); - - if (defined $c->session->{refill}) { - foreach my $s (@{$c->stash->{sets}}) { - next if ($s->{id} ne $c->session->{refill}->{set_id}); - foreach my $h (@{$s->{handles}}) { - next if ($h->{id} ne $c->session->{refill}->{handle_id}); - $h->{filename} = $c->session->{refill}->{filename}; - $h->{err} = 1; - } - } - $c->session->{refill} = undef; - } - - $c->stash->{template} = 'tt/sound.tt'; } sub list : Chained('base') PathPart('') Args(0) { my ($self, $c) = @_; + $c->stash->{sets} = $c->forward ('load_sets'); $c->stash->{template} = 'tt/sound.tt'; } -sub set_get : Chained('base') PathPart('set') CaptureArgs(1) { +sub set : Chained('base') PathPart('set') CaptureArgs(1) { my ($self, $c, $set_id) = @_; $c->stash->{set_id} = $set_id if ($set_id != 0); + $c->stash->{set} = $c->forward ('load_single_set') if ($set_id != 0); } sub set_add : Chained('base') PathPart('set') CaptureArgs(0) { my ($self, $c, $set_id) = @_; } -sub handle_get : Chained('set_get') PathPart('handle') CaptureArgs(1) { +sub handle : Chained('set') PathPart('handle') CaptureArgs(1) { my ($self, $c, $handle_id) = @_; $c->stash->{handle_id} = $handle_id; } -sub upload_soundfile : Chained('handle_get') PathPart('soundfile/upload') Args(0) { +sub upload_soundfile : Chained('handle') PathPart('soundfile/upload') Args(0) { my ($self, $c) = @_; my %messages; @@ -93,21 +80,22 @@ sub upload_soundfile : Chained('handle_get') PathPart('soundfile/upload') Args(0 }, undef)) { - $messages{topmsg} = 'Server.Voip.SavedSettings'; + $messages{sound_set_msg} = 'Server.Voip.SavedSettings'; } else { - $messages{toperr} = 'Client.Voip.InputErrorFound'; + $messages{sound_set_err} = 'Client.Voip.InputErrorFound'; } } else { - $messages{file_err} = 'Client.Syntax.InvalidFileType'; + $messages{sound_set_err} = 'Client.Syntax.InvalidFileType'; $c->session->{refill} = { set_id => $c->stash->{set_id}, handle_id => $c->stash->{handle_id}, filename => $filename }; } $c->session->{messages} = \%messages; - $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/edit#set_' . $c->stash->{set_id}); + # $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/edit#set_' . $c->stash->{set_id}); + $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/editfiles'); } -sub get_soundfile : Chained('handle_get') PathPart('soundfile/get') Args(0) { +sub get_soundfile : Chained('handle') PathPart('soundfile/get') Args(0) { my ($self, $c) = @_; my $soundfile; @@ -123,13 +111,18 @@ sub get_soundfile : Chained('handle_get') PathPart('soundfile/get') Args(0) { $c->response->body($soundfile->{data}); } -sub edit_set : Chained('set_get') PathPart('edit') Args(0) { +sub edit_set : Chained('set') PathPart('edit') Args(0) { my ($self, $c) = @_; - $c->stash->{edit_set_id} = $c->stash->{set_id}; # meh + $c->stash->{sets} = $c->forward ('load_sets'); $c->stash->{template} = 'tt/sound.tt'; } -sub delete_set : Chained('set_get') PathPart('delete') Args(0) { +sub edit_files : Chained('set') PathPart('editfiles') Args(0) { + my ($self, $c) = @_; + $c->stash->{template} = 'tt/sound_edit_files.tt'; +} + +sub delete_set : Chained('set') PathPart('delete') Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'tt/sound.tt'; my %messages; @@ -139,10 +132,10 @@ sub delete_set : Chained('set_get') PathPart('delete') Args(0) { { id => $c->stash->{set_id} }, undef)) { - $messages{topmsg} = 'Server.Voip.SoundsetDeleted'; + $messages{sound_set_msg} = 'Server.Voip.SoundsetDeleted'; } else { - $messages{toperr} = 'Client.Voip.InputErrorFound'; + $messages{sound_set_err} = 'Client.Voip.InputErrorFound'; } $c->response->redirect("/sound"); @@ -150,7 +143,7 @@ sub delete_set : Chained('set_get') PathPart('delete') Args(0) { # deletes an sound file, not the handle # usage of 'handle' here is from users perspective -sub delete_handle : Chained('handle_get') PathPart('delete') Args(0) { +sub delete_handle : Chained('handle') PathPart('delete') Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'tt/sound.tt'; my %messages; @@ -162,60 +155,61 @@ sub delete_handle : Chained('handle_get') PathPart('delete') Args(0) { }, undef)) { - $messages{topmsg} = 'Server.Voip.SoundHandleDeleted'; + $messages{sound_set_msg} = 'Server.Voip.SoundHandleDeleted'; } else { - $messages{toperr} = 'Client.Voip.InputErrorFound'; + $messages{sound_set_err} = 'Client.Voip.InputErrorFound'; } - $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/edit#set_' . $c->stash->{set_id}); + # $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/edit#set_' . $c->stash->{set_id}); + $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/editfiles'); } -sub save_set : Chained('set_get') PathPart('save') Args(0) { +sub save_set : Chained('set') PathPart('save') Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'tt/sound.tt'; my %messages; $c->stash->{set_name} = $c->request->params->{set_name}; + $c->stash->{set_description} = $c->request->params->{set_description}; if ($c->stash->{set_id}) { if ($c->model('Provisioning')->call_prov($c, 'voip', 'update_sound_set', { id => $c->stash->{set_id}, set_name => $c->stash->{set_name}, + set_description => $c->stash->{set_description}, }, undef)) { - $messages{topmsg} = 'Server.Voip.SavedSettings'; + $messages{sound_set_msg} = 'Server.Voip.SavedSettings'; } } else { if ($c->model('Provisioning')->call_prov($c, 'voip', 'create_sound_set', - { set_name => $c->request->params->{set_name} }, + { set_name => $c->request->params->{set_name}, + set_description => $c->stash->{set_description}, + }, undef )) { - $messages{topmsg} = 'Server.Voip.SavedSettings'; + $messages{sound_set_msg} = 'Server.Voip.SavedSettings'; } } - $messages{toperr} = 'Client.Voip.InputErrorFound'; + $messages{sound_set_err} = 'Client.Voip.InputErrorFound'; $c->response->redirect("/sound"); } sub load_sets :Private { - my ( $self, $c, $params) = @_; + my ($self, $c) = @_; my $sets; return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'get_sound_sets', - # TODO: remove comment - # handle_request (called from call_prov) will add - # reseller_id - # { reseller_id => $params->{reseller_id} }, undef, # parameters \$sets, ); @@ -223,5 +217,20 @@ sub load_sets :Private { return $sets; } +sub load_single_set :Private { + my ($self, $c) = @_; + + my $set; + return unless $c->model('Provisioning')->call_prov( + $c, + 'voip', + 'get_single_sound_set', + { set_id => $c->stash->{set_id} }, + \$set, + ); + + return $set; +} + # Ends, some people will rob their mothers for the ends ... 1 diff --git a/root/tt/sound.tt b/root/tt/sound.tt index cebe086..8e1ecb2 100644 --- a/root/tt/sound.tt +++ b/root/tt/sound.tt @@ -1,21 +1,30 @@

Manage sound sets

+[% IF messages.sound_set_err %]
[% messages.sound_set_err %]
[% END %] +[% IF messages.sound_set_msg %]
[% messages.sound_set_msg %]
[% END %] + -
+
+