package II3562149e53818b6637b38680e87ba918::linkerpro; use strict; use Zen::Config; use Zen::ScriptSys; use II8b55f24974af3d53369c3d9cea404f55; sub get { my ($form, $f) = @_; my ($mode, $config) = split ',', Zen::PerlHandler->getStatList, 2; my $object = $form->getDecorated; my $cfg = _load_config($config); my $C = Zen->getRequest->getCtx; my $sys_uri = Zen::ScriptSys->getURI; my $SP = II8dae0e141ee45f5daba6a74e4a7c3b6f::IIlIlIlIIIlIIlll($II720d6e18aa34327713eb014408fc9144::lIlIIIIlIllllIIl{$II720d6e18aa34327713eb014408fc9144::lIIlIIIIlllIlIII},1009,$II720d6e18aa34327713eb014408fc9144::lIlIIIIlIllllIIl{$II982446f8950cc3dc59e487adba22df54::llIlIIIIllllIIII})->new($C); my ($url_selector, $url_editor, $url_searcher); $url_selector = $sys_uri . $SP->parse($cfg->{url_selector}); $url_editor = $sys_uri . $SP->parse($cfg->{url_editor}) if $cfg->{url_editor}; $url_searcher = $sys_uri . $SP->parse($cfg->{url_searcher}); my $pfx = $form->pfx; my $code = '<input type="hidden"/>'; if (Zen->hasRequest) { my $request = Zen->getRequest; my $ctx = $request->getCtx; unless ($ctx->{AtkListersJsIncidence}) { $code .= <<CODE;
<script language="JavaScript" src="$ENV{SCRIPT_NAME}/suppl/atk/linkers.js"></script>
CODE
$ctx->{AtkListersJsIncidence}++; } } $code .= <<CODE;
<div id="DivAtkLProWrapper$pfx$f"></div>
<script language="JavaScript">
{ var lnk = new atkLinkerPro('$mode', '$pfx$f', '$cfg->{trigger_textsize}', '$cfg->{trigger_timeout}', '$url_selector', '$url_editor', '$url_searcher', '$config'); lnk.makeHTML(document.getElementById('DivAtkLProWrapper$pfx$f'));
CODE
if (ref($object) ne 'HASH' && $object->{$f}) { my @list = map { $cfg->{persistent_class}->get($_) } split ',', $object->{$f}; for my $o (@list) { my $title = $o->getView->{$cfg->{view_field}}; $title =~ s/'/\\'/g; $code .= qq(\nlnk.receive('$o->{id}','$title');\n); } } $code .= "}\n</script>\n"; $code; } sub set { my ($form, $f, $v) = @_; my $object = $form->getDecorated; my (%h, @v); for (split ',', $v) { push @v, $_ unless $h{$_}++; } $object->{$f} = join ',', @v; } sub act_search { my $class = shift; my $request = Zen->getRequest; my $in = $request->getInput; for ($in->{keyword}) { s/^\s+//; s/\s+$//; } $request->printHeader; return unless $in->{linkerpro_id} && $in->{keyword} && $in->{config}; my $cfg = _load_config($in->{config}); my @sea; if ($cfg->{addon_search}) { $cfg->{addon_search} = IIb39071a48a82a07eeb9256f406abebc5::lIIlIIIlllllllII($II720d6e18aa34327713eb014408fc9144::lIIIlllIllIIlllI{$II982446f8950cc3dc59e487adba22df54::IlIllIIIlllIlIll},1009,$II720d6e18aa34327713eb014408fc9144::lIIIlllIllIIlllI{$II720d6e18aa34327713eb014408fc9144::IIllllllIIllllll})->new($in)->parse($cfg->{addon_search}); eval "\@sea = ($cfg->{addon_search})"; warn "*** error evaluating addon search parameters: $cfg->{addon_search}\n" if $@; } my $obj_class = $cfg->{persistent_class}; push @sea, ( FETCH => $obj_class->selectExpression, keyword => $in->{keyword}, ORDER => 'id desc', ); my $objects; if ($cfg->{persistent_query_mode}) { $objects = $obj_class->search(@sea); } else { $objects = $obj_class->dbc->getRecords($obj_class->_sql_constructor(\@sea)); my $cache = $obj_class->cache; for my $obj (@$objects) { $obj->{_stored} = 1; $obj = $obj_class->assume($obj); $cache->store($obj->{id}, $obj); } } my @ObjsView = map { $_->getView } @$objects; my $i = 0; for my $v (@ObjsView) { if (++$i > $cfg->{num_records}) { my $N = @ObjsView; print "atkLinker($in->{linkerpro_id}).appendMoreLink($N);"; last; } my $title = $v->{$cfg->{view_field}}; $title =~ s/'/\\'/g; print "atkLinker($in->{linkerpro_id}).receive('$v->{ID}','$title',false);"; } } sub _load_config { my $config = shift; my $cfg = Zen::Config->get($1)->{$2} if $config =~ /^(.+?)::(\w+)$/; die "config not found [$config]" unless defined $cfg; die "persistent_class not found in config [$config]" unless $cfg->{persistent_class}; die "view_field not found in config [$config]" unless $cfg->{view_field}; die "url_selector not found in config [$config]" unless $cfg->{url_selector}; eval "require $cfg->{persistent_class}"; die $@ if $@; $cfg; } 1; 