Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
ActionDialogBase Class Reference
Inheritance diagram for ActionDialogBase:

Public Member Functions

 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)

Data Fields

const GAUGE_DELETE = 2
const GAUGE_SAVE = 2

Protected Member Functions

 createButtons ($bearsamppWinbinder)
 createFormFields ($bearsamppWinbinder)
 deleteItem ()
 getDeleteConfirmMessage ()
 getDeleteDialogTitle ()
 getDeleteErrorMessage ()
 getDeleteSuccessMessage ()
 getDialogTitle ()
 getFormValues ($bearsamppWinbinder)
 getGaugeDelete ()
 getGaugeSave ()
 getSaveErrorMessage ()
 getSaveSuccessMessage ($values)
 getWindowTitle ()
 handleCustomEvent ($window, $id, $ctrl, $param1, $param2)
 handleDelete ($window)
 handleSave ($window)
 initializeDialog ($args)
 isEditMode ()
 itemExists ($values)
 restartService ()
 saveItem ($values)
 validateInput ($values)

Protected Attributes

 $initValue
 $wbBtnCancel
 $wbBtnDelete
 $wbBtnSave
 $wbProgressBar
 $wbWindow

Detailed Description

Class ActionDialogBase

Base class for dialog-based actions (Add/Edit Alias/Vhost). This class provides common functionality for creating and managing dialog windows with form fields, validation, and save/delete operations.

Definition at line 17 of file class.action.dialogBase.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

Constructor for dialog actions

Parameters
array$argsCommand line arguments

Definition at line 189 of file class.action.dialogBase.php.

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 }
createFormFields($bearsamppWinbinder)
createButtons($bearsamppWinbinder)

References createButtons(), createFormFields(), getWindowTitle(), and initializeDialog().

Member Function Documentation

◆ createButtons()

createButtons ( $bearsamppWinbinder)
protected

Create standard buttons (Save, Delete, Cancel)

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
void

Definition at line 225 of file class.action.dialogBase.php.

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,
242 215,
243 132
244 );
245 $this->wbBtnDelete = $bearsamppWinbinder->createButton(
246 $this->wbWindow,
248 300,
249 132
250 );
251 $this->wbBtnCancel = $bearsamppWinbinder->createButton(
252 $this->wbWindow,
254 385,
255 132
256 );
257 } else {
258 // Add mode: Save, Cancel
259 $this->wbBtnSave = $bearsamppWinbinder->createButton(
260 $this->wbWindow,
262 300,
263 132
264 );
265 $this->wbBtnCancel = $bearsamppWinbinder->createButton(
266 $this->wbWindow,
268 387,
269 132
270 );
271 }
272 }
global $bearsamppLang
const BUTTON_CANCEL
const BUTTON_DELETE
const BUTTON_SAVE

References $bearsamppLang, Lang\BUTTON_CANCEL, Lang\BUTTON_DELETE, Lang\BUTTON_SAVE, getGaugeSave(), and isEditMode().

Referenced by __construct().

◆ createFormFields()

createFormFields ( $bearsamppWinbinder)
abstractprotected

Create form fields specific to the dialog This method should create all input fields, labels, and buttons

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
void

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by __construct().

◆ deleteItem()

deleteItem ( )
abstractprotected

Delete the item

Returns
bool True on success, false on failure

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleDelete().

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
abstractprotected

Get delete confirmation message

Returns
string The confirmation message

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleDelete().

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
abstractprotected

Get the delete dialog title

Returns
string The delete dialog title

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleDelete().

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
abstractprotected

Get error message after delete failure

Returns
string The error message

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleDelete().

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
abstractprotected

Get success message after delete

Returns
string The success message

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleDelete().

◆ getDialogTitle()

getDialogTitle ( )
abstractprotected

Get the dialog title for messages

Returns
string The dialog title

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
abstractprotected

Get the current form values

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
array Associative array of form values

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

◆ getGaugeDelete()

getGaugeDelete ( )
protected

Get the gauge value for delete operation (can be overridden)

Returns
int The gauge value

Definition at line 52 of file class.action.dialogBase.php.

53 {
54 return self::GAUGE_DELETE;
55 }

Referenced by handleDelete().

◆ getGaugeSave()

getGaugeSave ( )
protected

Get the gauge value for save operation (can be overridden)

Returns
int The gauge value

Reimplemented in ActionEditVhost.

Definition at line 42 of file class.action.dialogBase.php.

43 {
44 return self::GAUGE_SAVE;
45 }

Referenced by createButtons(), and handleSave().

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
abstractprotected

Get error message after save failure

Returns
string The error message

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
abstractprotected

Get success message after save

Parameters
array$valuesThe form values
Returns
string The success message

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

◆ getWindowTitle()

getWindowTitle ( )
abstractprotected

Get the dialog window title

