web/lib/Zend/Dojo/Form/Element/Button.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Dojo
       
    17  * @subpackage Form_Element
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  */
       
    21 
       
    22 /** Zend_Dojo_Form_Element_Dijit */
       
    23 require_once 'Zend/Dojo/Form/Element/Dijit.php';
       
    24 
       
    25 /**
       
    26  * Button dijit
       
    27  *
       
    28  * @category   Zend
       
    29  * @package    Zend_Dojo
       
    30  * @subpackage Form_Element
       
    31  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  * @version    $Id: Button.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    34  */
       
    35 class Zend_Dojo_Form_Element_Button extends Zend_Dojo_Form_Element_Dijit
       
    36 {
       
    37     /**
       
    38      * Use Button dijit view helper
       
    39      * @var string
       
    40      */
       
    41     public $helper = 'Button';
       
    42 
       
    43     /**
       
    44      * Constructor
       
    45      *
       
    46      * @param  string|array|Zend_Config $spec Element name or configuration
       
    47      * @param  string|array|Zend_Config $options Element value or configuration
       
    48      * @return void
       
    49      */
       
    50     public function __construct($spec, $options = null)
       
    51     {
       
    52         if (is_string($spec) && ((null !== $options) && is_string($options))) {
       
    53             $options = array('label' => $options);
       
    54         }
       
    55 
       
    56         parent::__construct($spec, $options);
       
    57     }
       
    58 
       
    59     /**
       
    60      * Return label
       
    61      *
       
    62      * If no label is present, returns the currently set name.
       
    63      *
       
    64      * If a translator is present, returns the translated label.
       
    65      *
       
    66      * @return string
       
    67      */
       
    68     public function getLabel()
       
    69     {
       
    70         $value = parent::getLabel();
       
    71 
       
    72         if (null === $value) {
       
    73             $value = $this->getName();
       
    74         }
       
    75 
       
    76         if (null !== ($translator = $this->getTranslator())) {
       
    77             return $translator->translate($value);
       
    78         }
       
    79 
       
    80         return $value;
       
    81     }
       
    82 
       
    83     /**
       
    84      * Has this submit button been selected?
       
    85      *
       
    86      * @return bool
       
    87      */
       
    88     public function isChecked()
       
    89     {
       
    90         $value = $this->getValue();
       
    91 
       
    92         if (empty($value)) {
       
    93             return false;
       
    94         }
       
    95         if ($value != $this->getLabel()) {
       
    96             return false;
       
    97         }
       
    98 
       
    99         return true;
       
   100     }
       
   101 
       
   102     /**
       
   103      * Default decorators
       
   104      *
       
   105      * Uses only 'DijitElement' and 'DtDdWrapper' decorators by default.
       
   106      *
       
   107      * @return void
       
   108      */
       
   109     public function loadDefaultDecorators()
       
   110     {
       
   111         if ($this->loadDefaultDecoratorsIsDisabled()) {
       
   112             return;
       
   113         }
       
   114 
       
   115         $decorators = $this->getDecorators();
       
   116         if (empty($decorators)) {
       
   117             $this->addDecorator('DijitElement')
       
   118                  ->addDecorator('DtDdWrapper');
       
   119         }
       
   120     }
       
   121 }