MT#4289 separate customer/ajax and contract/ajax

This is the first step towards separating the
tight coupling of the Customer and Contract Controllers.

Mantis: 4289#c25035
apogrebennyk/3_1_force_outbound
Gerhard Jungwirth 12 years ago
parent a37b165caf
commit 104751bb6a

@ -31,7 +31,8 @@ sub contract_list :Chained('/') :PathPart('contract') :CaptureArgs(0) {
{ name => "status", search => 1, title => "Status" },
]);
my $rs = NGCP::Panel::Utils::Contract::get_contract_rs(c => $c);
my $rs = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'));
unless($c->user->is_superuser) {
$rs = $rs->search({
'contact.reseller_id' => $c->user->reseller_id,
@ -382,31 +383,7 @@ sub customer_list :Chained('contract_list') :PathPart('customer') :CaptureArgs(0
$c->stash(page_title => "Customer",
page_title_plural => "Customers");
$c->stash(ajax_uri => $c->uri_for_action("/contract/customer_ajax"));
}
sub customer_root :Chained('customer_list') :PathPart('') :Args(0) {
}
sub customer_ajax :Chained('customer_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $rs = $c->stash->{customer_rs};
my $contract_dt_col = NGCP::Panel::Utils::Datatables::set_columns($c, [
{ name => "id", search => 1, title => "#" },
{ name => "external_id", search => 1, title => "External #" },
{ name => "contact.reseller.name", search => 1, title => "Reseller" },
{ name => "contact.email", search => 1, title => "Contact Email" },
{ name => "billing_mappings.product.name", search => 1, title => "Product" },
{ name => "billing_mappings.billing_profile.name", search => 1, title => "Billing Profile" },
{ name => "status", search => 1, title => "Status" },
{ name => "max_subscribers", search => 1, title => "Max Number of Subscribers" },
]);
push @{ $c->stash->{contract_dt_columns} },
{ name => "max_subscribers", search => 1, title => "Max Number of Subscribers" };
NGCP::Panel::Utils::Datatables::process($c, $rs, $contract_dt_col);
$c->detach( $c->view("JSON") );
$c->stash(ajax_uri => $c->uri_for_action("/customer/ajax"));
}
sub customer_ajax_reseller_filter :Chained('customer_list') :PathPart('ajax/reseller') :Args(1) {

@ -54,7 +54,26 @@ sub list_customer :Chained('/') :PathPart('customer') :CaptureArgs(0) {
{ name => "max_subscribers", search => 1, title => "Max Number of Subscribers" },
]);
my $rs = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'));
unless($c->user->is_superuser) {
$rs = $rs->search({
'contact.reseller_id' => $c->user->reseller_id,
}, {
join => 'contact',
});
}
$rs = $rs->search({
'-or' => [
'product.class' => 'sipaccount',
'product.class' => 'pbxaccount',
],
}, {
'join' => {'billing_mappings' => 'product'},
});
$c->stash(
contract_select_rs => $rs,
template => 'customer/list.tt'
);
}
@ -63,6 +82,14 @@ sub root :Chained('list_customer') :PathPart('') :Args(0) :Does(ACL) :ACLDetachT
my ($self, $c) = @_;
}
sub ajax :Chained('list_customer') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $res = $c->stash->{contract_select_rs};
NGCP::Panel::Utils::Datatables::process($c, $res, $c->stash->{contract_dt_columns});
$c->detach( $c->view("JSON") );
}
sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $contract_id) = @_;
@ -134,7 +161,8 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
});
}
my $contract_select_rs = NGCP::Panel::Utils::Contract::get_contract_rs(c => $c);
my $contract_select_rs = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'));
$contract_select_rs = $contract_select_rs->search({
'me.id' => $contract_id,
});

@ -34,7 +34,8 @@ sub auto :Private {
# and then again, it's only for subscriberadmins with pbxaccount product
if($c->user->roles eq "subscriberadmin") {
my $contract_id = $c->user->account_id;
my $contract_select_rs = NGCP::Panel::Utils::Contract::get_contract_rs(c => $c);
my $contract_select_rs = NGCP::Panel::Utils::Contract::get_contract_rs(
schema => $c->model('DB'));
$contract_select_rs = $contract_select_rs->search({ 'me.id' => $contract_id });
my $product_id = $contract_select_rs->first->get_column('product_id');
unless($product_id) {

@ -9,7 +9,7 @@ has_field 'id' => (
do_wrapper => 0,
required => 1,
template => 'helpers/datatables_field.tt',
ajax_src => '/contract/customer/ajax',
ajax_src => '/customer/ajax',
table_titles => ['#', 'Reseller', 'Contact Email', 'External #', 'Status'],
table_fields => ['id', 'contact_reseller_name', 'contact_email', 'external_id', 'status'],
);

@ -143,9 +143,9 @@ sub recursively_lock_contract {
sub get_contract_rs {
my %params = @_;
my $c = $params{c};
my $mapping_rs = $c->model('DB')->resultset('billing_mappings');
my $rs = $c->model('DB')->resultset('contracts')
my $schema = $params{schema};
my $mapping_rs = $schema->resultset('billing_mappings');
my $rs = $schema->resultset('contracts')
->search({
'me.status' => { '!=' => 'terminated' },
'billing_mappings.id' => {

@ -10,7 +10,7 @@
helper.create_flag = create_flag;
helper.edit_flag = edit_flag;
helper.form_object = form;
helper.ajax_uri = c.uri_for('/contract/customer/ajax');
helper.ajax_uri = c.uri_for_action('/customer/ajax');
UNLESS c.user.read_only;
helper.dt_buttons = [

Loading…
Cancel
Save