public function beforeExecute() { if ($this->getFormModel() && !$this->getFormModel()->validate()) { $that = $this; self::$responseForm = X2Widget::ajaxRender(function () use($that) { $that->renderForm(false); }, true); return false; } return true; }
/** * @param string $modelClass the model class for which the autocomplete should be rendered * @param bool $ajax if true, registered scripts are processed with ajaxRender */ public static function renderModelAutocomplete($modelClass, $ajax = false, $htmlOptions = array(), $value = null) { $modelClass = self::getModelName($modelClass); if (!class_exists($modelClass) || !$modelClass::model()->asa('X2LinkableBehavior')) { if ($ajax) { echo 'failure'; return; } else { return 'failure'; } /* throw new CException ( Yii::t('app', 'Error: renderModelAutocomplete: {modelClass} does not have '. 'X2LinkableBehavior', array ('{modelClass}' => $modelClass))); */ } if ($ajax) { Yii::app()->clientScript->scriptMap['*.css'] = false; } $renderWidget = function () use($modelClass, $htmlOptions, $value) { Yii::app()->controller->widget('zii.widgets.jui.CJuiAutoComplete', array('name' => isset($htmlOptions['name']) ? $htmlOptions['name'] : 'recordName', 'source' => Yii::app()->controller->createUrl(X2Model::model($modelClass)->autoCompleteSource), 'value' => $value ? $value : Yii::t('app', 'Start typing to suggest...'), 'options' => array('minLength' => '1', 'create' => 'js:function (event, ui) { // check for callback in parent form if ($(this).closest ("form").data ("afterAutocompleteCreated")) { $(this).closest ("form").data ("afterAutocompleteCreated") (); } }', 'select' => 'js:function (event, ui) { $(this).val(ui.item.value); // expects next input to be a hidden input which will contain the // record id $(this).nextAll ("input").val(ui.item.id); return false; }'), 'htmlOptions' => array_merge(array('class' => 'record-name-autocomplete x2-default-field', 'data-default-text' => Yii::t('app', 'Start typing to suggest...'), 'style' => $value ? '' : 'color:#aaa'), $htmlOptions))); Yii::app()->clientScript->registerScript('renderModelAutocomplete', "\n x2.forms.enableDefaultText (\$('.record-name-autocomplete'));\n ", CClientScript::POS_READY); }; if ($ajax) { X2Widget::ajaxRender($renderWidget); } else { $renderWidget(); } }
public function renderFilterCellContent() { switch ($this->fieldType) { case 'boolean': echo CHtml::activeDropdownList($this->grid->filter, $this->name, array('' => '- ' . Yii::t('app', 'Select') . ' -', '1' => Yii::t('app', 'Yes'), 'false' => Yii::t('app', "No")), array('class' => 'x2-minimal-select-filtercol')); break; case 'dropdown': $dropdown = Dropdowns::model()->findByPk($this->fieldModel['linkType']); if ($dropdown instanceof Dropdowns) { $options = json_decode($dropdown->options, 1); if (!$dropdown->multi) { $defaultOption = array('' => '- ' . Yii::t('app', 'Select') . ' -'); $options = is_array($options) ? array_merge($defaultOption, $options) : $defaultOption; } //$selected = isset($options[$this->grid->filter->{$this->name}]) ? //$this->grid->filter->{$this->name} : ''; echo CHtml::activeDropdownList($this->grid->filter, $this->name, $options, array('class' => 'x2-minimal-select-filtercol' . ($dropdown->multi ? ' x2-multiselect-dropdown x2-datacolumn-multiselect' : ''), 'multiple' => $dropdown->multi ? 'multiple' : '', 'data-selected-text' => $dropdown->multi ? 'option(s)' : '')); } else { parent::renderFilterCellContent(); } break; case 'visibility': echo CHtml::activeDropDownList($this->grid->filter, $this->name, array('' => '- ' . Yii::t('app', 'Select') . ' -', 1 => Yii::t('app', 'Public'), 0 => Yii::t('app', 'Private'), 2 => Yii::t('app', 'User\'s Groups')), array('class' => 'x2-minimal-select-filtercol')); break; case 'dateTime': case 'date': Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker'); $that = $this; $renderWidget = function () use($that) { echo Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $that->grid->filter, 'attribute' => $that->name, 'mode' => 'date', 'options' => array('dateFormat' => Formatter::formatDatePicker('medium')), 'htmlOptions' => array('id' => 'datePicker' . $that->name, 'class' => 'datePicker x2-gridview-filter-datepicker'), 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage()), true); }; if ($this->grid->ajax) { X2Widget::ajaxRender($renderWidget); } else { $renderWidget(); } break; default: parent::renderFilterCellContent(); } }
public function actionQuickView($id) { $model = $this->loadModel($id); if (!FormLayout::model()->findByAttributes(array('model' => get_class($model)))) { echo Yii::t('app', 'Quick view not supported'); } if ($this->checkPermissions($model, 'view')) { $that = $this; X2Widget::ajaxRender(function () use($model, $that) { $that->widget('DetailView', array_merge(array('model' => $model, 'scenario' => 'Inline', 'nameLink' => true))); }); return; } throw new CHttpException(403); }
/** * @param CModel $model * @param string $attribute * @param array (optional) $htmlOptions * @return string */ public static function activeDatePicker(CModel $model, $attribute, array $htmlOptions = array(), $mode = 'date', array $options = array()) { $options = array_merge(array('dateFormat' => Formatter::formatDatePicker(), 'changeMonth' => true, 'changeYear' => true), $options); ob_start(); ob_implicit_flush(false); Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker'); $model->{$attribute} = Formatter::formatDateTime($model->{$attribute}); $renderWidget = function () use($model, $attribute, $htmlOptions, $mode, $options) { Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => $attribute, 'mode' => $mode, 'options' => $options, 'htmlOptions' => $htmlOptions, 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage())); }; if (Yii::app()->controller->isAjaxRequest()) { // process output if this is an ajax request X2Widget::ajaxRender($renderWidget); } else { $renderWidget(); } return ob_get_clean(); }
/** * Renders an inline record create/update form * @param object $model * @param bool $hasErrors */ public function renderInlineForm($model, array $viewParams = array()) { //@FORMVIEW $that = $this; echo CJSON::encode(array('status' => $model->hasErrors() ? 'userError' : 'success', 'page' => X2Widget::ajaxRender(function () use($model, $that, $viewParams) { echo $that->owner->widget('FormView', array_merge(array('model' => $model, 'suppressQuickCreate' => true, 'formSettings' => array()), $viewParams), true, true); }, true))); }
public function actionQuickView($id) { $model = $this->loadModel($id); if (!FormLayout::model()->findByAttributes(array('model' => get_class($model)))) { echo Yii::t('app', 'Quick view not supported'); } if ($this->checkPermissions($model, 'view')) { $that = $this; X2Widget::ajaxRender(function () use($model, $that) { $that->widget('DetailView', array_merge(array('model' => $model, 'scenario' => 'Inline', 'nameLink' => true))); // $this->renderPartial( // 'application.components.views.@DETAILVIEW', // array_merge( array( // 'model' => $model, // 'modelName' => get_class ($model), // 'scenario'=>'Inline', // 'nameLink' => true, // ), $options) // , false, true); }); return; } throw new CHttpException(403); }