parent
65d1b2525c
commit
320a25024b
@ -0,0 +1,136 @@
|
||||
package NGCP::Panel::Controller::Contact;
|
||||
use Moose;
|
||||
use namespace::autoclean;
|
||||
use Data::Dumper;
|
||||
|
||||
BEGIN { extends 'Catalyst::Controller'; }
|
||||
|
||||
use NGCP::Panel::Form::Contact;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NGCP::Panel::Controller::Contact - Catalyst Controller
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Catalyst Controller.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
sub list :Chained('/') :PathPart('contact') :CaptureArgs(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $contacts = [
|
||||
{id => 1, firstname => 'Foo1', lastname => '1Bar', email => 'foo1@example.org' },
|
||||
{id => 1, firstname => 'Foo2', lastname => '2Bar', email => 'foo2@example.org' },
|
||||
{id => 1, firstname => 'Foo3', lastname => '3Bar', email => 'foo3@example.org' },
|
||||
{id => 1, firstname => 'Foo4', lastname => '4Bar', email => 'foo4@example.org' },
|
||||
];
|
||||
$c->stash(contacts => $contacts);
|
||||
$c->stash(template => 'contact/list.tt');
|
||||
|
||||
if($c->session->{redirect_targets} && @{ $c->session->{redirect_targets} }) {
|
||||
my $target = ${ $c->session->{redirect_targets} }[0];
|
||||
if('/'.$c->request->path eq $target->path) {
|
||||
shift @{$c->session->{redirect_targets}};
|
||||
} else {
|
||||
$c->stash(close_target => $target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub root :Chained('list') :PathPart('') :Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
}
|
||||
|
||||
sub create :Chained('list') :PathPart('create') :Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $form = NGCP::Panel::Form::Contact->new;
|
||||
$form->process(
|
||||
posted => ($c->request->method eq 'POST'),
|
||||
params => $c->request->params,
|
||||
action => $c->uri_for('create'),
|
||||
);
|
||||
if($form->validated) {
|
||||
if($c->stash->{close_target}) {
|
||||
# TODO: set created contact in flash to be selected at target
|
||||
$c->response->redirect($c->stash->{close_target});
|
||||
return;
|
||||
}
|
||||
$c->flash(messages => [{type => 'success', text => 'Contact successfully created!'}]);
|
||||
$c->response->redirect($c->stash->{close_target});
|
||||
return;
|
||||
}
|
||||
|
||||
$c->stash(create_flag => 1);
|
||||
$c->stash(form => $form);
|
||||
}
|
||||
|
||||
sub search :Chained('list') :PathPart('search') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$c->flash(messages => [{type => 'info', text => 'Contact search not implemented!'}]);
|
||||
$c->response->redirect($c->uri_for());
|
||||
}
|
||||
|
||||
sub base :Chained('/contact/list') :PathPart('') :CaptureArgs(1) {
|
||||
my ($self, $c, $contact_id) = @_;
|
||||
|
||||
unless($contact_id && $contact_id =~ /^\d+$/) {
|
||||
$c->flash(messages => [{type => 'error', text => 'Invalid contact id detected!'}]);
|
||||
$c->response->redirect($c->uri_for());
|
||||
return;
|
||||
}
|
||||
|
||||
# TODO: fetch details of contact from model
|
||||
my @rfilter = grep { $_->{id} == $contact_id } @{ $c->stash->{contacts} };
|
||||
$c->stash(contact => shift @rfilter);
|
||||
}
|
||||
|
||||
sub edit :Chained('base') :PathPart('edit') :Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $posted = ($c->request->method eq 'POST');
|
||||
my $form = NGCP::Panel::Form::Contact->new;
|
||||
$form->process(
|
||||
posted => 1,
|
||||
params => $posted ? $c->request->params : $c->stash->{contact},
|
||||
action => $c->uri_for($c->stash->{contact}->{id}, 'edit'),
|
||||
);
|
||||
if($posted && $form->validated) {
|
||||
$c->flash(messages => [{type => 'success', text => 'Contact successfully changed!'}]);
|
||||
$c->response->redirect($c->uri_for());
|
||||
return;
|
||||
}
|
||||
|
||||
$c->stash(form => $form);
|
||||
}
|
||||
|
||||
sub delete :Chained('base') :PathPart('delete') :Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
# $c->model('Provisioning')->contact($c->stash->{contact}->{id})->delete;
|
||||
$c->flash(messages => [{type => 'info', text => 'Contact delete not implemented!'}]);
|
||||
$c->response->redirect($c->uri_for());
|
||||
}
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Andreas Granig,,,
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
This library is free software. You can redistribute it and/or modify
|
||||
it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->meta->make_immutable;
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,51 @@
|
||||
package NGCP::Panel::Form::Contact;
|
||||
|
||||
use HTML::FormHandler::Moose;
|
||||
extends 'HTML::FormHandler';
|
||||
use Moose::Util::TypeConstraints;
|
||||
|
||||
use HTML::FormHandler::Widget::Block::Bootstrap;
|
||||
|
||||
has '+widget_wrapper' => ( default => 'Bootstrap' );
|
||||
sub build_render_list {[qw/fields actions/]}
|
||||
sub build_form_element_class { [qw/form-horizontal/] }
|
||||
|
||||
has_field 'firstname' => (
|
||||
type => 'Text',
|
||||
label => 'First Name',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
has_field 'lastname' => (
|
||||
type => 'Text',
|
||||
label => 'Last Name',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
|
||||
has_field 'email' => (
|
||||
type => 'Email',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
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/firstname lastname email/],
|
||||
);
|
||||
|
||||
has_block 'actions' => (
|
||||
tag => 'div',
|
||||
class => [qw/modal-footer/],
|
||||
render_list => [qw/save/],
|
||||
);
|
||||
|
||||
1;
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,54 @@
|
||||
package NGCP::Panel::Utils;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
sub check_redirect_chain {
|
||||
my %params = @_;
|
||||
|
||||
# TODO: check for missing fields
|
||||
my $c = $params{c};
|
||||
|
||||
if($c->session->{redirect_targets} && @{ $c->session->{redirect_targets} }) {
|
||||
my $target = ${ $c->session->{redirect_targets} }[0];
|
||||
if('/'.$c->request->path eq $target->path) {
|
||||
shift @{$c->session->{redirect_targets}};
|
||||
$c->stash(close_target => ${ $c->session->{redirect_targets} }[0]);
|
||||
} else {
|
||||
$c->stash(close_target => $target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_form_buttons {
|
||||
my %params = @_;
|
||||
|
||||
# TODO: check for missing fields
|
||||
my $c = $params{c};
|
||||
my $fields = $params{fields};
|
||||
my $form = $params{form};
|
||||
my $back_uri = $params{back_uri};
|
||||
|
||||
my $posted = ($c->request->method eq 'POST');
|
||||
|
||||
if($posted && $form->field('submitid')) {
|
||||
my $val = $form->field('submitid')->value;
|
||||
|
||||
if(grep {/^$val$/} @{ $fields }) {
|
||||
my $target = '/'.$val;
|
||||
$target =~ s/\./\//g;
|
||||
if($c->session->{redirect_targets}) {
|
||||
unshift @{ $c->session->{redirect_targets} }, $back_uri;
|
||||
} else {
|
||||
$c->session->{redirect_targets} = [ $back_uri ];
|
||||
}
|
||||
$c->response->redirect($c->uri_for($target));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,16 @@
|
||||
[% META title = 'Contacts' -%]
|
||||
[%
|
||||
helper.name = 'Contact';
|
||||
helper.data = contacts;
|
||||
helper.messages = messages;
|
||||
helper.column_titles = [ '#', 'First Name', 'Last Name', 'Email' ];
|
||||
helper.column_fields = [ 'id', 'firstname', 'lastname', 'email' ];
|
||||
|
||||
helper.close_target = close_target;
|
||||
helper.create_flag = create_flag;
|
||||
helper.edit_object = contact;
|
||||
helper.form_object = form;
|
||||
|
||||
PROCESS 'helpers/table_form.tt';
|
||||
-%]
|
||||
[% # vim: set tabstop=4 syntax=html expandtab: -%]
|
||||
Loading…
Reference in new issue