Use a modal to display the NCOS setting "Include local ac"

agranig/1_0_subfix
Gerhard Jungwirth 13 years ago
parent 266621e886
commit e41fe3305d

@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Form::NCOS::ResellerLevel;
use NGCP::Panel::Form::NCOS::AdminLevel;
use NGCP::Panel::Form::NCOS::Pattern;
use NGCP::Panel::Form::NCOS::LocalAC;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::Datatables;
@ -200,39 +201,8 @@ sub pattern_list :Chained('base') :PathPart('pattern') :CaptureArgs(0) {
{ name => 'description', search => 1, title => 'Description' },
]);
my $local_ac_form = HTML::FormHandler::Model::DBIC->new(field_list => [
local_ac => { type => 'Boolean', label => 'Include local area code'},
save => { type => 'Submit', value => 'Set', element_class => ['btn']},
],
'widget_wrapper' => 'Bootstrap',
form_element_class => ['form-horizontal', 'ngcp-quickform'],
);
$local_ac_form->process(
posted => ($c->request->method eq 'POST') && defined $c->req->params->{local_ac},
params => $c->request->params,
item => $c->stash->{level_result}
);
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $local_ac_form,
fields => {},
back_uri => $c->req->uri,
);
$c->stash(local_ac_form => $local_ac_form);
if($local_ac_form->validated) {
try {
$c->stash->{pattern_rs}->first->update({
local_ac => $local_ac_form->values->{local_ac},
});
$c->flash(messages => [{type => 'success', text => 'Successfully updated NCOS pattern'}]);
} catch($e) {
$c->log->error("failed to update local-ac for ncos: $e");
$c->flash(messages => [{type => 'success', text => 'Successfully updated NCOS pattern'}]);
}
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{pattern_base_uri});
}
$c->stash(template => 'ncos/pattern_list.tt');
$c->stash(local_ac_checked => $c->stash->{level_result}->local_ac,
template => 'ncos/pattern_list.tt');
}
sub pattern_root :Chained('pattern_list') :PathPart('') :Args(0) {
@ -343,6 +313,40 @@ sub pattern_create :Chained('pattern_list') :PathPart('create') :Args(0) {
);
}
sub pattern_edit_local_ac :Chained('pattern_list') :PathPart('edit_local_ac') :Args(0) {
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::NCOS::LocalAC->new;
$form->process(
posted => $posted,
params => $c->request->params,
item => $c->stash->{level_result},
);
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => {},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
try {
$c->stash->{level_result}->update($form->values);
$c->flash(messages => [{type => 'success', text => 'Setting successfully updated'}]);
} catch($e) {
$c->log->error("failed to update ncos level setting: $e");
$c->flash(messages => [{type => 'error', text => 'Failed to update NCOS level setting'}]);
}
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{pattern_base_uri});
}
$c->stash(
close_target => $c->stash->{pattern_base_uri},
form => $form,
edit_flag => 1
);
}
__PACKAGE__->meta->make_immutable;

@ -0,0 +1,59 @@
package NGCP::Panel::Form::NCOS::LocalAC;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
sub build_form_element_class {[qw(form-horizontal)]}
has_field 'local_ac' => (
type => 'Boolean',
label => 'Include local area code',
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/local_ac/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
=head1 NAME
NGCP::Panel::Form::LocalAC
=head1 DESCRIPTION
=head1 METHODS
=head1 AUTHOR
Gerhard Jungwirth
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# vim: set tabstop=4 expandtab:

@ -346,4 +346,9 @@ div.ngcp-modal .control-group.error .dataTables_wrapper input[type="text"] {
padding: 4px 6px !important;
}
#number_patterns_local_ac > label {
display: inline;
cursor: not-allowed;
}
/* vim: set tabstop=4 syntax=css expandtab: */

@ -26,6 +26,17 @@
PROCESS 'helpers/datatables.tt';
-%]
[% local_ac_form.render() %]
<div id="number_patterns_local_ac">
<input id="local_ac" type="checkbox" name="local_ac" disabled="disabled"
[% IF local_ac_checked %]checked="checked"[% END %]>
<label for="local_ac">Include local area code</label>
<div>
<a class="btn btn-primary btn-small"
href="[% c.uri_for_action("/ncos/pattern_edit_local_ac", [c.req.captures.0]) %]">
<i class="icon-edit"></i> Edit
</a>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

Loading…
Cancel
Save