From f908c19483d0a943a5d2fd2e35d568382cab5ea1 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 10 May 2013 13:45:10 +0200 Subject: [PATCH] outsource modal, introduce peaktime page modal uses a separate template file now the weekdays edit modal is WIP --- lib/NGCP/Panel/Controller/Billing.pm | 57 ++++++++++++++ .../Panel/Form/BillingPeaktimeWeekdays.pm | 57 ++++++++++++++ share/static/css/main.css | 1 + share/templates/billing/peaktimes.tt | 76 +++++++++++++++++++ share/templates/helpers/datatables.tt | 30 ++------ share/templates/helpers/modal.tt | 34 +++++++++ share/templates/helpers/pref_table.tt | 16 ++-- 7 files changed, 243 insertions(+), 28 deletions(-) create mode 100644 lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm create mode 100644 share/templates/billing/peaktimes.tt create mode 100644 share/templates/helpers/modal.tt diff --git a/lib/NGCP/Panel/Controller/Billing.pm b/lib/NGCP/Panel/Controller/Billing.pm index ec4e2aa3b4..e8dc64d8ec 100644 --- a/lib/NGCP/Panel/Controller/Billing.pm +++ b/lib/NGCP/Panel/Controller/Billing.pm @@ -7,8 +7,11 @@ BEGIN { extends 'Catalyst::Controller'; } use NGCP::Panel::Form::BillingProfile; use NGCP::Panel::Form::BillingFee; use NGCP::Panel::Form::BillingZone; +use NGCP::Panel::Form::BillingPeaktimeWeekdays; use NGCP::Panel::Utils; +my @WEEKDAYS = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday); + sub profile_list :Chained('/') :PathPart('billing') :CaptureArgs(0) :Args(0) { my ( $self, $c ) = @_; @@ -326,6 +329,60 @@ sub zones_delete :Chained('zones_base') :PathPart('delete') :Args(0) { $c->response->redirect($c->stash->{zones_root_uri}); } +sub peaktimes_list :Chained('base') :PathPart('peaktimes') :CaptureArgs(0) { + my ($self, $c) = @_; + + my @weekdays; + for(0 .. 6) { + $weekdays[$_] = { + name => $WEEKDAYS[$_], + ranges => [], + edit_link => $c->uri_for_action("/billing/peaktime_weekdays_edit", + [$c->req->captures->[0], $_]), + }; + } + + my $rs = $c->stash->{profile_result}->billing_peaktime_weekdays; + + foreach my $range ($rs->all) { + push @{ $weekdays[$range->weekday]->{ranges} }, { + start => $range->start, + end => $range->end, + id => $range->id, + } + } + + $c->stash(weekdays => \@weekdays); + $c->stash(template => 'billing/peaktimes.tt'); +} + +sub peaktimes :Chained('peaktimes_list') :PathPart('') :Args(0) { + my ($self, $c) = @_; +} + +sub peaktime_weekdays_base :Chained('peaktimes_list') :PathPart('weekday') :CaptureArgs(1) { + my ($self, $c, $weekday_id) = @_; + unless (defined $weekday_id && $weekday_id >= 0 && $weekday_id <= 6) { + $c->flash(messages => [{ + type => 'error', + text => 'This weekday does not exist.' + }]); + $c->response->redirect($c->uri_for_action( + "/billing/peaktimes", [$c->req->captures->[0]], + )); + } + $c->stash(weekday => $c->stash->{weekdays}->[$weekday_id]); +} + +sub peaktime_weekdays_edit :Chained('peaktime_weekdays_base') :PathPart('edit') :Args(0) { + my ($self, $c) = @_; + + my $form = NGCP::Panel::Form::BillingPeaktimeWeekdays->new; + + $c->stash(form => $form); + $c->stash(edit_flag => 1); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm b/lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm new file mode 100644 index 0000000000..88f6df154b --- /dev/null +++ b/lib/NGCP/Panel/Form/BillingPeaktimeWeekdays.pm @@ -0,0 +1,57 @@ +package NGCP::Panel::Form::BillingPeaktimeWeekdays; + +use HTML::FormHandler::Moose; +use Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +has_field 'weekday' => ( + type => 'Hidden', +); + +has_field 'start' => ( + type => 'Text', + do_label => 0, + do_wrapper => 0, +); + +has_field 'end' => ( + type => 'Text', + do_label => 0, + do_wrapper => 0, +); + +has_field 'add' => ( + type => 'Submit', + value => 'Add', + element_class => [qw/btn btn-primary/], + do_label => 0, + do_wrapper => 0, +); + +1; + +__END__ + +=head1 NAME + +NGCP::Panel::Form::BillingPeaktimeWeekdays + +=head1 DESCRIPTION + +Preferences Form. + +=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: diff --git a/share/static/css/main.css b/share/static/css/main.css index b58cd85f25..0877c8240e 100644 --- a/share/static/css/main.css +++ b/share/static/css/main.css @@ -80,6 +80,7 @@ table.ngcp-datatable .headerSortUp:after { } .ngcp-actions-column { /* TODO: use responsive design */ + width: 10px; white-space: nowrap; } diff --git a/share/templates/billing/peaktimes.tt b/share/templates/billing/peaktimes.tt new file mode 100644 index 0000000000..0f51d92c51 --- /dev/null +++ b/share/templates/billing/peaktimes.tt @@ -0,0 +1,76 @@ +[% site_config.title = 'Off-peak-times for ' _ profile.name -%] + +< Back + +[% IF messages -%] +
+ [% FOREACH m IN messages -%] +
[% m.text %]
+ [% END -%] +
+[% END -%] + +
+ +

Weekdays

+ + + + + + + [% #Actions %] + + + + [% FOR w IN weekdays %] + + + + + + [% END %] + +
WeekdayStart - End
[% w.name %] + [% FOR r IN w.ranges %] + [% r.start %] – [% r.end %]
+ [% END %] +
+ [% IF w.edit_link %] + + [% END %] +
+ +

Dates

+ + +[% IF edit_flag -%] +[% + PROCESS "helpers/modal.tt"; + modal_header(m.name = weekday.name); +-%] + + + +[% + modal_footer(); + modal_script(m.close_target = c.uri_for_action('/billing/peaktimes', [c.req.captures.0])); +-%] +[% END -%] +[% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index 50ec65ef4f..fc91f3df71 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -110,28 +110,14 @@ $(document).ready(function() { [% IF helper.edit_flag || helper.create_flag == 1 -%] - - +[% + PROCESS "helpers/modal.tt"; + modal_header(m.create_flag=helper.create_flag, + m.name = helper.name); + helper.form_object.render; + modal_footer(); + modal_script(m.close_target = helper.close_target); +-%] [% END -%] [% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/helpers/modal.tt b/share/templates/helpers/modal.tt new file mode 100644 index 0000000000..9240dc78f7 --- /dev/null +++ b/share/templates/helpers/modal.tt @@ -0,0 +1,34 @@ +[% MACRO modal_header BLOCK -%] + + +[% END -%] + +[% MACRO modal_script BLOCK %] + +[% END -%] + +[% # vim: set tabstop=4 syntax=html expandtab: -%] + diff --git a/share/templates/helpers/pref_table.tt b/share/templates/helpers/pref_table.tt index b39092a7f8..d6a261bc2d 100644 --- a/share/templates/helpers/pref_table.tt +++ b/share/templates/helpers/pref_table.tt @@ -102,11 +102,13 @@ $(function() { [% IF helper.edit_preference -%] -