• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / datagrid / 12932819551

23 Jan 2025 03:44PM UTC coverage: 34.009%. Remained the same
12932819551

push

github

f3l1x
Fixing custom classes on checkbox in inline edit

- `\Nette\Forms\Controls\Checkbox::getControl` returns label part and control part like one ``\Nette\Utils\Html` and then `$control->getControl()->getAttribute('class')` is always null and custom defined classes are always overwritten by `$control->setAttribute('class', 'form-control input-sm form-control-sm');`
- fixed by using `\Nette\Forms\Controls\BaseControl::getControlPrototype` which always returns only control part without label part

0 of 1 new or added line in 1 file covered. (0.0%)

1124 of 3305 relevant lines covered (34.01%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/InlineEdit/InlineEdit.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\InlineEdit;
4

5
use Contributte\Datagrid\Datagrid;
6
use Contributte\Datagrid\Row;
7
use Contributte\Datagrid\Traits\TButtonClass;
8
use Contributte\Datagrid\Traits\TButtonIcon;
9
use Contributte\Datagrid\Traits\TButtonText;
10
use Contributte\Datagrid\Traits\TButtonTitle;
11
use Contributte\Datagrid\Traits\TButtonTryAddIcon;
12
use Nette\Forms\Container;
13
use Nette\SmartObject;
14
use Nette\Utils\ArrayHash;
15
use Nette\Utils\Html;
16

17
/**
18
 * @method onSubmit($id, ArrayHash $values)
19
 * @method onControlAdd(Container $container)
20
 * @method onControlAfterAdd(Container $container)
21
 * @method onSetDefaults(Container $container, $item)
22
 * @method onCustomRedraw(string $buttonName)
23
 */
24
class InlineEdit
25
{
26

27
        use SmartObject;
28
        use TButtonTryAddIcon;
29
        use TButtonIcon;
30
        use TButtonClass;
31
        use TButtonTitle;
32
        use TButtonText;
33

34
        /** @var array|callable[] */
35
        public array $onSubmit = [];
36

37
        /** @var array|callable[] */
38
        public array $onControlAdd = [];
39

40
        /** @var array|callable[] */
41
        public array $onControlAfterAdd = [];
42

43
        /** @var array|callable[] */
44
        public array $onSetDefaults = [];
45

46
        /** @var array|callable[] */
47
        public array $onCustomRedraw = [];
48

49
        protected mixed $itemID = null;
50

51
        /**
52
         * Inline adding - render on the top or in the bottom?
53
         */
54
        protected bool $positionTop = false;
55

56
        /**
57
         * Columns that are not edited can displey normal value instaad of nothing..
58
         */
59
        protected bool $showNonEditingColumns = true;
60

61
        /** @var array<string, mixed> */
62
        protected array $dataAttributes = [];
63

64
        public function __construct(protected Datagrid $grid, protected ?string $primaryWhereColumn = null)
×
65
        {
66
                $this->title = 'contributte_datagrid.edit';
×
67
                $this->class = sprintf('btn btn-xs %s ajax', $grid::$btnSecondaryClass);
×
68
                $this->icon = 'pencil pencil-alt';
×
69

70
                $this->onControlAfterAdd[] = [$this, 'addControlsClasses'];
×
71
        }
72

73
        /**
74
         * @return static
75
         */
76
        public function setItemId(mixed $id): self
77
        {
78
                $this->itemID = $id;
×
79

80
                return $this;
×
81
        }
82

83
        public function getItemId(): mixed
84
        {
85
                return $this->itemID;
×
86
        }
87

88
        public function getPrimaryWhereColumn(): ?string
89
        {
90
                return $this->primaryWhereColumn;
×
91
        }
92

93
        public function renderButton(Row $row): Html
94
        {
95
                $a = Html::el('a')
×
96
                        ->href($this->grid->link('inlineEdit!', ['id' => $row->getId()]));
×
97

98
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
99

100
                if ($this->dataAttributes !== []) {
×
101
                        foreach ($this->dataAttributes as $key => $value) {
×
102
                                $a->data($key, $value);
×
103
                        }
104
                }
105

106
                $a->addText($this->text);
×
107

108
                if ($this->title !== null) {
×
109
                        $a->setAttribute(
×
110
                                'title',
×
111
                                $this->grid->getTranslator()->translate($this->title)
×
112
                        );
113
                }
114

115
                if ($this->class !== '') {
×
116
                        $a->appendAttribute('class', $this->class);
×
117
                }
118

119
                $a->appendAttribute('class', 'datagrid-inline-edit-trigger');
×
120

121
                return $a;
×
122
        }
123

124
        /**
125
         * Render row item detail button
126
         */
127
        public function renderButtonAdd(): Html
128
        {
129
                $a = Html::el('a')
×
130
                        ->href($this->grid->link('showInlineAdd!'));
×
131

132
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
133

134
                if ($this->dataAttributes !== []) {
×
135
                        foreach ($this->dataAttributes as $key => $value) {
×
136
                                $a->data($key, $value);
×
137
                        }
138
                }
139

140
                $a->addText($this->text);
×
141

142
                if ($this->title !== null) {
×
143
                        $a->setAttribute(
×
144
                                'title',
×
145
                                $this->grid->getTranslator()->translate($this->title)
×
146
                        );
147
                }
148

149
                if ($this->class !== '') {
×
150
                        $a->appendAttribute('class', $this->class);
×
151
                }
152

153
                return $a;
×
154
        }
155

156
        /**
157
         * @return static
158
         */
159
        public function setPositionTop(bool $positionTop = true): self
160
        {
161
                $this->positionTop = $positionTop;
×
162

163
                return $this;
×
164
        }
165

166
        public function isPositionTop(): bool
167
        {
168
                return $this->positionTop;
×
169
        }
170

171
        public function isPositionBottom(): bool
172
        {
173
                return !$this->positionTop;
×
174
        }
175

176
        public function addControlsClasses(Container $container): void
177
        {
178
                foreach ($container->getControls() as $key => $control) {
×
179
                        switch ($key) {
×
180
                                case 'submit':
×
181
                                        $control->setValidationScope([$container]);
×
182
                                        $control->setAttribute('class', 'btn btn-xs btn-primary');
×
183

184
                                        break;
×
185

186
                                case 'cancel':
×
187
                                        $control->setValidationScope([]);
×
188
                                        $control->setAttribute('class', 'btn btn-xs btn-danger');
×
189

190
                                        break;
×
191

192
                                default:
NEW
193
                                        if ($control->getControlPrototype()->getAttribute('class') === null) {
×
194
                                                $control->setAttribute('class', 'form-control form-control-sm');
×
195
                                        }
196

197
                                        break;
×
198
                        }
199
                }
200
        }
201

202
        /**
203
         * @return static
204
         */
205
        public function setShowNonEditingColumns(bool $show = true): self
206
        {
207
                $this->showNonEditingColumns = $show;
×
208

209
                return $this;
×
210
        }
211

212
        public function showNonEditingColumns(): bool
213
        {
214
                return $this->showNonEditingColumns;
×
215
        }
216

217
        /**
218
         * @return static
219
         */
220
        public function setDataAttribute(string $key, mixed $value): self
221
        {
222
                $this->dataAttributes[$key] = $value;
×
223

224
                return $this;
×
225
        }
226

227
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc