9 'emptyFieldLabel' =>
'Not found',
10 'emptyFieldValue' => 0,
24 'label' =>
UserModule::t(
'jQueryUI autocomplete', array(), __CLASS__),
25 'fieldType' => array(
'INTEGER'),
26 'params' => $this->params,
27 'paramsLabels' => array(
28 'modelName' =>
UserModule::t(
'Model Name', array(), __CLASS__),
29 'optionName' =>
UserModule::t(
'Lable field name', array(), __CLASS__),
30 'emptyFieldLabel' =>
UserModule::t(
'Empty item name', array(), __CLASS__),
31 'emptyFieldValue' =>
UserModule::t(
'Empty item value', array(), __CLASS__),
32 'relationName' =>
UserModule::t(
'Profile model relation name', array(), __CLASS__),
33 'minLength' =>
UserModule::t(
'minimal start research length', array(), __CLASS__),
58 $relation = $model->relations();
59 if ($this->params[
'relationName'] && isset($relation[$this->params[
'relationName']])) {
60 $m = $model->__get($this->params[
'relationName']);
62 $m = CActiveRecord::model($this->params[
'modelName'])->findByPk($model->getAttribute($field->varname));
66 return (($this->params[
'optionName']) ? $m->getAttribute($this->params[
'optionName']) : $m->id);
68 return $this->params[
'emptyFieldLabel'];
82 if (isset($this->params[
'emptyFieldValue'])) {
83 $list[] = array(
'id' => $this->params[
'emptyFieldValue'],
'label' => $this->params[
'emptyFieldLabel']);
85 $models = CActiveRecord::model($this->params[
'modelName'])->findAll();
86 foreach ($models as $m) {
87 $list[] = (($this->params[
'optionName']) ? array(
'label' => $m->getAttribute($this->params[
'optionName']),
'id' => $m->id) : array(
'label' => $m->id,
'id' => $m->id));
90 if (!isset($htmlOptions[
'id'])) {
91 $htmlOptions[
'id'] = $field->varname;
93 $id = $htmlOptions[
'id'];
95 $relation = $model->relations();
96 if ($this->params[
'relationName'] && isset($relation[$this->params[
'relationName']])) {
97 $m = $model->__get($this->params[
'relationName']);
99 $m = CActiveRecord::model($this->params[
'modelName'])->findByPk($model->getAttribute($field->varname));
103 $default_value = (($this->params[
'optionName']) ? $m->getAttribute($this->params[
'optionName']) : $m->id);
108 $htmlOptions[
'value'] = $default_value;
109 $options[
'source'] = $list;
110 $options[
'minLength'] = $this->params[
'minLength'];
111 $options[
'showAnim'] =
'fold';
112 $options[
'select'] =
"js:function(event, ui) { $('#".get_class($model).
"_".$field->varname.
"').val(ui.item.id);}";
113 $options = CJavaScript::encode($options);
115 $basePath = Yii::getPathOfAlias(
'application.modules.user.views.asset');
116 $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
117 $cs = Yii::app()->getClientScript();
118 $cs->registerCssFile(
$baseUrl.
'/css/'.$this->params[
'ui-theme'].
'/jquery-ui.css');
119 $cs->registerScriptFile(
$baseUrl.
'/js/jquery-ui.min.js');
120 $js =
"jQuery('#{$id}').autocomplete({$options});";
121 $cs->registerScript(
'Autocomplete'.
'#'.$id, $js);
123 return CHtml::activeTextField($model, $field->varname, $htmlOptions).CHtml::activehiddenField($model, $field->varname);