package II1b4055e43647c5076890f5400944c314::mod_select; use strict; use Zen::Config; sub process { my $class = shift; my ($action, $value, $config, $element_id, $edit_class, $edit_rec_id, $edit_field) = @_; my $cfg = _load_config($config); my $code; if ($cfg->{priv_check_handler}) { if (my $denied_msg = Zen::PerlHandler->get($cfg->{priv_check_handler})->do) { return $denied_msg; } } if ($action eq 'change') { eval "require $edit_class"; die $@ if $@; $edit_class->get($edit_rec_id)->set($edit_field => $value)->save; $action = undef; } if (! $action) { my $title = $value ? $cfg->{data_config_parsed} ? $cfg->{data_config_parsed}{$value} : $cfg->{persistent_class}->get($value)->{$cfg->{view_field}} : $cfg->{no_value_title}; $title ||= '[NO TITLE]'; $code = qq(<a href="#" onClick="ajax$element_id('show', '$value'); return false">[$title]</a>); } elsif ($action eq 'show') { my (@values, %labels); if ($cfg->{data_config_parsed}) { @values = keys %{ $cfg->{data_config_parsed} }; %labels = map { $_ => $cfg->{data_config_parsed}{$_} } @values; } else { my @sea; push @sea, ORDER => $cfg->{order_field} if $cfg->{order_field}; push @sea, @{ $cfg->{addon_search_parsed} } if $cfg->{addon_search_parsed}; my $objects = $cfg->{persistent_class}->search(@sea); @values = map { $_->{id} } @$objects; %labels = map { $_->{id} => $_->{$cfg->{view_field}} } @$objects; } $code = II3562149e53818b6637b38680e87ba918::perllist::buildList('select', $element_id.'_sel', $value, \@values, \%labels, '='.$cfg->{no_value_title}, qq(onChange="ajax$element_id('change', this.options[this.selectedIndex].value)")); } else { die "unknown action [$action]"; } $code .= Zen::PerlHandler->get($cfg->{attendant_content_handler})->do($action, $value, $element_id, $edit_class, $edit_rec_id, $edit_field) if $cfg->{attendant_content_handler}; $code; } sub _load_config { my $config = shift; my $cfg = Zen::Config->get($1)->{$2} if $config =~ /^(.+?)::(\w+)$/; die "config not found [$config]" unless defined $cfg; if (my $data_config = $cfg->{data_config}) { my $data = $data_config =~ /^(.+?)::(\w+)$/ ? Zen::Config->get($1)->{$2} : die; $cfg->{data_config_parsed} = $data; } else { die "persistent_class not found in config [$config]" unless $cfg->{persistent_class}; die "view_field not found in config [$config]" unless $cfg->{view_field}; eval "require $cfg->{persistent_class}"; die $@ if $@; if (my $addon_search = $cfg->{addon_search}) { my $in = Zen->getRequest->getInput; $addon_search =~ s!\#\{INPUT\.(\w+)\}!$in->{$1}!g; eval "\$cfg->{addon_search_parsed} = [$addon_search]"; } } $cfg; } 1; 