*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Dojo / View / Helper / Editor.php
blob8c3ce77799fd935e067dfcd1135ba7f35b0b2898
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Dojo
17 * @subpackage View
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Editor.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 /** Zend_Dojo_View_Helper_Textarea */
24 require_once 'Zend/Dojo/View/Helper/Textarea.php';
26 /** Zend_Json */
27 require_once 'Zend/Json.php';
29 /**
30 * Dojo Editor dijit
32 * @uses Zend_Dojo_View_Helper_Textarea
33 * @package Zend_Dojo
34 * @subpackage View
35 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Dojo_View_Helper_Editor extends Zend_Dojo_View_Helper_Textarea
40 /**
41 * @param string Dijit type
43 protected $_dijit = 'dijit.Editor';
45 /**
46 * @var string Dijit module to load
48 protected $_module = 'dijit.Editor';
50 /**
51 * JSON-encoded parameters
52 * @var array
54 protected $_jsonParams = array('captureEvents', 'events', 'plugins');
56 /**
57 * dijit.Editor
59 * @param string $id
60 * @param string $value
61 * @param array $params
62 * @param array $attribs
63 * @return string
65 public function editor($id, $value = null, $params = array(), $attribs = array())
67 $hiddenName = $id;
68 if (array_key_exists('id', $attribs)) {
69 $hiddenId = $attribs['id'];
70 } else {
71 $hiddenId = $hiddenName;
73 $hiddenId = $this->_normalizeId($hiddenId);
75 $textareaName = $this->_normalizeEditorName($hiddenName);
76 $textareaId = $hiddenId . '-Editor';
78 $hiddenAttribs = array(
79 'id' => $hiddenId,
80 'name' => $hiddenName,
81 'value' => $value,
82 'type' => 'hidden',
84 $attribs['id'] = $textareaId;
86 $this->_createGetParentFormFunction();
87 $this->_createEditorOnSubmit($hiddenId, $textareaId);
89 $html = '<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket()
90 . $this->textarea($textareaName, $value, $params, $attribs);
92 return $html;
95 /**
96 * Normalize editor element name
98 * @param string $name
99 * @return string
101 protected function _normalizeEditorName($name)
103 if ('[]' == substr($name, -2)) {
104 $name = substr($name, 0, strlen($name) - 2);
105 $name .= '[Editor][]';
106 } else {
107 $name .= '[Editor]';
109 return $name;
113 * Create onSubmit binding for element
115 * @param string $hiddenId
116 * @param string $editorId
117 * @return void
119 protected function _createEditorOnSubmit($hiddenId, $editorId)
121 $this->dojo->onLoadCaptureStart();
122 echo <<<EOJ
123 function() {
124 var form = zend.findParentForm(dojo.byId('$hiddenId'));
125 dojo.connect(form, 'onsubmit', function () {
126 dojo.byId('$hiddenId').value = dijit.byId('$editorId').getValue(false);
129 EOJ;
130 $this->dojo->onLoadCaptureEnd();