177 lines
4.3 KiB
Perl
177 lines
4.3 KiB
Perl
=head1 NAME
|
|
|
|
Dam::Components::Controls::Month
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
my ($year, $month) = Component__Get(CONTROL_MONTH, ['month']);
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Control para seleccionar un mes del año.
|
|
|
|
=head1 ARGUMENTS
|
|
|
|
(
|
|
TYPE => 'Month',
|
|
ID => 'month' (default),
|
|
INFO => 1 (show info in header; default) or 0 (don't show),
|
|
LABEL => 'Month' (default),
|
|
LABEL_INFO => Same as LABEL (default),
|
|
REQUIRED => 1 (control required; default) or 0 (not required)
|
|
)
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
use utf8;
|
|
|
|
package Dam::Components::Controls::Month;
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw(
|
|
Control__html Control__js Get
|
|
);
|
|
|
|
use Date::Calc qw(Today);
|
|
|
|
use Dam::Util;
|
|
use Dam::DamLogic;
|
|
use Dam::Var;
|
|
|
|
|
|
|
|
my $ID_DEFAULT = 'month';
|
|
|
|
|
|
|
|
sub __arguments {
|
|
my $arg_ref = shift;
|
|
|
|
$$arg_ref{LABEL} = _t('Month') if is_empty($$arg_ref{LABEL});
|
|
$$arg_ref{LABEL_INFO} = $$arg_ref{LABEL} if is_empty($$arg_ref{LABEL_INFO});
|
|
|
|
check_arguments($arg_ref,
|
|
TYPE => [ ARG_REQUIRED ],
|
|
ID => [ ARG_DEFAULT, $ID_DEFAULT ],
|
|
INFO => [ ARG_DEFAULT, 1, 0 ],
|
|
LABEL => [ ARG_REQUIRED ],
|
|
LABEL_INFO => [ ARG_REQUIRED ],
|
|
REQUIRED => [ ARG_DEFAULT, 1, 0 ]
|
|
);
|
|
}
|
|
|
|
|
|
|
|
sub Control__html {
|
|
my ($self, $arg_ref, $info_ref) = @_;
|
|
|
|
__arguments($arg_ref);
|
|
|
|
my $value = cgiapp_param($$arg_ref{ID});
|
|
|
|
my @today = Today();
|
|
my ($month_name, $month_value, $year_value) = ('', $today[1], $today[0]);
|
|
|
|
if (!is_report() || is_empty($value)) {
|
|
if ($month_value == 1) {
|
|
$month_value = 12;
|
|
$year_value--;
|
|
}
|
|
else {
|
|
$month_value--;
|
|
}
|
|
$month_name = _t('MONTHS', $month_value);
|
|
}
|
|
else {
|
|
($month_name, $year_value) = split(/ /, $value);
|
|
$month_value = _t('MONTHS', $month_name);
|
|
}
|
|
push(@{$info_ref}, { DATA => $$arg_ref{LABEL_INFO}, VALUE => "$month_name $year_value" }) if $$arg_ref{INFO};
|
|
|
|
# Required stylesheets:
|
|
Component__Header(ADD => 'CSS', RESOURCE => PACK_DATEPICKER);
|
|
|
|
return strval('
|
|
<div class="form-group form-group-', $ID_DEFAULT, '">
|
|
<label for="', $$arg_ref{ID}, $$arg_ref{REQUIRED} ? '" class="required">' : '">', $$arg_ref{LABEL}, '</label>
|
|
<input type="text" class="form-control input-lg input-date-month" data-provide="datepicker" id="', $$arg_ref{ID}, '" name="', $$arg_ref{ID}, '" value="', $month_name, ' ', $year_value, '" autocomplete="off" size=4', $$arg_ref{REQUIRED} ? ' required="required"' : '', ' />
|
|
</div>
|
|
');
|
|
}
|
|
|
|
|
|
|
|
sub Control__js {
|
|
my ($self, $arg_ref) = @_;
|
|
|
|
__arguments($arg_ref);
|
|
|
|
my @today = Today();
|
|
|
|
# Required javascripts:
|
|
Component__Header(ADD => 'JS', RESOURCE => PACK_DATEPICKER);
|
|
|
|
return strval('
|
|
$(function(){
|
|
$("#', $$arg_ref{ID}, '").datepicker({
|
|
language: "', _t('LANGUAGE_CODE'), '",
|
|
autoclose: true,
|
|
todayHighlight: true,
|
|
disableTouchKeyboard: true,
|
|
minViewMode: "months",
|
|
format: "MM yyyy",
|
|
endDate: "', $today[1] - 1, '-', $today[0], '"
|
|
});
|
|
});
|
|
');
|
|
}
|
|
|
|
|
|
|
|
sub Get {
|
|
my ($self, $id) = @_;
|
|
|
|
$id = $ID_DEFAULT if is_empty($id);
|
|
|
|
my $value = cgiapp_param($id);
|
|
return (undef, undef) if is_empty($value);
|
|
my ($month_name, $year_value) = split(/ /, $value);
|
|
my $month_value = _t('MONTHS', $month_name);
|
|
return ($year_value, $month_value);
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
=head1 AUTHOR
|
|
|
|
Manuel Cillero C<< <manuel@cillero.es> >>
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
|
|
=cut
|