package WebGUI::Operation::FormHelpers; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2006 Plain Black Corporation. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use strict; use WebGUI::Asset; use WebGUI::HTMLForm; =head1 NAME Package WebGUI::Operation::FormHelpers =head1 DESCRIPTION Operational support for various things relating to forms and rich editors. #------------------------------------------------------------------- =head2 www_formAssetTree ( $session ) Returns a list of the all the current Asset's children as form. The children can be filtered via the form variable C. A crumb trail is provided for navigation. =cut sub www_formAssetTree { my $session = shift; my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); my @crumb; my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1}); foreach my $ancestor (@{$ancestors}) { push(@crumb,'form->process("classLimiter").";formId=" .$session->form->process("formId")).'">'.$ancestor->get("menuTitle").''); } my $output = '

'.join(" > ", @crumb)."

\n"; my $children = $base->getLineage(["children"],{returnObjects=>1}); foreach my $child (@{$children}) { next unless $child->canView; if ($child->get("className") =~ /^$session->form->process("classLimiter")/) { $output .= 'getId.'\';window.opener.document.getElementById(\''. $session->form->process("formId").'_display\').value=\''.$child->get("title").'\';window.close();">(•) '; } else { $output .= "(•) "; } $output .= 'form->process("classLimiter").";formId=" .$session->form->process("formId")).'">'.$child->get("menuTitle").''."
\n"; } $session->style->useEmptyStyle("1"); return $output; } #------------------------------------------------------------------- =head2 www_richEditPageTree ( $session ) Asset picker for the rich editor. =cut sub www_richEditPageTree { my $session = shift; my $i18n = WebGUI::International->new($session); my $f = WebGUI::HTMLForm->new($session,-action=>"#",-extras=>'name"linkchooser"'); $f->text( -name=>"url", -label=>$i18n->get(104), -hoverHelp=>$i18n->get('104 description'), ); $f->selectBox( -name=>"target", -label=>$i18n->get('target'), -hoverHelp=>$i18n->get('target description'), -options=>{"_self"=>$i18n->get('link in same window'), "_blank"=>$i18n->get('link in new window')}, ); $f->button( -value=>$i18n->get('done'), -extras=>'onclick="createLink()"' ); $session->style->setScript($session->config->get("extrasURL")."/tinymce/jscripts/tiny_mce/tiny_mce_popup.js",{type=>"text/javascript"}); my $output = '
'.$i18n->get('insert a link').'
'.$i18n->get('insert a link').''.$f->print.'
'.$i18n->get('pages').' '; my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); my @crumb; my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1}); foreach my $ancestor (@{$ancestors}) { push(@crumb,''.$ancestor->get("menuTitle").''); } $output .= '

'.join(" > ", @crumb)."

\n"; my $children = $base->getLineage(["children"],{returnObjects=>1}); foreach my $child (@{$children}) { next unless $child->canView; $output .= '(•) '.$child->get("menuTitle").''."
\n"; } $session->style->useEmptyStyle("1"); return $output.'
'; } #------------------------------------------------------------------- =head2 www_richEditImageTree ( $session ) Similar to www_formAssetTree, except it is limited to only display assets of class WebGUI::Asset::File::Image. Each link display a thumbnail of the image via www_richEditViewThumbnail. =cut sub www_richEditImageTree { my $session = shift; my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); my @crumb; my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1}); foreach my $ancestor (@{$ancestors}) { push(@crumb,''.$ancestor->get("menuTitle").''); } my $output = '

'.join(" > ", @crumb)."

\n"; my $children = $base->getLineage(["children"],{returnObjects=>1}); foreach my $child (@{$children}) { next unless $child->canView; if ($child->get("className") =~ /^WebGUI::Asset::File::Image/) { $output .= '(•) '; } else { $output .= "(•) "; } $output .= ''.$child->get("menuTitle").''."
\n"; } $session->style->useEmptyStyle("1"); return $output; } #------------------------------------------------------------------- =head2 www_richEditViewThumbnail ( $session ) Displays a thumbnail of an Image Asset in the Image manager for the Rich Editor. The current URL in the session object is used to determine which Image is used. =cut sub www_richEditViewThumbnail { my $session = shift; my $image = WebGUI::Asset->newByUrl($session); my $i18n = WebGUI::International->new($session); $session->style->useEmptyStyle("1"); if ($image->get("className") =~ /WebGUI::Asset::File::Image/) { my $output = '
'; $output .= ''.$i18n->get('preview').''; $output .= '
'; $output .= $image->get("filename"); $output .= '
'; $output .= '\n"; return $output; } return '
'.$i18n->get('image manager').'
'; } 1;