1 | <?php |
||
19 | class TbButtonGroupColumn extends TbButtonColumn { |
||
20 | |||
21 | /** |
||
22 | * @var string the button size ('xs','sm','md','lg') |
||
23 | */ |
||
24 | public $buttonSize = 'xs'; |
||
25 | |||
26 | /** |
||
27 | * @var string the view button context ('info','primary','warning','danger','success' defaults to 'info'). |
||
28 | */ |
||
29 | public $viewButtonContext = 'info'; |
||
30 | |||
31 | /** |
||
32 | * @var string the update button context ('info','primary','warning','danger','success' defaults to 'warning'). |
||
33 | */ |
||
34 | public $updateButtonContext = 'warning'; |
||
35 | |||
36 | /** |
||
37 | * @var string the delete button context ('info','primary','warning','danger','success' defaults to 'danger') |
||
38 | */ |
||
39 | public $deleteButtonContext = 'danger'; |
||
40 | |||
41 | /** |
||
42 | *### .initDefaultButtons() |
||
43 | * |
||
44 | * Initializes the default buttons (view, update and delete). |
||
45 | */ |
||
46 | protected function initDefaultButtons() { |
||
47 | |||
48 | parent::initDefaultButtons(); |
||
49 | |||
50 | if ($this->viewButtonContext !== false && !isset($this->buttons['view']['context'])) { |
||
51 | $this->buttons['view']['context'] = $this->viewButtonContext; |
||
52 | } |
||
53 | if ($this->updateButtonContext !== false && !isset($this->buttons['update']['context'])) { |
||
54 | $this->buttons['update']['context'] = $this->updateButtonContext; |
||
55 | } |
||
56 | if ($this->deleteButtonContext !== false && !isset($this->buttons['delete']['context'])) { |
||
57 | $this->buttons['delete']['context'] = $this->deleteButtonContext; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | |||
62 | /** |
||
63 | *### .renderButton() |
||
64 | * |
||
65 | * Renders a link button. |
||
66 | * |
||
67 | * @param string $id the ID of the button |
||
68 | * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements. |
||
69 | * @param integer $row the row number (zero-based) |
||
70 | * @param mixed $data the data object associated with the row |
||
71 | */ |
||
72 | protected function renderButton($id, $button, $row, $data) { |
||
73 | |||
74 | if (isset($button['visible']) && !$this->evaluateExpression( |
||
75 | $button['visible'], |
||
76 | array('row' => $row, 'data' => $data) |
||
77 | ) |
||
78 | ) { |
||
79 | return; |
||
80 | } |
||
81 | |||
82 | $label = isset($button['label']) ? $button['label'] : $id; |
||
83 | $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row)) |
||
84 | : '#'; |
||
85 | $options = isset($button['options']) ? $button['options'] : array(); |
||
86 | |||
87 | if (!isset($options['title'])) { |
||
88 | $options['title'] = $label; |
||
89 | } |
||
90 | |||
91 | if (!isset($options['buttonType'])) { |
||
92 | $options['buttonType'] = 'link'; |
||
93 | } |
||
94 | |||
95 | if (!isset($options['data-toggle'])) { |
||
96 | $options['data-toggle'] = 'tooltip'; |
||
97 | } |
||
98 | |||
99 | if (!isset($options['class'])) { |
||
100 | $options['class'] = ''; |
||
101 | } |
||
102 | $options['class'] .= ' btn btn-' . $this->buttonSize; |
||
103 | if (isset($button['context'])) { |
||
104 | $options['class'] .= ' btn-' . $button['context']; |
||
105 | } |
||
106 | |||
107 | if (isset($button['icon'])) { |
||
108 | if (strpos($button['icon'], 'icon') === false && strpos($button['icon'], 'fa') === false) { |
||
109 | $button['icon'] = 'icon-' . implode(' icon-', explode(' ', $button['icon'])); |
||
110 | } |
||
111 | |||
112 | echo CHtml::link('<span class="' . $button['icon'] . '"></span>', $url, $options); |
||
113 | } else if (isset($button['imageUrl']) && is_string($button['imageUrl'])) { |
||
114 | echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options); |
||
115 | } else { |
||
116 | echo CHtml::link($label, $url, $options); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | *### .renderDataCellContent() |
||
122 | * |
||
123 | * Renders the data cell content. |
||
124 | * This method renders the view, update and delete buttons in the data cell. |
||
125 | * |
||
126 | * @param integer $row the row number (zero-based) |
||
127 | * @param mixed $data the data associated with the row |
||
128 | */ |
||
129 | protected function renderDataCellContent($row, $data) |
||
141 | } |
||
142 |