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.
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: ComboBox.php 11014 2008-08-24 21:15:31Z matthew $
23
/** Zend_Dojo_View_Helper_Dijit */
24
require_once 'Zend/Dojo/View/Helper/Dijit.php';
29
* @uses Zend_Dojo_View_Helper_Dijit
32
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
33
* @license http://framework.zend.com/license/new-bsd New BSD License
35
class Zend_Dojo_View_Helper_ComboBox extends Zend_Dojo_View_Helper_Dijit
41
protected $_dijit = 'dijit.form.ComboBox';
47
protected $_elementType = 'text';
53
protected $_module = 'dijit.form.ComboBox';
60
* @param array $params Parameters to use for dijit creation
61
* @param array $attribs HTML attributes
62
* @param array|null $options Select options
65
public function comboBox($id, $value = null, array $params = array(), array $attribs = array(), array $options = null)
68
if (!array_key_exists('id', $attribs)) {
71
if (array_key_exists('store', $params) && is_array($params['store'])) {
72
// using dojo.data datastore
73
if (false !== ($store = $this->_renderStore($params['store']))) {
74
$params['store'] = $params['store']['store'];
75
if (is_string($store)) {
78
$html .= $this->_createFormElement($id, $value, $params, $attribs);
81
unset($params['store']);
82
} elseif (array_key_exists('store', $params)) {
83
if (array_key_exists('storeType', $params)) {
85
'store' => $params['store'],
86
'type' => $params['storeType'],
88
unset($params['storeType']);
89
if (array_key_exists('storeParams', $params)) {
90
$storeParams['params'] = $params['storeParams'];
91
unset($params['storeParams']);
93
if (false !== ($store = $this->_renderStore($storeParams))) {
94
if (is_string($store)) {
99
$html .= $this->_createFormElement($id, $value, $params, $attribs);
103
// do as normal select
104
$attribs = $this->_prepareDijit($attribs, $params, 'element');
105
return $this->view->formSelect($id, $value, $attribs, $options);
109
* Render data store element
111
* Renders to dojo view helper
113
* @param array $params
114
* @return string|false
116
protected function _renderStore(array $params)
118
if (!array_key_exists('store', $params) || !array_key_exists('type', $params)) {
122
$this->dojo->requireModule($params['type']);
124
$extraParams = array();
125
$storeParams = array(
126
'dojoType' => $params['type'],
127
'jsId' => $params['store'],
130
if (array_key_exists('params', $params)) {
131
$storeParams = array_merge($storeParams, $params['params']);
132
$extraParams = $params['params'];
135
if ($this->_useProgrammatic()) {
136
if (!$this->_useProgrammaticNoScript()) {
137
$this->dojo->addJavascript('var ' . $storeParams['jsId'] . ';');
138
require_once 'Zend/Json.php';
139
$js = "function() {\n"
140
. ' ' . $storeParams['jsId'] . ' = '
141
. 'new ' . $storeParams['dojoType'] . '('
142
. Zend_Json::encode($extraParams)
144
$this->dojo->addOnLoad($js);
149
return '<div' . $this->_htmlAttribs($storeParams) . '></div>';