1 <?php
2 3 4 5 6 7 8 9
10
11 Yii::import('zii.widgets.grid.CButtonColumn');
12
13 14 15 16
17 class TbButtonColumn extends CButtonColumn
18 {
19 20 21
22 public $viewButtonIcon = 'eye-open';
23 24 25
26 public $updateButtonIcon = 'pencil';
27 28 29
30 public $deleteButtonIcon = 'trash';
31
32 33 34
35 protected function initDefaultButtons()
36 {
37 parent::initDefaultButtons();
38
39 if ($this->viewButtonIcon !== false && !isset($this->buttons['view']['icon']))
40 $this->buttons['view']['icon'] = $this->viewButtonIcon;
41 if ($this->updateButtonIcon !== false && !isset($this->buttons['update']['icon']))
42 $this->buttons['update']['icon'] = $this->updateButtonIcon;
43 if ($this->deleteButtonIcon !== false && !isset($this->buttons['delete']['icon']))
44 $this->buttons['delete']['icon'] = $this->deleteButtonIcon;
45 }
46
47 48 49 50 51 52 53
54 protected function renderButton($id, $button, $row, $data)
55 {
56 if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row'=>$row, 'data'=>$data)))
57 return;
58
59 $label = isset($button['label']) ? $button['label'] : $id;
60 $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data'=>$data, 'row'=>$row)) : '#';
61 $options = isset($button['options']) ? $button['options'] : array();
62
63 if (!isset($options['title']))
64 $options['title'] = $label;
65
66 if (!isset($options['rel']))
67 $options['rel'] = 'tooltip';
68
69 if (isset($button['icon']))
70 {
71 if (strpos($button['icon'], 'icon') === false)
72 $button['icon'] = 'icon-'.implode(' icon-', explode(' ', $button['icon']));
73
74 echo CHtml::link('<i class="'.$button['icon'].'"></i>', $url, $options);
75 }
76 else if (isset($button['imageUrl']) && is_string($button['imageUrl']))
77 echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
78 else
79 echo CHtml::link($label, $url, $options);
80 }
81 }
82