TT#12197 Use contacts connected to the resellers for the customers creation

Change-Id: I6fc8fc49b5c7dc7d6ca78c4dbc1ab75f4891437a
changes/71/12271/16
Irina Peshinskaya 9 years ago
parent 760a576eb1
commit 35bad60d2e

@ -276,36 +276,42 @@ sub delete :Chained('base') :PathPart('delete') :Args(0) {
sub ajax :Chained('list_contact') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
NGCP::Panel::Utils::Datatables::process(
$c,
$c->stash->{contacts}->search_rs(undef, {prefetch=>"contracts"}),
$c->stash->{contact_dt_columns},
sub {
my ($result) = @_;
my $contract_rs = $result->contracts->search({
status => { '!=' => 'terminated' },
});
my $subscriber_rs = $c->model('DB')->resultset('voip_subscribers')->search({
contact_id => $result->id,
status => { '!=' => 'terminated' },
});
my %data = (deletable => ($contract_rs->first or $subscriber_rs->first) ? 0 : 1);
return %data
},
);
$self->ajax_list_contacts($c, {'reseller' => 'any'});
$c->detach( $c->view("JSON") );
}
sub ajax_noreseller :Chained('list_contact') :PathPart('ajax_noreseller') :Args(0) {
my ($self, $c) = @_;
$self->ajax_list_contacts($c, {'reseller' => 'no_reseller'});
$c->detach( $c->view("JSON") );
}
sub ajax_reseller :Chained('list_contact') :PathPart('ajax_reseller') :Args(0) {
my ($self, $c) = @_;
$self->ajax_list_contacts($c, {'reseller' => 'not_empty'});
$c->detach( $c->view("JSON") );
}
sub ajax_list_contacts{
my ($self, $c, $params) = @_;
$params //= {};
my $reseller_query = [];
if('any' eq $params->{reseller}){
$reseller_query->[0] = undef;
}elsif('no_reseller' eq $params->{reseller}){
$reseller_query->[0] = { reseller_id => undef,};
}elsif('not_empty' eq $params->{reseller}){
$reseller_query->[0] = { reseller_id => { '!=' => undef },};
}
NGCP::Panel::Utils::Datatables::process(
$c,
$c->stash->{contacts}->search_rs({
reseller_id => undef,
}, {prefetch=>"contracts"}),
$c->stash->{contacts}->search_rs(
$reseller_query->[0],
$reseller_query->[1] ? $reseller_query->[1] : {
prefetch=>"contracts"
}
),
$c->stash->{contact_dt_columns},
sub {
my ($result) = @_;
@ -321,7 +327,6 @@ sub ajax_noreseller :Chained('list_contact') :PathPart('ajax_noreseller') :Args(
},
);
$c->detach( $c->view("JSON") );
}
sub countries_ajax :Chained('/') :PathPart('contact/country/ajax') :Args(0) {

@ -0,0 +1,28 @@
package NGCP::Panel::Field::ContactWithReseller;
use Moose;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::DataTable',
label => 'Contact',
do_label => 0,
do_wrapper => 0,
required => 1,
template => 'helpers/datatables_field.tt',
ajax_src => '/contact/ajax_reseller',
table_titles => ['#', 'Reseller', 'First Name', 'Last Name', 'Email'],
table_fields => ['id', 'reseller_name', 'firstname', 'lastname', 'email'],
);
has_field 'create' => (
type => 'Button',
do_label => 0,
value => 'Create Contact',
element_class => [qw/btn btn-tertiary pull-right/],
);
no Moose;
1;
# vim: set tabstop=4 expandtab:

@ -5,7 +5,7 @@ use Storable qw();
extends 'NGCP::Panel::Form::Contract::Base';
has_field 'contact' => (
type => '+NGCP::Panel::Field::Contact',
type => '+NGCP::Panel::Field::ContactWithReseller',
label => 'Contact',
validate_when_empty => 1,
element_attr => {

Loading…
Cancel
Save