PHP Classes

File: src/Libraries/Notify/Plugin.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Modals, alerts and confirmation dialogs for Jaxon   src/Libraries/Notify/Plugin.php   Download  
File: src/Libraries/Notify/Plugin.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Modals, alerts and confirmation dialogs for Jaxon
Display Ajax modal, alert and confirmation dialogs
Author: By
Last change: Upgraded the js code to the 2.0 release of the js library.
Also moved the js and HTML code to separated template files.
Date: 6 years ago
Size: 3,790 bytes
 

Contents

Class file image Download
<?php

/**
 * Plugin.php - Adapter for the Notify library.
 *
 * @package jaxon-dialogs
 * @author Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @copyright 2016 Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
 * @link https://github.com/jaxon-php/jaxon-dialogs
 */

namespace Jaxon\Dialogs\Libraries\Notify;

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('notify', '0.4.2');
    }
   
   
/**
     * 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('notify.js');
    }

   
/**
     * 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('notify/alert.js');
    }

   
/**
     * Print an alert message.
     *
     * @param string $message The text of the message
     * @param string $title The title of the message
     * @param string $class The type of the message
     *
     * @return void
     */
   
protected function alert($message, $title, $class)
    {
        if(
$this->getReturn())
        {
            return
"$.notify(" . $message . ", {className:'" . $class . "', position:'top center'})";
        }
       
$options = array('message' => $message, 'className' => $class);
       
// Show the alert
       
$this->addCommand(array('cmd' => 'notify.alert'), $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, 'warn');
    }

   
/**
     * 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');
    }
}