Download .zip |
Info | Documentation | View files (45) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2018-02-28 (10 hours ago) | Not enough user ratings | Total: 97 This week: 5 | All time: 8,888 This week: 121 |
Version | License | PHP version | Categories | |||
jaxon-dialogs 1.2.1 | BSD License | 5 | PHP 5, Utilities and Tools, Libraries, A... |
Description | Author | |
This packages can display modal, alert and confirmation dialogs in Jaxon-based PHP applications using various Javascript libraries. |
Modals, alerts and confirmation dialogs for Jaxon with various javascript libraries.
This package provides modal, alert and confirmation dialogs to Jaxon applications with various javascript libraries. 16 libraries are currently supported.
The javascript library to use for each function is chosen by configuration, and the package takes care of loading the library files into the page and generating the javascript code.
The URL and version number can be set individually for each javascript library.
Add the following lines in the composer.json
file, and run the composer update
command.
"require": {
"jaxon-php/jaxon-core": "~2.0",
"jaxon-php/jaxon-dialogs": "~1.0"
}
This package defines 3 config options in the default
section to set the default library to be used resp.
for modal, alert and confirmation dialogs.
The libraries
option allows to load additional libraries into the page.
The confirm
section defines options for the confirm dialog.
The lib.uri
option defines the URI where to download the libraries files from.
Specific options can also be set for each library.
'dialogs' => array(
'default' => array(
'modal' => 'bootstrap', // Default library for modal dialogs
'alert' => 'jconfirm', // Default library for alerts
'confirm' => 'noty', // Default library for confirmation
),
'libraries' => array('pgwjs', 'toastr'), // Additional libraries
'lib' => array(
'uri' => 'https://cdn.jaxon-php.org/libs',
),
// Confirm options
'confirm' => array(
'title' => 'Question', // The confirm dialog
'yes' => 'Oh Yes', // The text of the Yes button
'no' => 'No way', // The text of the No button
),
// Options for the Toastr library
'toastr' => array(
'options' => array(
'closeButton' => true,
'positionClass' => 'toast-top-center'
),
),
// Load a different version of the JQuery Confirm library from a different CDN
'jconfirm' => array(
'uri' => 'https://cdnjs.cloudflare.com/ajax/libs',
'subdir' => 'jquery-confirm',
'version' => '3.3.2',
),
),
This plugin provides functions to show and hide modal dialogs, with a title, a content and zero or more buttons.
/
* Show a modal dialog.
*/
public function show($title, $content, array $buttons, array $options = array());
/
* Hide the modal dialog.
*/
public function hide();
The parameters of the show()
methods are described as follow:
$title
: is a one line text to be printed at the top of the dialog.$content
: the HTML content of the dialog.$buttons
: a list of buttons to be printed in the dialog. Each button is an array with the following entries:
- title
: the text to be printed in the button.
- class
: the CSS class or classes to be applied on the button.
- click
: the javascript code to be executed on a click on this button. It can be defined using the Request Factory, or it can be set to close
to close the dialog.$options
: an array of config options that are specific to the javascript library in use.Example.
public function showDialog()
{
// The dialog buttons
$buttons = array(
array(
'title' => 'Close',
'class' => 'btn',
'click' => 'close'
)
);
// The HTML content of the dialog
$content = "This modal dialog depends on application settings!!";
// The dialog specific options
$options = array('width' => 500);
// Show the dialog
$this->response->dialog->show("Modal Dialog", $content, $buttons, $options);
return $this->response;
}
This plugin provides functions to show 4 different types of alerts or notification messages.
/
* Print a success message.
*/
public function success($message, $title = null);
/
* Print an information message.
*/
public function info($message, $title = null);
/
* Print a warning message.
*/
public function warning($message, $title = null);
/
* Print an error message.
*/
public function error($message, $title = null);
Example.
public function save($formValues)
{
if(!$this->validator->valid($formValues))
{
$this->response->dialog->error("Invalid input", "Error");
return $this->response;
}
$this->repository->save($formValues);
$this->response->dialog->success("Data saved!", "Success");
return $this->response;
}
The confirm()
function adds a confirmation question to a Jaxon request, which will then be called only if the user answers yes to the given question.
/
* Add a confirmation question to the request
*/
public function confirm($question, ...);
The first parameter, which is mandatory, is the question to ask.
The next parameters are optional; they allow the insertion of content from the web page in the confirmation question, using Jaxon or jQuery selectors and positional placeholders. They are specially useful when pieces of information from the web page need to be inserted in translated strings.
In the example below, the user has to choose a color, and the selected color is inserted in the confirmation question.
Example with Jaxon selector.
<select class="form-control" id="colorselect" name="colorselect" onchange="<?php
echo rq()->call('HelloWorld.setColor', rq()->select('colorselect'))
->confirm('Set color to {1}?', rq()->select('colorselect')) ?>; return false;">
<option value="black" selected="selected">Black</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
Example with jQuery selector.
<select class="form-control" id="colorselect" name="colorselect" onchange="<?php
echo rq()->call('HelloWorld.setColor', jq('#colorselect')->val())
->confirm('Set color to {1}?', jq('#colorselect')->val()) ?>; return false;">
<option value="black" selected="selected">Black</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
This package currently supports 16 javascript libraries, each implementing one or more interfaces.
Bootstrap Dialog: https://nakupanda.github.io/bootstrap3-dialog
Bootbox: http://bootboxjs.com
jAlert: http://flwebsites.biz/jAlert/
PgwJS: http://pgwjs.com/pgwmodal/
Toastr: https://codeseven.github.io/toastr/
Tingle: http://robinparisi.github.io/tingle/
Simply Toast: https://github.com/ericprieto/simply-toast
Noty: http://ned.im/noty/
Notify: https://notifyjs.com
Lobibox: http://lobianijs.com/site/lobibox
Overhang: http://paulkr.github.io/overhang.js/ (requires jQuery and jQuery UI)
PNotify: http://sciactive.com/pnotify/ (requires jQuery and jQuery UI)
Sweet Alert: http://t4t5.github.io/sweetalert/
JQuery-Confirm: https://craftpip.github.io/jquery-confirm/
IziToast: http://izitoast.marcelodolce.com
YmzBox: https://github.com/returnphp/ymzbox
In order to add a new javascript library to the Dialogs plugin, a new class needs to be defined and registered.
The class must inherit from Jaxon\Dialogs\Libraries\Library
, and implement a few functions and interfaces.
Starting from release 1.1.0
, its constructor takes the default subdir and version number as parameters.
These optional functions can be defined in the class.
/
* Get the javascript header code and file includes
*
* @return string
*/
public function getJs(){}
/
* Get the CSS header code and file includes
*
* @return string
*/
public function getCss(){}
/
* Get the javascript code to be printed into the page
*
* @return string
*/
public function getScript(){}
The getJs()
and getCss()
methods return the HTML header code for loading javascript and CSS files of the library.
The getScript()
method returns the javascript code to be executed after the page is loaded to initialize the library.
Depending on the javascript library features, the class must implement one or more of the following three interfaces.
namespace Jaxon\Dialogs\Interfaces;
Interface Modal
{
/
* Show a modal dialog.
*/
public function show($title, $content, array $buttons, array $options = array());
/
* Hide the modal dialog.
*/
public function hide();
}
namespace Jaxon\Request\Interfaces;
Interface Alert
{
/
* Print a success message.
*/
public function success($message, $title = null);
/
* Print an information message.
*/
public function info($message, $title = null);
/
* Print a warning message.
*/
public function warning($message, $title = null);
/
* Print an error message.
*/
public function error($message, $title = null);
}
namespace Jaxon\Request\Interfaces;
interface Confirm
{
/
* Return a script which makes a call only if the user answers yes to the given question
*/
public function confirm($question, $yesScript, $noScript);
}
The getOption($sName)
method provided by the Jaxon\Dialogs\Libraries\Library
class returns the value of a config option of the library.
The parameter $sName
is the name of the option without the dialogs.<library_name>
prefix.
In the example below, a call to $this->getOption('options.position')
will return the value center
.
After it is defined, the library class needs to be configured and registered before it can be used in the application.
First, declare the class in the Dialogs plugin configuration.
'dialogs' => array(
'default' => array(
'modal' => 'myplugin', // Default library for modal dialogs
'alert' => 'myplugin', // Default library for alerts
'confirm' => 'myplugin', // Default library for confirmation
),
'classes' => array(
'myplugin' => \Path\To\My\Plugin::class,
),
'myplugin' => array( // Plugin config options
'options' => array(
'position' => 'center',
),
),
),
If you are not using Armada or a framework integration package, make sure to register the classes, after the configuration options are set.
$jaxon->plugin('dialog')->registerClasses();
The package is licensed under the BSD license.
Files |
File | Role | Description | ||
---|---|---|---|---|
src (2 files, 2 directories) | ||||
templates (16 directories) | ||||
.styleci.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Interfaces (2 files) | ||||
Libraries (1 file, 16 directories) | ||||
Dialog.php | Class | Class source | ||
start.php | Example | Example script |
Files | / | src | / | Interfaces |
File | Role | Description |
---|---|---|
Modal.php | Class | Class source |
Plugin.php | Class | Class source |
Files | / | src | / | Libraries |
File | Role | Description | ||
---|---|---|---|---|
Bootbox (1 file) | ||||
Bootstrap (1 file) | ||||
Izi (2 files) | ||||
JAlert (1 file) | ||||
JQueryConfirm (1 file) | ||||
Lobibox (1 file) | ||||
Notify (1 file) | ||||
Noty (1 file) | ||||
Overhang (1 file) | ||||
PgwJS (1 file) | ||||
PNotify (1 file) | ||||
SimplyToast (1 file) | ||||
SweetAlert (1 file) | ||||
Tingle (1 file) | ||||
Toastr (1 file) | ||||
YmzBox (1 file) | ||||
Library.php | Class | Class source |
Files | / | templates |
Files | / | templates | / | bootbox |
File | Role | Description |
---|---|---|
alert.js | Data | Auxiliary data |
dialog.html | Doc. | Documentation |
Files | / | templates | / | pgwjs |
File | Role | Description |
---|---|---|
alert.js | Data | Auxiliary data |
dialog.html | Doc. | Documentation |
jaxon-dialogs-2018-02-28.zip 45KB | |
jaxon-dialogs-2018-02-28.tar.gz 18KB | |
Install with Composer |
Needed packages | ||
Class | Download | Why it is needed | Dependency |
---|---|---|---|
Jaxon | .zip .tar.gz | Uses the provided features | Required |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.