Returns
string The window title

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by __construct().

◆ handleCustomEvent()

handleCustomEvent ( $window,
$id,
$ctrl,
$param1,
$param2 )
protected

Handle custom events (can be overridden by child classes)

Parameters
resource$windowThe window resource
int$idThe control ID
resource$ctrlThe control resource
mixed$param1Additional parameter 1
mixed$param2Additional parameter 2
Returns
void

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Definition at line 320 of file class.action.dialogBase.php.

321 {
322 // Default: do nothing
323 // Child classes can override to handle specific events
324 }

Referenced by processWindow().

◆ handleDelete()

handleDelete ( $window)
protected

Handle delete operation

Parameters
resource$windowThe window resource
Returns
void

Definition at line 388 of file class.action.dialogBase.php.

389 {
390 global $bearsamppWinbinder;
391
392 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, $this->getGaugeDelete() + 1);
393
394 // Confirm deletion
395 $confirm = $bearsamppWinbinder->messageBoxYesNo(
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(
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 }

References deleteItem(), getDeleteConfirmMessage(), getDeleteDialogTitle(), getDeleteErrorMessage(), getDeleteSuccessMessage(), getGaugeDelete(), and restartService().

Referenced by processWindow().

◆ handleSave()

handleSave ( $window)
protected

Handle save operation

Parameters
resource$windowThe window resource
Returns
void

Definition at line 332 of file class.action.dialogBase.php.

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 }
validateInput($values)
getSaveSuccessMessage($values)
saveItem($values)
getFormValues($bearsamppWinbinder)
itemExists($values)

References getDialogTitle(), getFormValues(), getGaugeSave(), getSaveErrorMessage(), getSaveSuccessMessage(), itemExists(), restartService(), saveItem(), and validateInput().

Referenced by processWindow().

◆ initializeDialog()

initializeDialog ( $args)
protected

Initialize the dialog window

Parameters
array$argsCommand line arguments
Returns
bool True if initialization successful, false otherwise

Reimplemented in ActionEditAlias, and ActionEditVhost.

Definition at line 178 of file class.action.dialogBase.php.

179 {
180 // To be implemented by child classes if needed
181 return true;
182 }

Referenced by __construct().

◆ isEditMode()

isEditMode ( )
protected

Check if this is an edit operation (has delete button)

Returns
bool True if edit operation, false if add operation

Definition at line 160 of file class.action.dialogBase.php.

161 {
162 return isset($this->initValue) && !empty($this->initValue);
163 }

Referenced by createButtons(), and processWindow().

◆ itemExists()

itemExists ( $values)
abstractprotected

Check if the item already exists (for add/edit operations)

Parameters
array$valuesThe form values
Returns
bool True if exists, false otherwise

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

◆ processWindow()

processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Process window events

Parameters
resource$windowThe window resource
int$idThe control ID
resource$ctrlThe control resource
mixed$param1Additional parameter 1
mixed$param2Additional parameter 2
Returns
void

Definition at line 284 of file class.action.dialogBase.php.

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 }
handleCustomEvent($window, $id, $ctrl, $param1, $param2)

References WinBinder\CTRL_ID, handleCustomEvent(), handleDelete(), handleSave(), and isEditMode().

◆ restartService()

restartService ( )
abstractprotected

Restart the service after save/delete

Returns
void

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleDelete(), and handleSave().

◆ saveItem()

saveItem ( $values)
abstractprotected

Save the item (create or update)

Parameters
array$valuesThe form values
Returns
bool True on success, false on failure

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

◆ validateInput()

validateInput ( $values)
abstractprotected

Validate the form input

Parameters
array$valuesThe form values
Returns
array ['valid' => bool, 'error' => string|null]

Reimplemented in ActionAddAlias, ActionAddVhost, ActionEditAlias, and ActionEditVhost.

Referenced by handleSave().

Field Documentation

◆ $initValue

$initValue
protected

Definition at line 25 of file class.action.dialogBase.php.

◆ $wbBtnCancel

$wbBtnCancel
protected

Definition at line 22 of file class.action.dialogBase.php.

◆ $wbBtnDelete

$wbBtnDelete
protected

Definition at line 23 of file class.action.dialogBase.php.

◆ $wbBtnSave

$wbBtnSave
protected

Definition at line 21 of file class.action.dialogBase.php.

◆ $wbProgressBar

$wbProgressBar
protected

Definition at line 20 of file class.action.dialogBase.php.

◆ $wbWindow

$wbWindow
protected

Definition at line 19 of file class.action.dialogBase.php.

◆ GAUGE_DELETE

const GAUGE_DELETE = 2

Definition at line 28 of file class.action.dialogBase.php.

◆ GAUGE_SAVE

const GAUGE_SAVE = 2

Definition at line 27 of file class.action.dialogBase.php.


The documentation for this class was generated from the following file: