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

Source for file function.pnformbutton.php

Documentation is available at function.pnformbutton.php

  1. <?php
  2. /**
  3.  * Button plugin
  4.  *
  5.  * @copyright (c) 2006, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pnformbutton.php 24342 2008-06-06 12:03:14Z markwest $
  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.  * Button
  16.  *
  17.  * Buttons can be used to fire command events in your form event handler.
  18.  * When the user activates a button the command name and command argument
  19.  * will be sent to the form event handlers handleCommand function.
  20.  * Example:
  21.  * <code>
  22.  *  function handleCommand(&$render, &$args)
  23.  *  {
  24.  *    if ($args['commandName'] == 'update')
  25.  *    {
  26.  *      if (!$render->pnFormIsValid())
  27.  *        return false;
  28.  *
  29.  *      $data = $render->pnFormGetValues();
  30.  *
  31.  *      DBUtil::updateObject($data, 'demo_data');
  32.  *    }
  33.  *
  34.  *    return true;
  35.  *  }
  36.  * </code>
  37.  *
  38.  * The command arguments ($args) passed to the handler contains 'commandName' and
  39.  * 'commandArgument' with the values you passed to the button in the template.
  40.  *
  41.  * @package pnForm
  42.  * @subpackage Plugins
  43.  */
  44. {
  45.     /**
  46.      * Displayed text on the button
  47.      *
  48.      * You can use _XXX language defines directly as the text, no need to call <!--[pnml]--> for
  49.      * translation.
  50.      * @var string 
  51.      */
  52.     var $text;
  53.  
  54.     /**
  55.      * Name of command event handler method
  56.      * @var string Default is "handleCommand"
  57.      */
  58.     var $onCommand = 'handleCommand';
  59.  
  60.     /**
  61.      * Command name
  62.      * 
  63.      * This is the "commandName" parameter to pass in the event args of the command handler.
  64.      * @var string 
  65.      */
  66.     var $commandName;
  67.  
  68.     /**
  69.      * Command argument
  70.      *
  71.      * This value is passed in the event arguments to the form event handler as the commandArgument value.
  72.      * @var string 
  73.      */
  74.     var $commandArgument;
  75.  
  76.     /**
  77.      * Confirmation message
  78.      *
  79.      * If you set a confirmation message then a ok/cancel dialog box pops and asks the user to confirm
  80.      * the button click - very usefull for buttons that deletes items.
  81.      * You can use _XXX language defines directly as the message, no need to call <!--[pnml]--> for
  82.      * translation.
  83.      * @var string 
  84.      */
  85.     var $confirmMessage;
  86.  
  87.     /**
  88.      * CSS styling
  89.      *
  90.      * Please ignore - to be changed.
  91.      * @internal
  92.      */
  93.     var $styleHtml;
  94.  
  95.  
  96.     function getFilename()
  97.     {
  98.         return __FILE__// FIXME: may be found in smarty's data???
  99.     }
  100.  
  101.  
  102.     function render(&$render)
  103.     {
  104.         $idHtml $this->getIdHtml();
  105.  
  106.         $fullName $this->id '_' $this->commandName;
  107.  
  108.         $onclickHtml '';
  109.         if ($this->confirmMessage != null)
  110.         {
  111.           $msg $render->pnFormTranslateForDisplay($this->confirmMessage'?';
  112.           $onclickHtml " onclick=\"return confirm('$msg');\"";
  113.         }
  114.  
  115.         $text $render->pnFormTranslateForDisplay($this->text);
  116.  
  117.         $attributes $this->renderAttributes($render);
  118.  
  119.         $result "<input $idHtml type=\"submit\" name=\"$fullName\" value=\"$text\"$onclickHtml{$attributes}/>";
  120.  
  121.         return $result;
  122.     }
  123.  
  124.  
  125.     function decodePostBackEvent(&$render)
  126.     {
  127.         $fullName $this->id '_' $this->commandName;
  128.  
  129.         if (isset($_POST[$fullName]))
  130.         {
  131.             $args array('commandName' => $this->commandName,
  132.                           'commandArgument' => $this->commandArgument);
  133.             if (!empty($this->onCommand))
  134.                 if ($render->pnFormRaiseEvent($this->onCommand$args=== false)
  135.                     return false;
  136.         }
  137.  
  138.         return true;
  139.     }
  140. }
  141.  
  142.  
  143. function smarty_function_pnformbutton($params&$render)
  144. {
  145.     return $render->pnFormRegisterPlugin('pnFormButton'$params);
  146. }

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