1 <?php
2 3 4 5 6 7 8 9
10
11 class UWdropDownDep {
12
13 public $params = array(
14 'modelName'=>'',
15 'optionName'=>'',
16 'emptyField'=>'',
17 'relationName'=>'',
18 'modelDestName'=>'',
19 'destField'=>'',
20 'optionDestName'=>'',
21 );
22
23 24 25 26
27 public function init() {
28 return array(
29 'name'=>__CLASS__,
30 'label'=>UserModule::t('DropDown List Dependent',array(),__CLASS__),
31 'fieldType'=>array('INTEGER'),
32 'params'=>$this->params,
33 'paramsLabels' => array(
34 'modelName'=>UserModule::t('Model Name',array(),__CLASS__),
35 'optionName'=>UserModule::t('Lable field name',array(),__CLASS__),
36 'emptyField'=>UserModule::t('Empty item name',array(),__CLASS__),
37 'relationName'=>UserModule::t('Profile model relation name',array(),__CLASS__),
38 'modelDestName'=>UserModule::t('Model Dest Name',array(),__CLASS__),
39 'destField'=>UserModule::t('Dest Field',array(),__CLASS__),
40 'optionDestName'=>UserModule::t('Label Dest field name',array(),__CLASS__),
41 ),
42 );
43 }
44
45 46 47 48 49 50
51 public function setAttributes($value,$model,$field_varname) {
52 return $value;
53 }
54
55 56 57 58 59
60 public function viewAttribute($model,$field) {
61 $relation = $model->relations();
62 if ($this->params['relationName']&&isset($relation[$this->params['relationName']])) {
63 $m = $model->__get($this->params['relationName']);
64 } else {
65 $m = CActiveRecord::model($this->params['modelName'])->findByPk($model->getAttribute($field->varname));
66 }
67
68 if ($m)
69 return (($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m->id);
70 else
71 return $this->params['emptyField'];
72
73 }
74
75 76 77 78 79 80
81 public function editAttribute($model,$field,$htmlOptions=array()) {
82 $list = array();
83 if ($this->params['emptyField']) $list[0] = $this->params['emptyField'];
84
85 $models = CActiveRecord::model($this->params['modelName'])->findAll();
86 foreach ($models as $m)
87 $list[$m->id] = (($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m->id);
88 return CHtml::activeDropDownList($model,$field->varname,$list,$htmlOptions=array(
89 'ajax'=>array(
90 'type'=>'POST',
91 'url'=>CController::createUrl('/user/profileField/getDroDownDepValues'),
92 'data'=>array('model'=>$this->params['modelDestName'], 'field_dest'=>$this->params['destField'], 'varname'=>$field->varname, $field->varname=>'js:this.value', 'optionDestName'=>$this->params['optionDestName']),
93 'success'=>'function(data){
94 $("#ajax_loader").hide();
95 $("#Profile_'.$this->params['destField'].'").html(data)
96 }',
97 'beforeSend'=>'function(){
98 $("#ajax_loader").fadeIn();
99 }',
100 )
101 ));
102 }
103
104 }
105