Initial commit
This commit is contained in:
commit
f4bfb0e367
71 changed files with 10399 additions and 0 deletions
138
Dam/Components/Controls/Option.pm
Normal file
138
Dam/Components/Controls/Option.pm
Normal file
|
@ -0,0 +1,138 @@
|
|||
=head1 NAME
|
||||
|
||||
Dam::Components::Controls::Option
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
my $option = Component__Get(CONTROL_OPTION, ['option']);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Control para seleccionar una opción de una lista sencilla.
|
||||
|
||||
=head1 ARGUMENTS
|
||||
|
||||
(
|
||||
TYPE => 'Option',
|
||||
ID => 'opt' (default),
|
||||
INFO => 1 (show info in header; default) or 0 (don't show),
|
||||
LABEL => 'Options' (default),
|
||||
LABEL_INFO => Same as LABEL (default),
|
||||
REQUIRED => 1 (control required; default) or 0 (not required)
|
||||
OPTIONS => { 'op1' => 'Option 1', 'op2' => 'Option 2' } (default)
|
||||
)
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
package Dam::Components::Controls::Option;
|
||||
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw(
|
||||
Control__html Control__js Get
|
||||
);
|
||||
|
||||
use Dam::Util;
|
||||
use Dam::DamLogic;
|
||||
|
||||
|
||||
|
||||
my $ID_DEFAULT = 'option';
|
||||
|
||||
|
||||
|
||||
sub __arguments {
|
||||
my $arg_ref = shift;
|
||||
|
||||
$$arg_ref{LABEL} = _t('Options') 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 ],
|
||||
OPTIONS => [ ARG_DEFAULT, { 'op1' => strval(_t('Option'), ' 1'), 'op2' => strval(_t('Option'), ' 2') } ]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub Control__html {
|
||||
my ($self, $arg_ref, $info_ref) = @_;
|
||||
|
||||
__arguments($arg_ref);
|
||||
|
||||
my $opt_value = cgiapp_param($$arg_ref{ID});
|
||||
|
||||
my $list_opts = $$arg_ref{REQUIRED} ? '' : strval('<option value="" title=""></option>');
|
||||
for my $key (sort keys(%{$$arg_ref{OPTIONS}})) {
|
||||
my $selected = '">';
|
||||
if (is_eq($opt_value, $key)) {
|
||||
$selected = '" selected="selected">';
|
||||
push(@{$info_ref}, { DATA => $$arg_ref{LABEL_INFO}, VALUE => ${$$arg_ref{OPTIONS}}{$key} }) if $$arg_ref{INFO};
|
||||
}
|
||||
$list_opts .= strval('<option value="', $key, '" title="', ${$$arg_ref{OPTIONS}}{$key}, $selected, ${$$arg_ref{OPTIONS}}{$key}, '</option>');
|
||||
}
|
||||
|
||||
return strval('
|
||||
<div class="form-group form-group-', $ID_DEFAULT, '">
|
||||
<label for="', $$arg_ref{ID}, $$arg_ref{REQUIRED} ? '" class="required">' : '">', $$arg_ref{LABEL}, '</label>
|
||||
<select class="form-control input-lg" id="', $$arg_ref{ID}, '" name="', $$arg_ref{ID}, '"', $$arg_ref{REQUIRED} ? ' required="required">' : '>', $list_opts, '</select>
|
||||
</div>
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub Control__js {
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub Get {
|
||||
my ($self, $id) = @_;
|
||||
|
||||
$id = $ID_DEFAULT if is_empty($id);
|
||||
|
||||
return cgiapp_param($id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
|
Reference in a new issue