1: <?php
2:
3: namespace Mesour\DataGrid\Column;
4:
5: use Mesour\DataGrid\Components\Button;
6: use Mesour\DataGrid\Components\Link;
7: use \Nette\Utils\Html;
8:
9: 10: 11: 12:
13: class SubItemButton extends Base {
14:
15: const NAME = 'name',
16: OPENED = 'opened',
17: TWO_ROWS = 'two-rows',
18: KEY = 'key';
19:
20: public function setName($name) {
21: $this->option[self::NAME] = $name;
22: return $this;
23: }
24:
25: public function setKey($key) {
26: $this->option[self::KEY] = $key;
27: return $this;
28: }
29:
30: public function setOpened($opened = TRUE) {
31: $this->option[self::OPENED] = $opened;
32: return $this;
33: }
34:
35: public function setTwoRows($two_rows = TRUE) {
36: $this->option[self::TWO_ROWS] = $two_rows;
37: return $this;
38: }
39:
40: protected function setDefaults() {
41: return array(
42: self::OPENED => FALSE,
43: self::KEY => -1,
44: self::TWO_ROWS => FALSE,
45: self::NAME => NULL,
46: );
47: }
48:
49: public function () {
50: return array();
51: }
52:
53: public function () {
54: return NULL;
55: }
56:
57: public function getBodyAttributes($data) {
58: $attributes = array('colspan' => $data, 'class' => 'subgrid-button');
59: if($this->option[self::TWO_ROWS]) {
60: $attributes['rowspan'] = 2;
61: }
62: return parent::mergeAttributes($data, $attributes);
63: }
64:
65: public function getBodyContent($data) {
66: $button = new Button();
67: $button->setPresenter($this->grid->presenter)
68: ->setType('btn-info btn-xs')
69: ->setClassName('mesour-ajax')
70: ->addAttribute('href', $this->grid['subitem']->link('toggleItem!', array($this->option[self::KEY], $this->option[self::NAME])));
71: if($this->option[self::OPENED]) {
72: $button->setIcon('glyphicon-minus')
73: ->setTitle('Disable sub item');
74: } else {
75: $button->setIcon('glyphicon-plus')
76: ->setTitle('Enable sub item');
77: }
78: return $button;
79: }
80:
81: }