| 
<?php
 /**
 * Plugin.php - Adapter for the Toastr library.
 *
 * @package jaxon-dialogs
 * @author Thierry Feuzeu <[email protected]>
 * @copyright 2016 Thierry Feuzeu <[email protected]>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
 * @link https://github.com/jaxon-php/jaxon-dialogs
 */
 
 namespace Jaxon\Dialogs\Libraries\Toastr;
 
 use Jaxon\Dialogs\Libraries\Library;
 use Jaxon\Dialogs\Interfaces\Modal;
 use Jaxon\Request\Interfaces\Alert;
 use Jaxon\Request\Interfaces\Confirm;
 
 class Plugin extends Library implements Alert
 {
 use \Jaxon\Request\Traits\Alert;
 
 /**
 * The constructor
 */
 public function __construct()
 {
 parent::__construct('toastr.js', '2.1.3');
 }
 
 /**
 * Get the javascript header code and file includes
 *
 * It is a function of the Jaxon\Dialogs\Interfaces\Plugin interface.
 *
 * @return string
 */
 public function getJs()
 {
 return $this->getJsCode('toastr.min.js');
 }
 
 /**
 * Get the CSS header code and file includes
 *
 * It is a function of the Jaxon\Dialogs\Interfaces\Plugin interface.
 *
 * @return string
 */
 public function getCss()
 {
 return $this->getCssCode('toastr.min.css');
 }
 
 /**
 * Get the javascript code to be printed into the page
 *
 * It is a function of the Jaxon\Dialogs\Interfaces\Plugin interface.
 *
 * @return string
 */
 public function getScript()
 {
 return $this->render('toastr/alert.js', [
 'options' =>  $this->getOptionScript('toastr.options.', 'options.')
 ]);
 }
 
 /**
 * Print an alert message.
 *
 * @param string              $message              The text of the message
 * @param string              $title                The title of the message
 * @param string              $type                 The type of the message
 *
 * @return void
 */
 protected function alert($message, $title, $type)
 {
 if($this->getReturn())
 {
 if(($title))
 {
 return "toastr." . $type . "(" . $message . ", '" . $title . "')";
 }
 else
 {
 return "toastr." . $type . "(" . $message . ")";
 }
 }
 $options = array('message' => $message, 'title' => $title);
 // Show the alert
 $this->addCommand(array('cmd' => 'toastr.' . $type), $options);
 }
 
 /**
 * Print a success message.
 *
 * It is a function of the Jaxon\Request\Interfaces\Alert interface.
 *
 * @param string              $message              The text of the message
 * @param string|null         $title                The title of the message
 *
 * @return void
 */
 public function success($message, $title = null)
 {
 return $this->alert($message, $title, 'success');
 }
 
 /**
 * Print an information message.
 *
 * It is a function of the Jaxon\Request\Interfaces\Alert interface.
 *
 * @param string              $message              The text of the message
 * @param string|null         $title                The title of the message
 *
 * @return void
 */
 public function info($message, $title = null)
 {
 return $this->alert($message, $title, 'info');
 }
 
 /**
 * Print a warning message.
 *
 * It is a function of the Jaxon\Request\Interfaces\Alert interface.
 *
 * @param string              $message              The text of the message
 * @param string|null         $title                The title of the message
 *
 * @return void
 */
 public function warning($message, $title = null)
 {
 return $this->alert($message, $title, 'warning');
 }
 
 /**
 * Print an error message.
 *
 * It is a function of the Jaxon\Request\Interfaces\Alert interface.
 *
 * @param string              $message              The text of the message
 * @param string|null         $title                The title of the message
 *
 * @return void
 */
 public function error($message, $title = null)
 {
 return $this->alert($message, $title, 'error');
 }
 
 public function remove()
 {
 $this->response()->script('toastr.remove()');
 }
 
 public function clear()
 {
 $this->response()->script('toastr.clear()');
 }
 }
 
 |