1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: class X2ActiveForm extends CActiveForm {
38:
39: /**
40: * @var string $id
41: */
42: public $id = 'x2-form';
43:
44: /**
45: * @var bool $instantiateJSClassOnInit
46: */
47: public $instantiateJSClassOnInit = true;
48:
49: /**
50: * @var string $JSClass
51: */
52: public $JSClass = 'X2Form';
53:
54: /**
55: * @var CFormModel $formModel
56: */
57: public $formModel;
58:
59: public function __construct ($owner=null) {
60: $this->attachBehaviors ($this->behaviors ());
61: parent::__construct ($owner);
62: }
63:
64: public function behaviors () {
65: return array (
66: 'X2WidgetBehavior' => array (
67: 'class' => 'application.components.behaviors.X2WidgetBehavior'
68: ),
69: );
70: }
71:
72: public function getJSClassParams () {
73: return array_merge (
74: $this->asa ('X2WidgetBehavior')->getJSClassParams (),
75: array (
76: 'formSelector' => '#'.$this->id,
77: 'submitUrl' => $this->action ? $this->action : '',
78: 'formModelName' => get_class ($this->formModel),
79: )
80: );
81: }
82:
83: public function getPackages () {
84: if (!isset ($this->_packages)) {
85: $this->_packages = array_merge ($this->asa ('X2WidgetBehavior')->getPackages (), array(
86: 'X2FormJS' => array(
87: 'baseUrl' => Yii::app()->baseUrl,
88: 'js' => array(
89: 'js/X2Form.js',
90: ),
91: 'depends' => array ('auxlib'),
92: ),
93: ));
94: }
95: return $this->_packages;
96: }
97:
98: public function multiTypeAutocomplete (
99: $model, $typeAttribute, $idAttribute, $options, array $config = array ()) {
100: return X2Html::activeMultiTypeAutocomplete (
101: $model, $typeAttribute, $idAttribute, $options, $config);
102:
103: }
104:
105: /**
106: * This method is Copyright (c) 2008-2014 by Yii Software LLC
107: * http://www.yiiframework.com/license/
108: */
109: public function dropDownList($model,$attribute,$data,$htmlOptions=array()) {
110: return X2Html::activeDropDownList($model,$attribute,$data,$htmlOptions);
111: }
112:
113: public function richTextArea (CModel $model, $attribute, array $htmlOptions=array ()) {
114: return X2Html::activeRichTextArea ($model, $attribute, $htmlOptions);
115: }
116:
117: public function codeEditor (CModel $model, $attribute, array $htmlOptions = array ()) {
118: return X2Html::activeCodeEditor ($model, $attribute, $htmlOptions);
119: }
120:
121: public function resolveHtmlOptions (CModel $model, $attribute, array $htmlOptions = array ()) {
122: CHtml::resolveNameID ($model, $attribute, $htmlOptions);
123: $htmlOptions['id'] = $this->resolveId ($htmlOptions['id']);
124: return $htmlOptions;
125: }
126:
127: public function init () {
128: $this->id = $this->resolveId ($this->id);
129:
130: if ($this->instantiateJSClassOnInit) {
131: $this->registerPackages ();
132: $this->instantiateJSClass (false);
133: }
134:
135: parent::init ();
136: echo CHtml::hiddenField (X2WidgetBehavior::NAMESPACE_KEY, $this->namespace);
137: }
138:
139: }
140: