2017 © Pedro Peláez
 

yii2-extension yii2-ajaxy

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

image

nozzha/yii2-ajaxy

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

  • Saturday, May 2, 2015
  • by EmadOmar
  • Repository
  • 3 Watchers
  • 3 Stars
  • 21 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 5 % Grown

The README.md

Nozzha Ajaxy 2.0: Actions Dialog via Ajax for Yii 2

Nozzha Ajaxy is a Yii 2.0 extension that provides a simple API to show an action via a dialog box in the page using the Bootstrap plugin Bootbox., (*1)

Ajaxy was designed to display either a create or an update actions dialog box. In other words, an action that has a single form., (*2)

Note: Ajaxy was not tested with actions that does not have a form like a view or index action., (*3)

For license information check the LICENSE-file., (*4)

Latest Stable Version Total Downloads Latest Unstable Version License, (*5)

Installation

The preferred way to install this extension is through composer., (*6)

Either run, (*7)

php composer.phar require --prefer-dist nozzha/yii2-ajaxy

or add, (*8)

"nozzha/yii2-ajaxy": "~1.0"

to the require section of your composer.json., (*9)

Usage

There are two steps for using Ajaxy, (*10)

1. Handle Ajaxy requests

1.1. Preparing the View

For Ajaxy to display the dialog box of the requested action, it will need to request for the view content first, and to retrieve the view at the proper time and request, (*11)

You'll first use Ajaxy::isAjaxy() to check if this is an Ajaxy request that asks for the view content, and then return the content using Controller::renderAjax()., (*12)

Example:, (*13)

in the controller, (*14)

if (Ajaxy::isAjaxy()) {
    return $this->renderAjax('create', $params);
}

and in the view (in our example create.php) attach Ajaxy to the form using Ajaxy::attachTo($view, $activeForm), (*15)

Note: You should set an id for the form to avoid duplicate ids when requesting the view via Ajax, (*16)

Example:, (*17)

<?php
$form = ActiveForm::begin([
    'enableAjaxValidation' => true, // Is up to you
    'id' => $model->formName(), // You need to set an id for the form
    'action' => ['create'] // Recommended
]);
?>
...
<?php ActiveForm::end(); ?>
<?php Ajaxy::attachTo($this, $form); ?>

1.2. Handle the submitted form and return the response

When the submits the form, Ajaxy will post it via ajax to the specified action, and you may need to handle this request differently to return the proper response., (*18)

Ajaxy provides to methods to do so, Ajaxy::isSubmitted() that checks whether the Ajaxy form has submitted. And Ajaxy::response() that prepares a response for the Ajaxy request., (*19)

Example:, (*20)

if (Ajaxy::isSubmitted()) {
    // Handle model validation create, update or save ...
    return Ajaxy::response($status, $data);
}

And now the action is ready to provide it's view and to handle the submitted form., (*21)

2. Display the Dialog Box

1. Register Ajaxy assets

To link the JavaScript api of Ajaxy register it's asset bundle, (*22)

Ajaxy::registerAssets($view);

2. Show the Dialog

and then in your JavaScript code call $ajaxy.showModalForm(options) to show a dialog box of a view that you want to display, (*23)

Example:, (*24)

$ajaxy.showModalForm({
    url: 'http://example.com/controller/action',
    data: {
        User: { displayName: 'User Name' }
    },
    onResult: function (result) {
        console.log(result.data);
        // console.log("Created User #" + result.data.ID); // Example
    }
});

The Versions

02/05 2015

dev-master

9999999-dev

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

  Sources   Download

MIT

The Requires

 

by Emad Omar

yii2 form extension ajax-form ajaxy form-dialog

02/05 2015

v2.0

2.0.0.0

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

  Sources   Download

MIT

The Requires

 

by Emad Omar

yii2 form extension ajax-form ajaxy form-dialog

02/05 2015

dev-develop

dev-develop

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

  Sources   Download

MIT

The Requires

 

by Emad Omar

yii2 form extension ajax-form ajaxy form-dialog

02/05 2015

dev-improve-documentation

dev-improve-documentation

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

  Sources   Download

MIT

The Requires

 

by Emad Omar

yii2 form extension ajax-form ajaxy form-dialog

28/04 2015

v1.0

1.0.0.0

Nozzha Ajaxy - Actions Dialog via Ajax extension for Yii 2

  Sources   Download

MIT

The Requires

 

by Emad Omar

yii2 form extension ajax-form ajaxy form-dialog

26/04 2015

0.2-alpha

0.2.0.0-alpha

Yii2 - Nozzha Ajaxy

  Sources   Download

MIT

The Requires

 

by Nozzha

yii2 extension

12/02 2015

0.1-alpha

0.1.0.0-alpha

Yii2 - Nozzha Ajaxy

  Sources   Download

MIT

The Requires

 

by Nozzha

yii2 extension