Check for correct date in billing weekday settings

agranig/1_0_subfix
Gerhard Jungwirth 12 years ago
parent 00d279f6d1
commit 25c535cda1

@ -455,9 +455,13 @@ sub peaktime_weekdays_edit :Chained('peaktime_weekdays_base') :PathPart('edit')
} }
$rs->delete(); $rs->delete();
} }
$form = NGCP::Panel::Form::BillingPeaktimeWeekdays->new
unless $form->has_errors;
$self->load_weekdays($c); $self->load_weekdays($c);
$c->stash(weekday => $c->stash->{weekdays}->[$c->stash->{weekday_id}]); $c->stash(weekday => $c->stash->{weekdays}->[$c->stash->{weekday_id}]);
$c->stash(form => NGCP::Panel::Form::BillingPeaktimeWeekdays->new); $c->stash(form => $form);
$c->stash(edit_flag => 1); $c->stash(edit_flag => 1);
} }

@ -3,7 +3,12 @@ package NGCP::Panel::Form::BillingPeaktimeWeekdays;
use HTML::FormHandler::Moose; use HTML::FormHandler::Moose;
use Moose; use Moose;
extends 'HTML::FormHandler'; extends 'HTML::FormHandler';
use HTML::FormHandler::Widget::Block::Bootstrap;
use Moose::Util::TypeConstraints; use Moose::Util::TypeConstraints;
use DateTime;
use DateTime::Format::Strptime;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'weekday' => ( has_field 'weekday' => (
type => 'Hidden', type => 'Hidden',
@ -12,24 +17,25 @@ has_field 'weekday' => (
has_field 'start' => ( has_field 'start' => (
type => 'Text', type => 'Text',
do_label => 0, do_label => 0,
do_wrapper => 0, do_wrapper => 1,
element_attr => { element_attr => {
class => ['ngcp_time_range'], class => ['ngcp_time_range'],
rel => ['tooltip'], rel => ['tooltip'],
title => ['The start time in format hh:mm:ss'] title => ['The start time in format hh:mm:ss']
}, },
wrapper_class => ['ngcp_field_inline'],
); );
has_field 'end' => ( has_field 'end' => (
type => 'Text', type => 'Text',
do_label => 0, do_label => 0,
do_wrapper => 0, do_wrapper => 1,
element_attr => { element_attr => {
class => ['ngcp_time_range'], class => ['ngcp_time_range'],
rel => ['tooltip'], rel => ['tooltip'],
title => ['The end time in format hh:mm:ss'] title => ['The end time in format hh:mm:ss']
}, },
wrapper_class => ['ngcp_field_inline'],
); );
has_field 'add' => ( has_field 'add' => (
@ -40,6 +46,23 @@ has_field 'add' => (
do_wrapper => 0, do_wrapper => 0,
); );
sub validate {
my $self = shift;
my $parsetime = DateTime::Format::Strptime->new(pattern => '%T');
my $parsetime2 = DateTime::Format::Strptime->new(pattern => '%R');
my $start = $parsetime->parse_datetime($self->field('start')->value)
|| $parsetime2->parse_datetime($self->field('start')->value);
my $end = $parsetime->parse_datetime($self->field('end')->value)
|| $parsetime2->parse_datetime($self->field('end')->value);
if ($end < $start) {
my $err_msg = 'Start time must be later than end time.';
$self->field('start')->add_error($err_msg);
$self->field('end')->add_error($err_msg);
}
}
1; 1;
__END__ __END__
@ -54,6 +77,10 @@ Preferences Form.
=head1 METHODS =head1 METHODS
=head2 validate
Checks if start time comes before end time.
=head1 AUTHOR =head1 AUTHOR
Gerhard Jungwirth Gerhard Jungwirth

@ -216,6 +216,12 @@ div.ngcp-modal .control-group.error .dataTables_wrapper input[type="text"] {
width: 67%; width: 67%;
float: right; float: right;
} }
.modal-body .control-group .controls input.ngcp_time_range { .modal-body div.ngcp_field_inline {
width: 43%; display: inline-block;
*display: inline;
width: 218px;
}
.modal-body div.ngcp_field_inline input {
width: 206px !important;
padding: 4px 6px !important;
} }

Loading…
Cancel
Save