1 <?php
2 3 4 5 6 7 8 9 10 11 12
13
14 Yii::import('ext.editable.EditableField');
15 Yii::import('zii.widgets.CDetailView');
16
17 class EditableDetailView extends CDetailView
18 {
19
20 public $url = '';
21
22
23 public $htmlOptions = array('class'=> 'table table-bordered table-striped table-hover table-condensed');
24
25 public function init()
26 {
27 if (!$this->data instanceof CModel) {
28 throw new CException('Property "data" should be of CModel class.');
29 }
30
31 parent::init();
32 }
33
34 protected function renderItem($options, $templateData)
35 {
36
37 $isEditable = array_key_exists('editable', $options) && $options['editable'] !== false;
38
39
40 $isEditable = !empty($options['name']) && $this->data->isAttributeSafe($options['name']);
41
42 if ($isEditable) {
43
44 if(!array_key_exists('editable', $options) || !is_array($options['editable'])) $options['editable'] = array();
45
46
47 if (!array_key_exists('url', $options['editable'])) {
48 $options['editable']['url'] = $this->url;
49 }
50
51 $editableOptions = CMap::mergeArray($options['editable'], array(
52 'model' => $this->data,
53 'attribute' => $options['name'],
54 'emptytext' => ($this->nullDisplay === null) ? Yii::t('zii', 'Not set') : strip_tags($this->nullDisplay),
55 ));
56
57
58 if(array_key_exists('value', $options) && $options['value'] !== null) {
59 $editableOptions['text'] = $templateData['{value}'];
60 $editableOptions['encode'] = false;
61 }
62
63 $templateData['{value}'] = $this->controller->widget('EditableField', $editableOptions, true);
64 }
65
66 parent::renderItem($options, $templateData);
67 }
68
69 }
70
71