MT#7191 Use DT to select contact country.

ipeshinskaya/InvoiceTemplate5
Andreas Granig 11 years ago
parent ca7e7a6f0c
commit 378f53c806
Notes: Jenkins User 11 years ago
jenkins_trigger: false

2
debian/control vendored

@ -31,6 +31,7 @@ Build-Depends: debhelper (>= 8),
libfile-spec-perl (>= 3.4000~),
libfile-type-perl,
libgd-gd2-perl,
libgeography-countries-perl,
libhash-merge-simple-perl,
libhash-storediterator-perl,
libhtml-formhandler-model-dbic-perl,
@ -109,6 +110,7 @@ Depends: gettext,
libfile-spec-perl (>= 3.4000~),
libfile-type-perl,
libgd-gd2-perl,
libgeography-countries-perl,
libhash-merge-simple-perl,
libhtml-formhandler-model-dbic-perl,
libhtml-formhandler-perl (>= 0.40026),

@ -158,11 +158,13 @@ sub POST :Allow {
my $form = $self->get_form($c);
$resource->{reseller_id} //= undef;
$resource->{country}{id} = delete $resource->{country};
last unless $self->validate_form(
c => $c,
resource => $resource,
form => $form,
);
$resource->{country} = $resource->{country}{id};
my $reseller = $c->model('DB')->resultset('resellers')
->find($resource->{reseller_id});

@ -185,6 +185,9 @@ sub field_to_json : Private {
when(/\+NGCP::Panel::Field::Regex/) {
return "String";
}
when(/\+NGCP::Panel::Field::Country/) {
return "String";
}
when(/\+NGCP::Panel::Field::EmailList/) {
return "String";
}
@ -232,6 +235,8 @@ sub get_collection_properties {
$name = 'primary_number';
} elsif($f->type =~ /AliasNumber/) {
$name = 'alias_numbers';
} elsif($f->type =~ /Country$/) {
$name = 'country';
} elsif($f->type !~ /Regex|EmailList|SubscriberStatusSelect|SubscriberLockSelect|Identifier|PosInteger/) {
$name .= '_id';
}

@ -145,12 +145,14 @@ sub POST :Allow {
);
last unless $resource;
$resource->{country}{id} = delete $resource->{country};
my $form = $self->get_form($c);
last unless $self->validate_form(
c => $c,
resource => $resource,
form => $form,
);
$resource->{country} = $resource->{country}{id};
my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{create_timestamp} = $now;

@ -8,6 +8,8 @@ use NGCP::Panel::Form::Contact::Admin;
use NGCP::Panel::Utils::Message;
use NGCP::Panel::Utils::Navigation;
use Geography::Countries qw/countries country CNT_F_REGULAR CNT_I_FLAG CNT_I_CODE2/;
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
my ($self, $c) = @_;
$c->log->debug(__PACKAGE__ . '::auto');
@ -75,6 +77,7 @@ sub create :Chained('list_contact') :PathPart('create') :Args(0) {
if($c->user->is_superuser && $no_reseller) {
delete $form->values->{reseller};
}
$form->values->{country} = $form->values->{country}{id};
my $contact = $c->stash->{contacts}->create($form->values);
delete $c->session->{created_objects}->{reseller};
$c->session->{created_objects}->{contact} = { id => $contact->id };
@ -121,6 +124,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
my $form;
my $params = { $c->stash->{contact}->get_inflated_columns };
$params = $params->merge($c->session->{created_objects});
$params->{country}{id} = delete $params->{country};
if($c->user->is_superuser && $no_reseller) {
$form = NGCP::Panel::Form::Contact::Reseller->new;
$params->{reseller}{id} = $c->user->reseller_id;
@ -152,6 +156,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$form->values->{reseller_id} = $form->values->{reseller}{id};
}
delete $form->values->{reseller};
$form->values->{country} = $form->values->{country}{id};
$c->stash->{contact}->update($form->values);
$c->flash(messages => [{type => 'success', text => $c->loc('Contact successfully changed')}]);
delete $c->session->{created_objects}->{reseller};
@ -229,6 +234,53 @@ 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) {
my ($self, $c) = @_;
my $from = $c->request->params->{iDisplayStart} // 0;
my $len = $c->request->params->{iDisplayLength} // 4;
my $to = $from + $len - 1;
my $search = $c->request->params->{sSearch};
my $top = $c->request->params->{iIdOnTop};
my $top_entry;
my @aaData = map {
my @c = country($_);
if($c[CNT_I_CODE2]) {
my $e = { name => $_, id => $c[CNT_I_CODE2] };
if($top && !$top_entry && $top eq $e->{id}) {
$top_entry = $e;
(); # we insert it as top element after the map
} else {
$e;
}
} else { (); }
} countries;
if($top_entry) {
unshift @aaData, $top_entry;
}
if(defined $search) {
@aaData = map {
if($_->{id} =~ /$search/i || $_->{name} =~ /$search/i) {
$_;
} else { (); }
} @aaData;
}
my $count = @aaData;
@aaData = @aaData[$from .. ($to < $#aaData ? $to : $#aaData)];
$c->stash(aaData => \@aaData,
iTotalRecords => $count,
iTotalDisplayRecords => $count,
sEcho => int($c->request->params->{sEcho} // 1),
);
$c->detach( $c->view("JSON") );
}
__PACKAGE__->meta->make_immutable;
1;

@ -0,0 +1,17 @@
package NGCP::Panel::Field::Country;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::DataTable',
label => 'Country',
do_label => 0,
do_wrapper => 0,
required => 1,
template => 'helpers/datatables_field.tt',
ajax_src => '/contact/country/ajax',
table_titles => ['#', 'Country'],
table_fields => ['id', 'name'],
);
1;

@ -79,8 +79,9 @@ has_field 'city' => (
);
has_field 'country' => (
type => 'Text',
maxlength => 2,
type => '+NGCP::Panel::Field::Country',
validate_when_empty => 1,
label => 'Country',
element_attr => {
rel => ['tooltip'],
title => ['The two-letter ISO 3166-1 country code of the contact (e.g. US or DE).']

@ -60,6 +60,7 @@ sub hal_from_contact {
relation => 'ngcp:'.$self->resource_name,
);
$resource{country}{id} = delete $resource{country};
$form //= $self->get_form($c);
$self->validate_form(
c => $c,
@ -67,6 +68,7 @@ sub hal_from_contact {
form => $form,
run => 0,
);
$resource{country} = $resource{country}{id};
$resource{id} = int($contact->id);
$hal->resource({%resource});
@ -83,6 +85,7 @@ sub contact_by_id {
sub update_contact {
my ($self, $c, $contact, $old_resource, $resource, $form) = @_;
$resource->{country}{id} = delete $resource->{country};
$form //= $self->get_form($c);
# TODO: for some reason, formhandler lets missing reseller_id slip thru
$resource->{reseller_id} //= undef;
@ -91,6 +94,7 @@ sub update_contact {
form => $form,
resource => $resource,
);
$resource->{country} = $resource->{country}{id};
my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{modify_timestamp} = $now;

@ -46,6 +46,7 @@ sub hal_from_contact {
relation => 'ngcp:'.$self->resource_name,
);
$resource{country}{id} = delete $resource{country};
$form //= $self->get_form($c);
# TODO: i'd expect reseller to be removed automatically
@ -56,6 +57,7 @@ sub hal_from_contact {
form => $form,
run => 0,
);
$resource{country} = $resource{country}{id};
$resource{id} = int($contact->id);
$hal->resource({%resource});
@ -71,6 +73,7 @@ sub contact_by_id {
sub update_contact {
my ($self, $c, $contact, $old_resource, $resource, $form) = @_;
$resource->{country}{id} = delete $resource->{country};
$form //= $self->get_form($c);
delete $resource->{reseller_id};
return unless $self->validate_form(
@ -78,6 +81,7 @@ sub update_contact {
form => $form,
resource => $resource,
);
$resource->{country} = $resource->{country}{id};
my $now = NGCP::Panel::Utils::DateTime::current_local;
$resource->{modify_timestamp} = $now;

Loading…
Cancel
Save