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 MobileFieldInputRenderer extends FieldInputRenderer {
38:
39: public function renderLink ($field, array $htmlOptions = array ()) {
40: $fieldName = $field->fieldName;
41: $linkId = '';
42: $name = '';
43: $linkSource = null;
44:
45: // TODO: move this code and duplicate code in X2Model::renderModelInput into a helper
46: // method. Might be able to use X2Model::getLinkedModel.
47: if (class_exists($field->linkType)) {
48: if (!empty($this->owner->$fieldName)) {
49: list($name, $linkId) = Fields::nameAndId($this->owner->$fieldName);
50: $linkModel = X2Model::getLinkedModelMock($field->linkType, $name, $linkId, true);
51: } else {
52: $linkModel = X2Model::model($field->linkType);
53: }
54: if ($linkModel instanceof X2Model &&
55: $linkModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) {
56:
57: $linkSource = Yii::app()->controller->createAbsoluteUrl (
58: $linkModel->autoCompleteSource);
59: $linkId = $linkModel->id;
60: $oldLinkFieldVal = $this->owner->$fieldName;
61: $this->owner->$fieldName = $name;
62: }
63: }
64:
65: $input = CHtml::hiddenField(
66: $field->modelName . '[' . $fieldName . '_id]', $linkId,
67: array());
68:
69: $input .= CHtml::activeTextField($this->owner, $field->fieldName, array_merge(array(
70: 'title' => $field->attributeLabel,
71: 'data-x2-link-source' => $linkSource,
72: 'class' => 'x2-mobile-autocomplete',
73: 'autocomplete' => 'off',
74: ), $htmlOptions));
75: return $input;
76: }
77:
78: public function renderDate ($field, array $htmlOptions = array ()) {
79: $model = $this->owner;
80: $fieldName = $field->fieldName;
81:
82: $oldDateVal = $model->$fieldName;
83: $model->$fieldName = Formatter::formatDate($model->$fieldName, 'medium');
84: Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
85: $pickerOptions = array(// jquery options
86: 'dateFormat' => Formatter::formatDatePicker(),
87: 'changeMonth' => false,
88: 'changeYear' => false,
89: );
90: if (Yii::app()->getLanguage() === 'fr')
91: $pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
92: $input = Yii::app()->controller->widget('CJuiDateTimePicker', array(
93: 'model' => $model, //Model object
94: 'attribute' => $fieldName, //attribute name
95: 'mode' => 'date', //use "time","date" or "datetime" (default)
96: 'options' => $pickerOptions,
97: 'htmlOptions' => array_merge(array(
98: 'title' => $field->attributeLabel,
99: 'class' => 'x2-mobile-datepicker',
100: ), $htmlOptions),
101: 'language' => (Yii::app()->language == 'en') ? '' : Yii::app()->getLanguage(),
102: ), true);
103: $model->$fieldName = $oldDateVal;
104: return $input;
105: }
106:
107: /**
108: * TODO: add full support for datetime fields
109: */
110: public function renderDateTime ($field, array $htmlOptions = array ()) {
111: return $this->renderDate ($field, $htmlOptions);
112:
113: // $model = $this->owner;
114: // $fieldName = $field->fieldName;
115: //
116: // $oldDateTimeVal = $model->$fieldName;
117: // $pickerOptions = array(// jquery options
118: // 'dateFormat' => Formatter::formatDatePicker('medium'),
119: // 'timeFormat' => Formatter::formatTimePicker(),
120: // 'ampm' => Formatter::formatAMPM(),
121: // 'changeMonth' => false,
122: // 'changeYear' => false,
123: // );
124: // if (Yii::app()->getLanguage() === 'fr')
125: // $pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
126: // $model->$fieldName = Formatter::formatDateTime($model->$fieldName);
127: // Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
128: // $input = Yii::app()->controller->widget('CJuiDateTimePicker', array(
129: // 'model' => $model, //Model object
130: // 'attribute' => $fieldName, //attribute name
131: // 'mode' => 'datetime', //use "time","date" or "datetime" (default)
132: // 'options' => $pickerOptions,
133: // 'htmlOptions' => array_merge(array(
134: // 'title' => $field->attributeLabel,
135: // ), $htmlOptions),
136: // 'language' => (Yii::app()->language == 'en') ? '' : Yii::app()->getLanguage(),
137: // ), true);
138: // $model->$fieldName = $oldDateTimeVal;
139: // return $input;
140: }
141:
142: public function renderDropdown ($field, array $htmlOptions = array ()) {
143: $om = $field->getDropdownOptions ();
144: $multi = (bool) $om['multi'];
145: // enables custom multi-select menu for non-phonegap x2touch. Not needed for phonegap since
146: // it uses a native multiselct
147: if ($multi && !Yii::app()->params->isPhoneGap)
148: $htmlOptions['data-native-menu'] = 'false';
149: return X2Model::renderModelInput ($this->owner, $field, $htmlOptions);
150: }
151:
152: public function renderAssignment ($field, array $htmlOptions = array ()) {
153: // enables custom multi-select menu for non-phonegap x2touch. Not needed for phonegap since
154: // it uses a native multiselct
155: if ($field->linkType === 'multiple' && !Yii::app()->params->isPhoneGap)
156: $htmlOptions['data-native-menu'] = 'false';
157: return X2Model::renderModelInput ($this->owner, $field, $htmlOptions);
158: }
159:
160: public function renderBoolean ($field, array $htmlOptions = array ()) {
161: $fieldName = $field->fieldName;
162: $inputName=CHtml::resolveName($this->owner, $fieldName);
163: $for=CHtml::getIdByName($inputName);
164: return
165: CHtml::label ('', $for).
166: CHtml::activeCheckBox($this->owner, $field->fieldName, array_merge(array(
167: 'unchecked' => 0,
168: 'title' => $field->attributeLabel,
169: ), $htmlOptions));
170: }
171: }
172:
173: ?>
174: