Bearsampp
2026.7.11
Toggle main menu visibility
Loading...
Searching...
No Matches
class.action.dialogBase.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2024 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
17
abstract
class
ActionDialogBase
18
{
19
protected
$wbWindow
;
20
protected
$wbProgressBar
;
21
protected
$wbBtnSave
;
22
protected
$wbBtnCancel
;
23
protected
$wbBtnDelete
;
24
25
protected
$initValue
;
// Initial value for edit operations
26
27
const
GAUGE_SAVE
= 2;
28
const
GAUGE_DELETE
= 2;
29
35
abstract
protected
function
getWindowTitle
();
36
42
protected
function
getGaugeSave
()
43
{
44
return
self::GAUGE_SAVE;
45
}
46
52
protected
function
getGaugeDelete
()
53
{
54
return
self::GAUGE_DELETE;
55
}
56
64
abstract
protected
function
createFormFields
($bearsamppWinbinder);
65
72
abstract
protected
function
getFormValues
($bearsamppWinbinder);
73
80
abstract
protected
function
validateInput
($values);
81
88
abstract
protected
function
itemExists
($values);
89
96
abstract
protected
function
saveItem
($values);
97
103
abstract
protected
function
deleteItem
();
104
111
abstract
protected
function
getSaveSuccessMessage
($values);
112
118
abstract
protected
function
getSaveErrorMessage
();
119
125
abstract
protected
function
getDeleteConfirmMessage
();
126
132
abstract
protected
function
getDeleteSuccessMessage
();
133
139
abstract
protected
function
getDeleteErrorMessage
();
140
146
abstract
protected
function
getDialogTitle
();
147
153
abstract
protected
function
getDeleteDialogTitle
();
154
160
protected
function
isEditMode
()
161
{
162
return
isset($this->initValue) && !empty($this->initValue);
163
}
164
170
abstract
protected
function
restartService
();
171
178
protected
function
initializeDialog
($args)
179
{
180
// To be implemented by child classes if needed
181
return
true
;
182
}
183
189
public
function
__construct
($args)
190
{
191
global $bearsamppWinbinder;
192
193
// Initialize dialog (child class can load data, etc.)
194
if
(!$this->
initializeDialog
($args)) {
195
return
;
196
}
197
198
$bearsamppWinbinder->reset();
199
$this->wbWindow = $bearsamppWinbinder->createAppWindow(
200
$this->
getWindowTitle
(),
201
490,
202
200,
203
WBC_NOTIFY,
204
WBC_KEYDOWN | WBC_KEYUP
205
);
206
207
// Create form fields (implemented by child class)
208
$this->
createFormFields
($bearsamppWinbinder);
209
210
// Create progress bar and buttons
211
$this->
createButtons
($bearsamppWinbinder);
212
213
// Set up event handler
214
$bearsamppWinbinder->setHandler($this->wbWindow, $this,
'processWindow'
);
215
$bearsamppWinbinder->mainLoop();
216
$bearsamppWinbinder->reset();
217
}
218
225
protected
function
createButtons
($bearsamppWinbinder)
226
{
227
global
$bearsamppLang
;
228
229
$this->wbProgressBar = $bearsamppWinbinder->createProgressBar(
230
$this->wbWindow,
231
$this->
getGaugeSave
() + 1,
232
15,
233
137,
234
$this->
isEditMode
() ? 190 : 275
235
);
236
237
if
($this->
isEditMode
()) {
238
// Edit mode: Save, Delete, Cancel
239
$this->wbBtnSave = $bearsamppWinbinder->createButton(
240
$this->wbWindow,
241
$bearsamppLang
->getValue(
Lang::BUTTON_SAVE
),
242
215,
243
132
244
);
245
$this->wbBtnDelete = $bearsamppWinbinder->createButton(
246
$this->wbWindow,
247
$bearsamppLang
->getValue(
Lang::BUTTON_DELETE
),
248
300,
249
132
250
);
251
$this->wbBtnCancel = $bearsamppWinbinder->createButton(
252
$this->wbWindow,
253
$bearsamppLang
->getValue(
Lang::BUTTON_CANCEL
),
254
385,
255
132
256
);
257
}
else
{
258
// Add mode: Save, Cancel
259
$this->wbBtnSave = $bearsamppWinbinder->createButton(
260
$this->wbWindow,
261
$bearsamppLang
->getValue(
Lang::BUTTON_SAVE
),
262
300,
263
132
264
);
265
$this->wbBtnCancel = $bearsamppWinbinder->createButton(
266
$this->wbWindow,
267
$bearsamppLang
->getValue(
Lang::BUTTON_CANCEL
),
268
387,
269
132
270
);
271
}
272
}
273
284
public
function
processWindow
($window, $id, $ctrl, $param1, $param2)
285
{
286
global $bearsamppWinbinder;
287
288
// Handle save button
289
if
($id == $this->wbBtnSave[
WinBinder::CTRL_ID
]) {
290
$this->
handleSave
($window);
291
return
;
292
}
293
294
// Handle delete button (if in edit mode)
295
if
($this->
isEditMode
() && $id == $this->wbBtnDelete[
WinBinder::CTRL_ID
]) {
296
$this->
handleDelete
($window);
297
return
;
298
}
299
300
// Handle cancel button or window close
301
if
($id == IDCLOSE || $id == $this->wbBtnCancel[
WinBinder::CTRL_ID
]) {
302
$bearsamppWinbinder->destroyWindow($window);
303
return
;
304
}
305
306
// Handle custom events (implemented by child class)
307
$this->
handleCustomEvent
($window, $id, $ctrl, $param1, $param2);
308
}
309
320
protected
function
handleCustomEvent
($window, $id, $ctrl, $param1, $param2)
321
{
322
// Default: do nothing
323
// Child classes can override to handle specific events
324
}
325
332
protected
function
handleSave
($window)
333
{
334
global $bearsamppWinbinder;
335
336
$bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, $this->
getGaugeSave
() + 1);
337
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
338
339
// Get form values
340
$values = $this->
getFormValues
($bearsamppWinbinder);
341
342
// Validate input
343
$validation = $this->
validateInput
($values);
344
if
(!$validation[
'valid'
]) {
345
$bearsamppWinbinder->messageBoxError(
346
$validation[
'error'
],
347
$this->
getDialogTitle
()
348
);
349
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
350
return
;
351
}
352
353
// Check if item already exists (for add or rename operations)
354
if
($this->
itemExists
($values)) {
355
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
356
return
;
357
}
358
359
// Save the item
360
if
($this->
saveItem
($values)) {
361
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
362
363
// Restart service
364
$this->
restartService
();
365
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
366
367
// Show success message
368
$bearsamppWinbinder->messageBoxInfo(
369
$this->
getSaveSuccessMessage
($values),
370
$this->
getDialogTitle
()
371
);
372
$bearsamppWinbinder->destroyWindow($window);
373
}
else
{
374
$bearsamppWinbinder->messageBoxError(
375
$this->
getSaveErrorMessage
(),
376
$this->
getDialogTitle
()
377
);
378
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
379
}
380
}
381
388
protected
function
handleDelete
($window)
389
{
390
global $bearsamppWinbinder;
391
392
$bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, $this->
getGaugeDelete
() + 1);
393
394
// Confirm deletion
395
$confirm = $bearsamppWinbinder->messageBoxYesNo(
396
$this->
getDeleteConfirmMessage
(),
397
$this->
getDeleteDialogTitle
()
398
);
399
400
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
401
402
if
($confirm) {
403
if
($this->
deleteItem
()) {
404
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
405
406
// Restart service
407
$this->
restartService
();
408
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
409
410
// Show success message
411
$bearsamppWinbinder->messageBoxInfo(
412
$this->
getDeleteSuccessMessage
(),
413
$this->
getDeleteDialogTitle
()
414
);
415
$bearsamppWinbinder->destroyWindow($window);
416
}
else
{
417
$bearsamppWinbinder->messageBoxError(
418
$this->
getDeleteErrorMessage
(),
419
$this->
getDeleteDialogTitle
()
420
);
421
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
422
}
423
}
else
{
424
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
425
}
426
}
427
}
428
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
ActionDialogBase
Definition
class.action.dialogBase.php:18
ActionDialogBase\createFormFields
createFormFields($bearsamppWinbinder)
ActionDialogBase\$wbBtnDelete
$wbBtnDelete
Definition
class.action.dialogBase.php:23
ActionDialogBase\createButtons
createButtons($bearsamppWinbinder)
Definition
class.action.dialogBase.php:225
ActionDialogBase\getGaugeDelete
getGaugeDelete()
Definition
class.action.dialogBase.php:52
ActionDialogBase\$initValue
$initValue
Definition
class.action.dialogBase.php:25
ActionDialogBase\$wbWindow
$wbWindow
Definition
class.action.dialogBase.php:19
ActionDialogBase\GAUGE_DELETE
const GAUGE_DELETE
Definition
class.action.dialogBase.php:28
ActionDialogBase\getDeleteSuccessMessage
getDeleteSuccessMessage()
ActionDialogBase\handleCustomEvent
handleCustomEvent($window, $id, $ctrl, $param1, $param2)
Definition
class.action.dialogBase.php:320
ActionDialogBase\__construct
__construct($args)
Definition
class.action.dialogBase.php:189
ActionDialogBase\validateInput
validateInput($values)
ActionDialogBase\getSaveSuccessMessage
getSaveSuccessMessage($values)
ActionDialogBase\getDeleteDialogTitle
getDeleteDialogTitle()
ActionDialogBase\getSaveErrorMessage
getSaveErrorMessage()
ActionDialogBase\handleSave
handleSave($window)
Definition
class.action.dialogBase.php:332
ActionDialogBase\restartService
restartService()
ActionDialogBase\getDeleteErrorMessage
getDeleteErrorMessage()
ActionDialogBase\getDialogTitle
getDialogTitle()
ActionDialogBase\saveItem
saveItem($values)
ActionDialogBase\$wbBtnCancel
$wbBtnCancel
Definition
class.action.dialogBase.php:22
ActionDialogBase\deleteItem
deleteItem()
ActionDialogBase\isEditMode
isEditMode()
Definition
class.action.dialogBase.php:160
ActionDialogBase\$wbBtnSave
$wbBtnSave
Definition
class.action.dialogBase.php:21
ActionDialogBase\getDeleteConfirmMessage
getDeleteConfirmMessage()
ActionDialogBase\getWindowTitle
getWindowTitle()
ActionDialogBase\getFormValues
getFormValues($bearsamppWinbinder)
ActionDialogBase\GAUGE_SAVE
const GAUGE_SAVE
Definition
class.action.dialogBase.php:27
ActionDialogBase\processWindow
processWindow($window, $id, $ctrl, $param1, $param2)
Definition
class.action.dialogBase.php:284
ActionDialogBase\getGaugeSave
getGaugeSave()
Definition
class.action.dialogBase.php:42
ActionDialogBase\initializeDialog
initializeDialog($args)
Definition
class.action.dialogBase.php:178
ActionDialogBase\$wbProgressBar
$wbProgressBar
Definition
class.action.dialogBase.php:20
ActionDialogBase\handleDelete
handleDelete($window)
Definition
class.action.dialogBase.php:388
ActionDialogBase\itemExists
itemExists($values)
Lang\BUTTON_CANCEL
const BUTTON_CANCEL
Definition
class.lang.php:370
Lang\BUTTON_DELETE
const BUTTON_DELETE
Definition
class.lang.php:367
Lang\BUTTON_SAVE
const BUTTON_SAVE
Definition
class.lang.php:368
WinBinder\CTRL_ID
const CTRL_ID
Definition
class.winbinder.php:21
sandbox
core
classes
actions
class.action.dialogBase.php
Generated by
1.17.0