Add subscriber termination.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent 5e5b221bbf
commit cc707fa6d0

@ -56,11 +56,6 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
back_uri => $c->uri_for('/subscriber/create'),
);
if($form->validated) {
# TODO: save subscriber
$c->log->debug(">>>>>>>>>>>>>>>>>>>>>>>>>> subscriber validated");
# TODO: use transaction
my $schema = $c->model('DB');
try {
$schema->txn_do(sub {
@ -136,15 +131,14 @@ sub base :Chained('/subscriber/sub_list') :PathPart('') :CaptureArgs(1) {
return;
}
my $res = $c->model('DB')->resultset('voip_subscribers')->find($subscriber_id);
unless(defined($res)) {
my $res = $c->model('DB')->resultset('voip_subscribers')->find({ id => $subscriber_id });
unless(defined $res) {
$c->flash(messages => [{type => 'error', text => 'Subscriber does not exist!'}]);
$c->response->redirect($c->uri_for());
return;
$c->response->redirect($c->uri_for('/subscriber'));
$c->detach;
}
$c->stash(subscriber => {$res->get_columns});
$c->stash(subscriber_result => $res);
$c->stash(subscriber => $res);
}
sub ajax :Chained('sub_list') :PathPart('ajax') :Args(0) {
@ -152,8 +146,8 @@ sub ajax :Chained('sub_list') :PathPart('ajax') :Args(0) {
my $dispatch_to = '_ajax_resultset_' . $c->user->auth_realm;
my $resultset = $self->$dispatch_to($c);
$c->forward( "/ajax_process_resultset", [$resultset,
["id", "username", "domain_id"],
["username", "domain_id"]]);
["id", "username", "domain_id", "status",],
["username", "domain_id", "status",]]);
$c->detach( $c->view("JSON") );
}
@ -169,6 +163,29 @@ sub _ajax_resultset_reseller {
return $c->model('DB')->resultset('voip_subscribers');
}
sub terminate :Chained('base') :PathPart('terminate') :Args(0) {
my ($self, $c) = @_;
my $subscriber = $c->stash->{subscriber};
my $schema = $c->model('DB');
try {
$schema->txn_do(sub {
use Data::Printer;
p $subscriber;
$subscriber->provisioning_voip_subscriber->delete;
$subscriber->update({ status => 'terminated' });
});
$c->flash(messages => [{type => 'success', text => 'Successfully terminated subscriber'}]);
$c->response->redirect($c->uri_for());
return;
} catch($e) {
$c->log->error("Failed to terminate subscriber: $e");
$c->flash(messages => [{type => 'error', text => 'Failed to terminate subscriber'}]);
$c->response->redirect($c->uri_for());
return;
}
}
sub master :Chained('/') :PathPart('subscriber') :Args(1) {
my ($self, $c, $subscriber_id) = @_;

@ -26,15 +26,23 @@ $(document).ready(function() {
{ "mData": "[% f %]" },
[% END -%]
{ "mRender": function ( data, type, full ) {
return '' +
'<div class="sw_actions pull-right">'
var html = '' +
'<div class="sw_actions pull-right">';
[% FOR button IN helper.dt_buttons -%]
[% confirm_delete = 'data-confirm="Delete"' IF button.name == "Delete" -%]
+ '<a class="btn [% button.class %]" href="[% button.uri %]" [% confirm_delete %]>' +
'<i class="[% button.icon %]"></i> [% button.name %]' +
'</a>'
[% IF button.condition -%]
if([% button.condition %]) {
[% END -%]
html +=
'<a class="btn [% button.class %]" href="[% button.uri %]" [% confirm_delete %]>' +
'<i class="[% button.icon %]"></i> [% button.name %]' +
'</a>';
[% IF button.condition -%]
}
[% END -%]
[% END -%]
+ '</div>';
html += '</div>';
return html;
},
"mData": null,
"bSortable": false,

@ -3,8 +3,8 @@
helper.name = 'Subscriber';
helper.data = subscribers;
helper.messages = messages;
helper.column_titles = [ '#', 'Username', 'Domain #' ];
helper.column_fields = [ 'id', 'username', 'domain_id' ];
helper.column_titles = [ '#', 'Username', 'Domain #', 'Status' ];
helper.column_fields = [ 'id', 'username', 'domain_id', 'status' ];
helper.close_target = close_target;
helper.create_flag = create_flag;
@ -13,8 +13,8 @@
helper.ajax_uri = c.uri_for( c.controller.action_for('ajax') );
helper.dt_buttons = [
{ name = 'Delete', uri = "/subscriber/'+full[\"id\"]+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
{ name = 'Preferences', uri = "/subscriber/'+full[\"id\"]+'/preferences", class = 'btn-small btn-tertiary', icon = 'icon-list' },
{ name = 'Terminate', uri = "/subscriber/'+full.id+'/terminate", class = 'btn-small btn-secondary', icon = 'icon-trash', condition = 'full.status != "terminated"' },
{ name = 'Preferences', uri = "/subscriber/'+full.id+'/preferences", class = 'btn-small btn-tertiary', icon = 'icon-list', condition = 'full.status != "terminated"' },
];
helper.top_buttons = [
{ name = 'Create Subscriber', uri = c.uri_for_action('/subscriber/create_list'), icon = 'icon-star' },

Loading…
Cancel
Save