dev-master
9999999-devDisplay your admin actions in bootstrap modals with frames and callbacks
GPL-3.0
The Requires
extension yii2
Wallogit.com
2017 © Pedro Peláez
Display your admin actions in bootstrap modals with frames and callbacks
Display your admin actions in bootstrap modals with frames and callbacks., (*1)
Current status: Work in progress., (*2)
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist devgroup/yii2-admin-modals "*"
or add, (*5)
"devgroup/yii2-admin-modals": "*"
to the require section of your composer.json file., (*6)
Add DevGroup\AdminModals\components\AdminModals component with component id adminModals., (*7)
Modify your main web application config:, (*8)
return [
// your app config here
// ...
'components' => [
'adminModals' => [
'class' => 'DevGroup\AdminModals\components\AdminModals',
'layoutFile' => '@app/actions/views/empty-layout',
],
// your other app components
],
];
AdminModals components has the following params:, (*9)
admin-modals actionAdmin-modals action is used for displaying simple empty page inside modal's frame during loading the needed route., (*10)
You can show loader spinner there., (*11)
By default JS part of yii2-admin-modals will load '/site/admin-modal'. That could be configured later., (*12)
For adding action modify your Controller actions() function:, (*13)
public function actions()
{
return [
// other actions here...
'admin-modal' => [
'class' => DevGroup\AdminModals\actions\EmptyPageAction::class,
'viewFile' => '@DevGroup/AdminModals/views/admin-modal',
'layoutFile' => '@app/actions/views/empty-layout',
]
];
}
EmptyPageAction takes the following params:, (*14)
AdminModalsBehavior but is not required. If not set - the default controller layout will be used.admin-modal__frame-form class that would be used for loading actions with POST method.At first you need to add dependency to DevGroup\AdminModals\assets\AdminModalsBundle in you main application AssetBundle:, (*15)
class AppAsset extends AssetBundle { // your stuff here public $depends = [ // add dependency DevGroup\AdminModals\assets\AdminModalsBundle::class, ]; }
If you need to configure JS-part of yii2-admin-modals - add javascript object before AdminModalsBundle loads(for example after opening body tag):, (*16)
window.AdminModalsSettings = {
modalActionSelector: '.admin-modal-trigger',
dataAttribute: 'adminModals',
adminModalPageUrl: '/site/admin-modal',
adminModalFrameFormSelector: '.admin-modal__frame-form',
magicParamKey: '__admin_modals',
adminModalsUniqueParamKey: '__admin-modals__unique-id'
}
All links and buttons with admin-modal-trigger class assigned will automatically call opening modal windows instead of direct action performing., (*17)
Example code:, (*18)
<a href="/admin/user/edit?id=1" class="btn btn-primary modal-test admin-modal-trigger">
Open user #1 edit form in modal!
</a>
An example for showing confirmation on deletion of jstree node:, (*19)
function confirmDelete(node) {
AdminModals.modalOpen({
url: '/category/delete',
data: {
id: $(node.reference[0]).data('id')
},
method: 'GET',
closeCallback: function() {
alert('Thank you!');
}
});
return false;
}
That will display /category/delete?id=### in modal., (*20)
A helper for jstree DevGroup\AdminModals\helpers\JsTreeHelper has the following static functions:, (*21)
Display your admin actions in bootstrap modals with frames and callbacks
GPL-3.0
extension yii2