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

contributte / datagrid / 8230157862

11 Mar 2024 09:02AM UTC coverage: 34.102%. First build
8230157862

Pull #1060

github

radimvaculik
Fix failing tests
Pull Request #1060: [7.x] Next

117 of 435 new or added lines in 54 files covered. (26.9%)

1124 of 3296 relevant lines covered (34.1%)

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

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

67
                $this->onControlAfterAdd[] = [$this, 'addControlsClasses'];
×
68
        }
69

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

77
                return $this;
×
78
        }
79

80
        public function getItemId(): mixed
81
        {
82
                return $this->itemID;
×
83
        }
84

85
        public function getPrimaryWhereColumn(): ?string
86
        {
87
                return $this->primaryWhereColumn;
×
88
        }
89

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

95
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
96

97
                $a->addText($this->text);
×
98

99
                if ($this->title !== null) {
×
100
                        $a->setAttribute(
×
101
                                'title',
×
102
                                $this->grid->getTranslator()->translate($this->title)
×
103
                        );
104
                }
105

NEW
106
                if ($this->class !== '') {
×
107
                        $a->appendAttribute('class', $this->class);
×
108
                }
109

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

112
                return $a;
×
113
        }
114

115
        /**
116
         * Render row item detail button
117
         */
118
        public function renderButtonAdd(): Html
119
        {
120
                $a = Html::el('a')
×
121
                        ->href($this->grid->link('showInlineAdd!'));
×
122

123
                $this->tryAddIcon($a, $this->getIcon(), $this->getText());
×
124

125
                $a->addText($this->text);
×
126

127
                if ($this->title !== null) {
×
128
                        $a->setAttribute(
×
129
                                'title',
×
130
                                $this->grid->getTranslator()->translate($this->title)
×
131
                        );
132
                }
133

NEW
134
                if ($this->class !== '') {
×
135
                        $a->appendAttribute('class', $this->class);
×
136
                }
137

138
                return $a;
×
139
        }
140

141
        /**
142
         * @return static
143
         */
144
        public function setPositionTop(bool $positionTop = true): self
145
        {
146
                $this->positionTop = $positionTop;
×
147

148
                return $this;
×
149
        }
150

151
        public function isPositionTop(): bool
152
        {
153
                return $this->positionTop;
×
154
        }
155

156
        public function isPositionBottom(): bool
157
        {
158
                return !$this->positionTop;
×
159
        }
160

161
        public function addControlsClasses(Container $container): void
162
        {
163
                foreach ($container->getControls() as $key => $control) {
×
164
                        switch ($key) {
×
165
                                case 'submit':
×
166
                                        $control->setValidationScope([$container]);
×
167
                                        $control->setAttribute('class', 'btn btn-xs btn-primary');
×
168

169
                                        break;
×
170

171
                                case 'cancel':
×
172
                                        $control->setValidationScope([]);
×
173
                                        $control->setAttribute('class', 'btn btn-xs btn-danger');
×
174

175
                                        break;
×
176

177
                                default:
178
                                        if ($control->getControl()->getAttribute('class') === null) {
×
NEW
179
                                                $control->setAttribute('class', 'form-control form-control-sm');
×
180
                                        }
181

182
                                        break;
×
183
                        }
184
                }
185
        }
186

187
        /**
188
         * @return static
189
         */
190
        public function setShowNonEditingColumns(bool $show = true): self
191
        {
192
                $this->showNonEditingColumns = $show;
×
193

194
                return $this;
×
195
        }
196

197
        public function showNonEditingColumns(): bool
198
        {
199
                return $this->showNonEditingColumns;
×
200
        }
201

202
}
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

© 2025 Coveralls, Inc