=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(''); 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('