mickgeek/yii2-actionbar Customizable bar with the drop-down list for manipulation selected GridView items and control buttons.

extensionwidgetdropdowngridbulkactions

Action Bar

Action Bar is a Yii 2 widget that render the drop-down list for manipulation selected GridView items and control buttons. The widget permits you to fully customize elements.

Screenshot

Installation

You can install the widget in two ways, using Composer or by downloading an archive file.

Installing via Composer

Run the following commands under your application folder:

php composer.phar require --prefer-dist "mickgeek/yii2-actionbar *"

Note: You can just do composer update --prefer-dist if pre-adding the following to require section of your composer.json:

"mickgeek/yii2-actionbar": "*"

Installing from an Archive File

Download the archive file, unpack it to path/to/app/vendor/mickgeek folder and modify the main configuration file like this:

$vendorDir = dirname(__DIR__) . '/vendor';

return [
    'vendorPath' => $vendorDir,
    'extensions' => array_merge(
        require($vendorDir . '/yiisoft/extensions.php'),
        [
            'mickgeek/yii2-actionbar' => [
                'name' => 'mickgeek/yii2-actionbar',
                'version' => '9999999-dev',
                'alias' => [
                    '@mickgeek/actionbar' => $vendorDir . '/mickgeek/yii2-actionbar',
                ],
            ],
        ]
    ),
    ...
];

where $vendorDir is the path to the directory that stores vendor files.

Usage

use mickgeek\actionbar\Widget as ActionBar;

<?= ActionBar::widget([
    'grid' => 'user-grid',
]) ?>

But first, add the action to your controller:

public function actions()
{
    return [
        'delete-multiple' => [
            'class' => 'mickgeek\actionbar\DeleteMultipleAction',
            'modelClass' => 'app\models\User',
        ],
    ];
}

Note: You can write your action without using DeleteMultipleAction class.

Tip: For information about properties and methods of the widget, see the bundled DOCUMENTATION.md.

CSRF validation

For enable CSRF validation make sure you have <?= Html::csrfMetaTags() ?> in main layout.

Examples

Below are two examples showing some features of the widget.

Advanced Bulk Actions

Advanced Bulk Actions Screenshot

The code in the view:

use yii\helpers\Url;
use mickgeek\actionbar\Widget as ActionBar;

<?= ActionBar::widget([
    'grid' => 'user-grid',
    'templates' => [
        '{bulk-actions}' => ['class' => 'col-xs-4'],
        '{create}' => ['class' => 'col-xs-8 text-right'],
    ],
    'bulkActionsItems' => [
        'Update Status' => [
            'status-active' => 'Active',
            'status-blocked' => 'Blocked',
        ],
        'General' => ['general-delete' => 'Delete'],
    ],
    'bulkActionsOptions' => [
        'options' => [
            'status-active' => [
                'url' => Url::toRoute(['update-status', 'status' => 'active']),
                'disabled' => !Yii::$app->user->can('updateUserStatus'),
            ],
            'status-blocked' => [
                'url' => Url::toRoute(['update-status', 'status' => 'blocked']),
                'disabled' => !Yii::$app->user->can('updateUserStatus'),
            ],
            'general-delete' => [
                'url' => Url::toRoute('delete-multiple'),
                'data-confirm' => 'Are you sure?',
                'disabled' => !Yii::$app->user->can('deleteUser'),
            ],
        ],
        'class' => 'form-control',
    ],
]) ?>

The code in the User controller:

public function actions()
{
    return [
        'delete-multiple' => [
            'class' => 'mickgeek\actionbar\DeleteMultipleAction',
            'modelClass' => 'app\models\User',
            'beforeDeleteCallback' => function ($action) {
                if (!Yii::$app->user->can('deleteOwnAccount', Yii::$app->getRequest()->post('ids'))) {
                    Yii::$app->getSession()->setFlash('error', 'You cannot delete your own account.');

                    $action->redirect();
                    Yii::$app->end();
                }
            },
            'afterDeleteCallback' => function ($action) {
                Yii::$app->getSession()->setFlash('success', 'The selected users have been deleted successfully.');
            },
        ],
    ];
}

public function actionUpdateStatus($status)
{
    ...
}

Custom Buttons

Custom Buttons Screenshot

The code:

use mickgeek\actionbar\Widget as ActionBar;

/* @var $model app\models\User */
<?= ActionBar::widget([
    'templates' => [
        '{back}' => ['class' => 'col-xs-4'],
        '{update} {delete}' => ['class' => 'col-xs-8 text-right'],
    ],
    'elements' => [
        'back' => Html::a(
            '<span class="glyphicon glyphicon-chevron-left"></span> ' . 'Back',
            ['/users/index'],
            ['class' => 'btn btn-default']
        ),
        'update' => Html::a(
            '<span class="glyphicon glyphicon-pencil"></span> ' . 'Update',
            ['/users/update', 'id' => $model->id],
            ['class' => 'btn btn-default']
        ),
        'delete' => Html::a(
            '<span class="glyphicon glyphicon-trash"></span> ' . 'Delete',
            ['/users/delete', 'id' => $model->id],
            ['class' => 'btn btn-default']
        ),
    ],
]) ?>

License

This extension is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

Changelog

Action Bar Changelog

Version 1.0.0 July 15, 2014

  • Initial release

Version 1.1.0 December 09, 2016

  • Request parameter "ids" change support

Version 1.1.1 March 10, 2017

  • Added CSRF notice in documentaion

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.1.1 is the latest of 2 releases



BSD 3-Clause license
Stats
15 github stars & 7 github forks
2 downloads in the last day
294 downloads in the last 30 days
7356 total downloads