Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
snippet.php
1<?
2
4
10
11Loc::loadMessages(__FILE__);
12
13
19{
20 protected $applyButton;
21 protected $saveButton;
22 protected $cancelButton;
23 protected $editButton;
24 protected $removeButton;
26 protected $forAllCheckbox;
27
28
33 public function getSaveEditButton()
34 {
35 if (!is_array($this->saveButton))
36 {
37 $onchange = new Onchange();
38 $onchange->addAction(array("ACTION" => Actions::SHOW_ALL, "DATA" => array()));
39 $onchange->addAction(array("ACTION" => Actions::CALLBACK, "DATA" => array(array("JS" => "Grid.editSelectedSave()"))));
40 $onchange->addAction(array("ACTION" => Actions::REMOVE, "DATA" => array(array("ID" => DefaultValue::SAVE_BUTTON_ID), array("ID" => DefaultValue::CANCEL_BUTTON_ID))));
41
42 $saveButton = new Button();
44 $saveButton->setText(Loc::getMessage("SAVE_BUTTON_TEXT"));
46 $saveButton->setOnchange($onchange);
47
48 $this->saveButton = $saveButton->toArray();
49 }
50
51 return $this->saveButton;
52 }
53
54
59 public function getCancelEditButton()
60 {
61 if (!is_array($this->cancelButton))
62 {
63 $onchange = new Onchange();
64 $onchange->addAction(array("ACTION" => Actions::SHOW_ALL, "DATA" => array()));
65 $onchange->addAction(array("ACTION" => Actions::CALLBACK, "DATA" => array(array("JS" => "Grid.editSelectedCancel()"))));
66 $onchange->addAction(array("ACTION" => Actions::REMOVE, "DATA" => array(array("ID" => DefaultValue::SAVE_BUTTON_ID), array("ID" => DefaultValue::CANCEL_BUTTON_ID))));
67
68 $cancelButton = new Button();
70 $cancelButton->setText(Loc::getMessage("CANCEL_BUTTON_TEXT"));
72 $cancelButton->setOnchange($onchange);
73
74 $this->cancelButton = $cancelButton->toArray();
75 }
76
77 return $this->cancelButton;
78 }
79
80
85 public function getEditButton()
86 {
87 if (!is_array($this->editButton))
88 {
89 $onchange = new Onchange();
90 $onchange->addAction(array("ACTION" => Actions::CREATE, "DATA" => array($this->getSaveEditButton(), $this->getCancelEditButton())));
91 $onchange->addAction(array("ACTION" => Actions::CALLBACK, "DATA" => array(array("JS" => "Grid.editSelected()"))));
92 $onchange->addAction(array("ACTION" => Actions::HIDE_ALL_EXPECT, "DATA" => array(array("ID" => DefaultValue::SAVE_BUTTON_ID), array("ID" => DefaultValue::CANCEL_BUTTON_ID))));
93
94 $editButton = new Button();
97 $editButton->setText(Loc::getMessage("EDIT_ACTION_NAME"));
98 $editButton->setOnchange($onchange);
99 $editButton->setTitle(Loc::getMessage("EDIT_BUTTON_TITLE"));
100
101 $this->editButton = $editButton->toArray();
102 }
103
104 return $this->editButton;
105 }
106
107
112 public function getEditAction()
113 {
114 return array(
115 "NAME" => GetMessage("EDIT_ACTION_NAME"),
116 "VALUE" => "edit",
117 "ONCHANGE" => array(
118 array("ACTION" => Actions::CREATE, "DATA" => array($this->getSaveEditButton(), $this->getCancelEditButton())),
119 array("ACTION" => Actions::CALLBACK, "DATA" => array(array("JS" => "Grid.editSelected()"))),
120 array("ACTION" => Actions::HIDE_ALL_EXPECT, "DATA" => array(array("ID" => DefaultValue::SAVE_BUTTON_ID), array("ID" => DefaultValue::CANCEL_BUTTON_ID)))
121 )
122 );
123 }
124
125
130 public function getRemoveButton()
131 {
132 if (!is_array($this->removeButton))
133 {
134 $onchange = new Onchange();
135 $onchange->addAction(
136 array(
137 "ACTION" => Actions::CALLBACK,
138 "CONFIRM" => true,
139 "CONFIRM_APPLY_BUTTON" => Loc::getMessage("CONFIRM_APPLY_REMOVE_BUTTON_TEXT"),
140 "DATA" => array(
141 array("JS" => "Grid.removeSelected()")
142 )
143 )
144 );
145
146 $removeButton = new Button();
149 $removeButton->setOnchange($onchange);
150 $removeButton->setText(Loc::getMessage("REMOVE_ACTION_NAME"));
151 $removeButton->setTitle(Loc::getMessage("REMOVE_BUTTON_TITLE"));
152
153 $this->removeButton = $removeButton->toArray();
154 }
155
156 return $this->removeButton;
157 }
158
159
164 public function getRemoveAction()
165 {
166 return array(
167 "NAME" => GetMessage("REMOVE_ACTION_NAME"),
168 "VALUE" => "remove",
169 "ONCHANGE" => array(
170 array(
171 "ACTION" => Actions::CALLBACK,
172 "CONFIRM" => true,
173 "CONFIRM_APPLY_BUTTON" => Loc::getMessage("CONFIRM_APPLY_REMOVE_BUTTON_TEXT"),
174 "DATA" => array(
175 array("JS" => "Grid.removeSelected()")
176 )
177 )
178 )
179 );
180 }
181
187 public function getApplyButton(array $params)
188 {
189 return array(
190 'TYPE' => Types::BUTTON,
191 'ID' => "apply_button",
192 'CLASS' => "apply",
193 'TEXT' => Loc::getMessage("APPLY_BUTTON_TEXT"),
194 'ONCHANGE' => isset($params['ONCHANGE']) && is_array($params['ONCHANGE']) ? $params['ONCHANGE'] : array()
195 );
196 }
197
203 public function getSendSelectedButton(?string $confirmMessage = null): array
204 {
205 $action = [
206 'ACTION' => Actions::CALLBACK,
207 'DATA' => [
208 [
209 'JS' => 'Grid.sendSelected()',
210 ]
211 ],
212 ];
213
214 if (!empty($confirmMessage))
215 {
216 $action['CONFIRM'] = true;
217 $action['CONFIRM_MESSAGE'] = $confirmMessage;
218 }
219
220 $onchange = new Onchange();
221 $onchange->addAction($action);
222
223 $button = new Button();
224 $button->setId('apply_button');
225 $button->setClass('apply');
226 $button->setOnchange($onchange);
227 $button->setText(Loc::getMessage("APPLY_BUTTON_TEXT"));
228
229 return $button->toArray();
230 }
231
236 public function getForAllCheckbox()
237 {
238 if (!is_array($this->forAllCheckbox))
239 {
240 $onchange = new Onchange();
241 $onchange->addAction(array("ACTION" => Actions::CALLBACK, "DATA" => array(array("JS" => "Grid.confirmForAll()"))));
242
243 $checkbox = new Checkbox();
244 $checkbox->setId(DefaultValue::FOR_ALL_CHECKBOX_ID);
245 $checkbox->setOnchange($onchange);
246 $checkbox->setName(DefaultValue::FOR_ALL_CHECKBOX_NAME);
247 $checkbox->setValue(DefaultValue::FOR_ALL_CHECKBOX_VALUE);
248 $checkbox->setClass(DefaultValue::FOR_ALL_CHECKBOX_CLASS);
249 $this->forAllCheckbox = $checkbox->toArray();
250 }
251
252 return $this->forAllCheckbox;
253 }
254
260 public function setButtonActions(array &$button, array $actions)
261 {
262 $handler = new Onchange($actions);
263 $button["ONCHANGE"] = $handler->toArray();
264 }
265}
getApplyButton(array $params)
Definition snippet.php:187
getSendSelectedButton(?string $confirmMessage=null)
Definition snippet.php:203
setButtonActions(array &$button, array $actions)
Definition snippet.php:260
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29