Skip to content

Commit

Permalink
Renamed the Alert and Confirm classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed Nov 27, 2019
1 parent ee2f220 commit 15c17b3
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Alert.php - Interface for alert messages.
* Message.php - Interface for alert messages.
*
* @package jaxon-dialogs
* @author Thierry Feuzeu <thierry.feuzeu@gmail.com>
Expand All @@ -12,7 +12,7 @@

namespace Jaxon\Contracts\Dialogs;

interface Alert
interface Message
{
/**
* Tells if the library should return the javascript code or run it in the browser.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Confirm.php - A confirm question for a Jaxon request
* Question.php - A confirmation question for a Jaxon request
*
* Interface for adding a confirmation question which is asked before calling a Jaxon function.
*
Expand All @@ -13,7 +13,7 @@

namespace Jaxon\Contracts\Dialogs;

interface Confirm
interface Question
{
/**
* Return a script which makes a call only if the user answers yes to the given question
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Alert.php - Interface for alert messages.
* Message.php - Trait for alert messages.
*
* @package jaxon-dialogs
* @author Thierry Feuzeu <thierry.feuzeu@gmail.com>
Expand All @@ -12,7 +12,7 @@

namespace Jaxon\Features\Dialogs;

trait Alert
trait Message
{
/**
*
Expand Down
6 changes: 3 additions & 3 deletions src/Plugin/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ private function _getScript()
$aVars = $this->getOptionVars();
$sYesScript = 'jaxon.ajax.response.process(command.response)';
$sNoScript = 'jaxon.confirm.skip(command);jaxon.ajax.response.process(command.response)';
$sConfirmScript = jaxon()->dialog()->confirm('msg', $sYesScript, $sNoScript);
$aVars['sConfirmScript'] = $this->xTemplate->render('jaxon::plugins/confirm.js', [
'sConfirmScript' => $sConfirmScript,
$sQuestionScript = jaxon()->dialog()->confirm('msg', $sYesScript, $sNoScript);
$aVars['sQuestionScript'] = $this->xTemplate->render('jaxon::plugins/confirm.js', [
'sQuestionScript' => $sQuestionScript,
]);

return $this->xTemplate->render('jaxon::plugins/config.js', $aVars) . "\n" . $this->sJsScript . '
Expand Down
18 changes: 9 additions & 9 deletions src/Plugin/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ private function setPluginPriority(Plugin $xPlugin, $nPriority)
*/
public function registerPlugin(Plugin $xPlugin, $nPriority = 1000)
{
$bIsAlert = ($xPlugin instanceof \Jaxon\Contracts\Dialogs\Alert);
$bIsConfirm = ($xPlugin instanceof \Jaxon\Contracts\Dialogs\Confirm);
$bIsMessage = ($xPlugin instanceof \Jaxon\Contracts\Dialogs\Message);
$bIsQuestion = ($xPlugin instanceof \Jaxon\Contracts\Dialogs\Question);
$bIsListener = ($xPlugin instanceof \Jaxon\Contracts\Event\Listener);
if($xPlugin instanceof Request)
{
Expand All @@ -158,20 +158,20 @@ public function registerPlugin(Plugin $xPlugin, $nPriority = 1000)
// The name of a response plugin is used as key in the plugin table
$this->aResponsePlugins[$xPlugin->getName()] = $xPlugin;
}
elseif(!$bIsConfirm && !$bIsAlert && !$bIsListener)
elseif(!$bIsQuestion && !$bIsMessage && !$bIsListener)
{
$sErrorMessage = $this->trans('errors.register.invalid', ['name' => get_class($xPlugin)]);
throw new \Jaxon\Exception\Error($sErrorMessage);
}
// This plugin implements the Alert interface
if($bIsAlert)
// This plugin implements the Message interface
if($bIsMessage)
{
jaxon()->dialog()->setAlert($xPlugin);
jaxon()->dialog()->setMessage($xPlugin);
}
// This plugin implements the Confirm interface
if($bIsConfirm)
// This plugin implements the Question interface
if($bIsQuestion)
{
jaxon()->dialog()->setConfirm($xPlugin);
jaxon()->dialog()->setQuestion($xPlugin);
}
// Register the plugin as an event listener
if($bIsListener)
Expand Down
2 changes: 1 addition & 1 deletion src/Request/Factory/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function getScript()
$sScript = 'if(' . $this->sCondition . '){' . $sScript . ';}';
if(($sPhrase))
{
$xDialog->getAlert()->setReturn(true);
$xDialog->getMessage()->setReturn(true);
$sScript .= 'else{' . $xDialog->warning($sPhrase) . ';}';
}
}
Expand Down
88 changes: 44 additions & 44 deletions src/Utils/Dialogs/Dialog.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Dialogs.php - Shows alert and confirm dialogs
* Dialog.php - Shows alert and confirm dialogs
*
* @author Thierry Feuzeu <thierry.feuzeu@gmail.com>
* @copyright 2019 Thierry Feuzeu <thierry.feuzeu@gmail.com>
Expand All @@ -11,133 +11,133 @@

namespace Jaxon\Utils\Dialogs;

use Jaxon\Contracts\Dialogs\Alert as AlertContract;
use Jaxon\Contracts\Dialogs\Confirm as ConfirmContract;
use Jaxon\Contracts\Dialogs\Message as MessageContract;
use Jaxon\Contracts\Dialogs\Question as QuestionContract;

class Dialog
{
/**
* Javascript confirm function
*
* @var ConfirmContract
* @var QuestionContract
*/
private $xConfirm;
private $xQuestion;

/**
* Default javascript confirm function
*
* @var ConfirmContract
* @var QuestionContract
*/
private $xDefaultConfirm;
private $xDefaultQuestion;

/**
* Javascript alert function
*
* @var AlertContract
* @var MessageContract
*/
private $xAlert;
private $xMessage;

/**
* Default javascript alert function
*
* @var AlertContract
* @var MessageContract
*/
private $xDefaultAlert;
private $xDefaultMessage;

/**
* The constructor
*/
public function __construct()
{
// Javascript confirm function
$this->xConfirm = null;
$this->xDefaultConfirm = new Confirm();
$this->xQuestion = null;
$this->xDefaultQuestion = new Question();

// Javascript alert function
$this->xAlert = null;
$this->xDefaultAlert = new Alert();
$this->xMessage = null;
$this->xDefaultMessage = new Message();
}

/**
* Set the javascript confirm function
*
* @param ConfirmContract $xConfirm The javascript confirm function
* @param QuestionContract $xQuestion The javascript confirm function
*
* @return void
*/
public function setConfirm(ConfirmContract $xConfirm)
public function setQuestion(QuestionContract $xQuestion)
{
$this->xConfirm = $xConfirm;
$this->xQuestion = $xQuestion;
}

/**
* Get the javascript confirm function
* Get the javascript question function
*
* @return ConfirmContract
* @return QuestionContract
*/
public function getConfirm()
public function getQuestion()
{
return (($this->xConfirm) ? $this->xConfirm : $this->xDefaultConfirm);
return (($this->xQuestion) ? $this->xQuestion : $this->xDefaultQuestion);
}

/**
* Get the default javascript confirm function
*
* @return ConfirmContract
* @return QuestionContract
*/
public function getDefaultConfirm()
public function getDefaultQuestion()
{
return $this->xDefaultConfirm;
return $this->xDefaultQuestion;
}

/**
* Set the javascript alert function
*
* @param AlertContract $xAlert The javascript alert function
* @param MessageContract $xMessage The javascript alert function
*
* @return void
*/
public function setAlert(AlertContract $xAlert)
public function setMessage(MessageContract $xMessage)
{
$this->xAlert = $xAlert;
$this->xMessage = $xMessage;
}

/**
* Get the javascript alert function
*
* @return AlertContract
* @return MessageContract
*/
public function getAlert()
public function getMessage()
{
return (($this->xAlert) ? $this->xAlert : $this->xDefaultAlert);
return (($this->xMessage) ? $this->xMessage : $this->xDefaultMessage);
}

/**
* Get the default javascript alert function
*
* @return Alert
* @return Message
*/
public function getDefaultAlert()
public function getDefaultMessage()
{
return $this->xDefaultAlert;
return $this->xDefaultMessage;
}

/**
* Get the script which makes a call only if the user answers yes to the given question
*
* It is a function of the Confirm interface.
* It is a function of the Question interface.
*
* @return string
*/
public function confirm($question, $yesScript, $noScript)
{
return $this->getConfirm()->confirm($question, $yesScript, $noScript);
return $this->getQuestion()->confirm($question, $yesScript, $noScript);
}

/**
* Print a success message.
*
* It is a function of the Alert interface.
* It is a function of the Message interface.
*
* @param string $message The text of the message
* @param string|null $title The title of the message
Expand All @@ -146,13 +146,13 @@ public function confirm($question, $yesScript, $noScript)
*/
public function success($message, $title = null)
{
return $this->getAlert()->success($message, $title);
return $this->getMessage()->success($message, $title);
}

/**
* Print an information message.
*
* It is a function of the Alert interface.
* It is a function of the Message interface.
*
* @param string $message The text of the message
* @param string|null $title The title of the message
Expand All @@ -161,13 +161,13 @@ public function success($message, $title = null)
*/
public function info($message, $title = null)
{
return $this->getAlert()->info($message, $title);
return $this->getMessage()->info($message, $title);
}

/**
* Print a warning message.
*
* It is a function of the Alert interface.
* It is a function of the Message interface.
*
* @param string $message The text of the message
* @param string|null $title The title of the message
Expand All @@ -176,13 +176,13 @@ public function info($message, $title = null)
*/
public function warning($message, $title = null)
{
return $this->getAlert()->warning($message, $title);
return $this->getMessage()->warning($message, $title);
}

/**
* Print an error message.
*
* It is a function of the Alert interface.
* It is a function of the Message interface.
*
* @param string $message The text of the message
* @param string|null $title The title of the message
Expand All @@ -191,6 +191,6 @@ public function warning($message, $title = null)
*/
public function error($message, $title = null)
{
return $this->getAlert()->error($message, $title);
return $this->getMessage()->error($message, $title);
}
}
Loading

0 comments on commit 15c17b3

Please sign in to comment.