Zikula_Template_Plugins
[ class tree: Zikula_Template_Plugins ] [ index: Zikula_Template_Plugins ] [ all elements ]

Source for file function.pnformcontextmenuitem.php

Documentation is available at function.pnformcontextmenuitem.php

  1. <?php
  2. /**
  3.  * Context menu plugin
  4.  *
  5.  * @copyright (c) 2006, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pnformdateinput.php 21129 2007-01-19 19:08:26Z jornlind $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Jorn Wildt
  10.  * @package Zikula_Template_Plugins
  11.  * @subpackage Functions
  12.  */
  13.  
  14.  
  15. /**
  16.  * Context menu item
  17.  *
  18.  * This plugin represents a menu item.
  19.  *
  20.  * @see pnFormContextMenu
  21.  *
  22.  * @package pnForm
  23.  * @subpackage Plugins
  24. */
  25. {
  26.     /**
  27.      * Menu title
  28.      *
  29.      * Language constants can be used here.
  30.      *
  31.      * @var string 
  32.      */
  33.     var $title;
  34.  
  35.  
  36.     var $imageURL;
  37.  
  38.     /**
  39.      * Command name passed to the event handler
  40.      *
  41.      * @var string 
  42.      */
  43.     var $commandName;
  44.  
  45.  
  46.     /**
  47.      * JavaScript code to execute when menu item is selected
  48.      *
  49.      * Your script will be wrapped in a function that passes a parameter "commandArgument". This parameter
  50.      * contains the command argument of the pnformcontextmenureference plugin. In this way your script
  51.      * can work with the menu item data you clicked. Example:
  52.      * <code>
  53.      * <!--[pnformcontextmenuitem title=Preview imageURL="preview.gif" commandScript="popupPreview(commandArgument)"]-->
  54.      *
  55.      * <script type="text/javascript">
  56.      * function popupPreview(commandArgument)
  57.      * {
  58.      *   alert(commandArgument);
  59.      * }
  60.      * </script>
  61.      * </code>
  62.      *
  63.      * @var string 
  64.      */
  65.     var $commandScript;
  66.  
  67.  
  68.     /**
  69.      * URL to redirect to when menu item is selected
  70.      *
  71.      * You can place {commandArgument} (including the braces) in your URL. This will get substituted with the
  72.      * command argument value of the pnformcontextmenureference plugin. In this way you can redirect to something
  73.      * depending on data.
  74.      * @var string 
  75.      */
  76.     var $commandRedirect;
  77.  
  78.  
  79.     /**
  80.      * Confirmation message
  81.      *
  82.      * If you set a confirmation message then a ok/cancel dialog box pops and asks the user to confirm
  83.      * the menu item click - very usefull for menu selections that deletes items.
  84.      * You can use _XXX language defines directly as the message, no need to call <!--[pnml]--> for
  85.      * translation.
  86.      * @var string 
  87.      */
  88.     var $confirmMessage;
  89.  
  90.  
  91.     function getFilename()
  92.     {
  93.         return __FILE__;
  94.     }
  95.  
  96.         
  97.     function create(&$render&$params)
  98.     {
  99.     }
  100.  
  101.  
  102.     function render(&$render)
  103.     {
  104.         $contextMenu =$this->getParentContextMenu();
  105.  
  106.         // Avoid creating menu multiple times if included in a repeated template
  107.         if (!$contextMenu->firstTime())
  108.             return '';
  109.  
  110.         if (!empty($this->commandName))
  111.         {
  112.             $click 'javascript:' $this->renderConfirm($render$render->pnFormGetPostBackEventReference($this$this->commandName));
  113.         }
  114.         else if (!empty($this->commandScript))
  115.         {
  116.             $hiddenName "contentMenuArgument" $contextMenu->id;
  117.             $click 'javascript:' $this->renderConfirm($render"pnForm.contextMenu.commandScript('$hiddenName', function(commandArgument){$this->commandScript . "})");
  118.         }
  119.         else if (!empty($this->commandRedirect))
  120.         {
  121.             $hiddenName "contentMenuArgument" $contextMenu->id;
  122.             $url urlencode($this->commandRedirect);
  123.             $click 'javascript:' $this->renderConfirm($render"pnForm.contextMenu.redirect('$hiddenName','$url')");
  124.         }
  125.         else
  126.         {
  127.             pn_exit('Missing commandName, commandScript, or commandRedirect in context menu item');
  128.         }
  129.  
  130.         $url $click;
  131.         $title $render->pnFormTranslateForDisplay($this->title);
  132.  
  133.         if (!empty($this->imageURL))
  134.         {
  135.             $style " style=\"background-image: url($this->imageURL)\"";
  136.         }
  137.         else
  138.         {
  139.             $style'';
  140.         }
  141.  
  142.         $html "<li$style><a href=\"$url\">$title</a></li>";
  143.  
  144.         return $html;
  145.     }
  146.  
  147.  
  148.     function renderConfirm(&$render$script)
  149.     {
  150.         if (!empty($this->confirmMessage))
  151.         {
  152.             $msg $render->pnFormTranslateForDisplay($this->confirmMessage'?';
  153.             return "if (confirm('$msg')) { $script }";
  154.         }
  155.         else
  156.             return $script;
  157.     }
  158.  
  159.  
  160.     // Called by pnForms framework due to the use of pnFormGetPostBackEventReference() above
  161.     function raisePostBackEvent(&$render$eventArgument)
  162.     {
  163.         $contextMenu =$this->getParentContextMenu();
  164.  
  165.         $hiddenName "contentMenuArgument" $contextMenu->id;
  166.         $commandArgument FormUtil::getPassedValue($hiddenNamenull'POST');
  167.  
  168.         $args array('commandName' => $eventArgument'commandArgument' => $commandArgument);
  169.         $render->pnFormRaiseEvent($contextMenu->onCommand == null 'handleCommand' $contextMenu->onCommand$args);
  170.     }
  171.  
  172.  
  173.     function getParentContextMenu()
  174.     {
  175.         // Locate parent context menu
  176.         $contextMenu &$this->parentPlugin;
  177.  
  178.         while ($contextMenu != null  &&  strcasecmp(get_class($contextMenu)'pnformcontextmenu'!= 0)
  179.             $contextMenu &$contextMenu->parentPlugin;
  180.  
  181.         return $contextMenu;
  182.     }
  183. }
  184.  
  185.  
  186. function smarty_function_pnformcontextmenuitem($params&$render)
  187. {
  188.     return $render->pnFormRegisterPlugin('pnFormContextMenuItem'$params);
  189. }

Documentation generated on Fri, 18 Jul 2008 21:45:46 +0200 by phpDocumentor 1.4.1