=head1 NAME
Dam::Components::Controls::MultiCheck
=head1 SYNOPSIS
my @checks = Component__Get(CONTROL_MULTICHECK, ['multicheck']);
=head1 DESCRIPTION
Control para seleccionar una o más opciones de una lista.
=head1 ARGUMENTS
(
TYPE => 'MultiCheck',
ID => 'multicheck' (default),
INFO => 1 (show info in header; default) or 0 (don't show),
LABEL => 'MultiCheck' (default),
LABEL_INFO => Same as LABEL (default),
REQUIRED => 1 (control required; default) or 0 (not required)
MULTIPLE => 1 (allows to select any number of options; default) or 0 (allows
to select only one option),
OPTIONS => { 'op1' => 'Option 1', 'op2' => 'Option 2' } (default); you can
use { ..., 'opN' => _DIVIDER_, ... } to include separators
between the options according to order,
DEFAULT => Default option(s), e.g. "'op1'" or "'op1','op3'"
)
=cut
use strict;
use warnings;
use utf8;
package Dam::Components::Controls::MultiCheck;
use Exporter qw(import);
our @EXPORT = qw(
Control__html Control__js Get
);
use Dam::Util;
use Dam::DamLogic;
my $ID_DEFAULT = 'multicheck';
sub __arguments {
my $arg_ref = shift;
$$arg_ref{LABEL} = 'MultiCheck' 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 ],
MULTIPLE => [ ARG_DEFAULT, 1, 0 ],
OPTIONS => [ ARG_DEFAULT, { 'op1' => strval(_t('Option'), ' 1'), 'op2' => strval(_t('Option'), ' 2') } ],
DEFAULT => [ ARG_OPTIONAL ]
);
}
sub Control__html {
my ($self, $arg_ref, $info_ref) = @_;
__arguments($arg_ref);
my $multicheck_value = !is_report() && !is_empty($$arg_ref{DEFAULT}) ? $$arg_ref{DEFAULT} : strval_join(',', cgiapp_multi($$arg_ref{ID}));
my $form_group = 'form-group';
my $list_opts = '';
my $info_opts = '';
my $count_opts = 0;
for my $key (sort keys(%{$$arg_ref{OPTIONS}})) {
if (is_eq(${$$arg_ref{OPTIONS}}{$key}, _DIVIDER_)) {
$list_opts .= '';
}
else {
my $checked = defined($multicheck_value) && index($multicheck_value, $key) >= 0;
my $selected = $checked ? '" selected="selected">' : '">';
$list_opts .= strval('