File indexing completed on 2024-12-29 05:27:35
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Dojo 0017 * @subpackage View 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Dojo_View_Helper_Dijit */ 0024 // require_once 'Zend/Dojo/View/Helper/Dijit.php'; 0025 0026 /** 0027 * Dojo ComboBox dijit 0028 * 0029 * @uses Zend_Dojo_View_Helper_Dijit 0030 * @package Zend_Dojo 0031 * @subpackage View 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Dojo_View_Helper_ComboBox extends Zend_Dojo_View_Helper_Dijit 0036 { 0037 /** 0038 * Dijit being used 0039 * @var string 0040 */ 0041 protected $_dijit = 'dijit.form.ComboBox'; 0042 0043 /** 0044 * HTML element type 0045 * @var string 0046 */ 0047 protected $_elementType = 'text'; 0048 0049 /** 0050 * Dojo module to use 0051 * @var string 0052 */ 0053 protected $_module = 'dijit.form.ComboBox'; 0054 0055 /** 0056 * dijit.form.ComboBox 0057 * 0058 * @param int $id 0059 * @param mixed $value 0060 * @param array $params Parameters to use for dijit creation 0061 * @param array $attribs HTML attributes 0062 * @param array|null $options Select options 0063 * @return string 0064 */ 0065 public function comboBox($id, $value = null, array $params = array(), array $attribs = array(), array $options = null) 0066 { 0067 $html = ''; 0068 if (!array_key_exists('id', $attribs)) { 0069 $attribs['id'] = $id; 0070 } 0071 if (array_key_exists('store', $params) && is_array($params['store'])) { 0072 // using dojo.data datastore 0073 if (false !== ($store = $this->_renderStore($params['store'], $id))) { 0074 $params['store'] = $params['store']['store']; 0075 if (is_string($store)) { 0076 $html .= $store; 0077 } 0078 $html .= $this->_createFormElement($id, $value, $params, $attribs); 0079 return $html; 0080 } 0081 unset($params['store']); 0082 } elseif (array_key_exists('store', $params)) { 0083 if (array_key_exists('storeType', $params)) { 0084 $storeParams = array( 0085 'store' => $params['store'], 0086 'type' => $params['storeType'], 0087 ); 0088 unset($params['storeType']); 0089 if (array_key_exists('storeParams', $params)) { 0090 $storeParams['params'] = $params['storeParams']; 0091 unset($params['storeParams']); 0092 } 0093 if (false !== ($store = $this->_renderStore($storeParams, $id))) { 0094 if (is_string($store)) { 0095 $html .= $store; 0096 } 0097 } 0098 } 0099 $html .= $this->_createFormElement($id, $value, $params, $attribs); 0100 return $html; 0101 } 0102 0103 // required for correct type casting in declerative mode 0104 if (isset($params['autocomplete'])) { 0105 $params['autocomplete'] = ($params['autocomplete']) ? 'true' : 'false'; 0106 } 0107 // do as normal select 0108 $attribs = $this->_prepareDijit($attribs, $params, 'element'); 0109 return $this->view->formSelect($id, $value, $attribs, $options); 0110 } 0111 0112 /** 0113 * Render data store element 0114 * 0115 * Renders to dojo view helper 0116 * 0117 * @param array $params 0118 * @return string|false 0119 */ 0120 protected function _renderStore(array $params, $id) 0121 { 0122 if (!array_key_exists('store', $params) || !array_key_exists('type', $params)) { 0123 return false; 0124 } 0125 0126 $this->dojo->requireModule($params['type']); 0127 0128 $extraParams = array(); 0129 $storeParams = array( 0130 'dojoType' => $params['type'], 0131 'jsId' => $params['store'], 0132 ); 0133 0134 if (array_key_exists('params', $params)) { 0135 $storeParams = array_merge($storeParams, $params['params']); 0136 $extraParams = $params['params']; 0137 } 0138 0139 if ($this->_useProgrammatic()) { 0140 if (!$this->_useProgrammaticNoScript()) { 0141 // require_once 'Zend/Json.php'; 0142 $this->dojo->addJavascript('var ' . $storeParams['jsId'] . ";\n"); 0143 $js = $storeParams['jsId'] . ' = ' 0144 . 'new ' . $storeParams['dojoType'] . '(' 0145 . Zend_Json::encode($extraParams) 0146 . ");\n"; 0147 $js = "function() {\n$js\n}"; 0148 $this->dojo->_addZendLoad($js); 0149 } 0150 return true; 0151 } 0152 0153 return '<div' . $this->_htmlAttribs($storeParams) . '></div>'; 0154 } 0155 }