uhi67/umenu

Universal menu for Yii2

Installs: 201

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

1.1.4 2021-06-18 09:44 UTC

This package is auto-updated.

Last update: 2024-04-18 15:48:50 UTC


README

Universal menu for Yii2 With footer form support in gridview

Version 1.1.4 -- 2021-06-18

Installation

The preferred way to install this extension is through composer.

To install, either run

composer require uhi67/umenu "*" 

or add

"uhi67/umenu" : "*"

or clone form github

git clone https://github.com/uhi67/umenu

Usage

Title menu

In controller action, use

return [
    'model' => $this->findModel($id),
    'mode' => $editmode ? 'edit' : 'view',
	'titleMenuItems' => [
		[
			'visible' => $editmode, 
			'enabled' => Yii::$app->user->can('/contract/update'), 
			'title' => Yii::t('app', 'Save details data'), 
			'icon' => 'glyphicon-ok', 
			'action' => "javascript:$(this).closest('div.block').find('form').get(0).submit();",
		],
		[
			'enabled' => Yii::$app->user->can('/contract/update'), 
			//'caption'=>'Edit', 
			'title' => Yii::t('app', 'Edit contract details'), 
			'icon' => $editmode ? 'glyphicon-remove' : 'glyphicon-pencil', 
			'action' => $editmode ? '/contract/view/'.$id : '/contract/edit/'.$id,
		],
		[
			'enabled' => Yii::$app->user->can('/contract/delete'), 
			//'caption'=>'Delete', 
			'title' => Yii::t('app', 'Delete contract'), 
			'icon'=>'glyphicon-trash', 
			'action'=>'/contract/delete/'.$id, 
			'confirm' => Yii::t('app', 'This will delete the contract. Ary you sure?')
		],
		[
			'title' => 'Lista',
			'icon' => 'glyphicon-list',
			'action' => '/contract',
		],
	],
];

In your view use

uhi67\umenu\UMenuAsset::register($this); // or put this into the global layout 
UMenu::showMenu($titleMenuItems, 'title-menu');

See UMenu::showMenu for detailed menu properties.

Context menu and footer form functions in GridView

Context menu is a menu associated to a gridview or any similar list object. Context menu may cointain group items, which are visible only if one or more ites are selected in the associated gridview. GridView association is automatic if you put the menu in the same form with gridView.

Footer form is a hidden form in the footer row of a gridView object. A context menu button shows the form. The form contains a close button which hides it again. Actions with hidden footer-form do not send footer-form fields (and nor validation is performed as well).

In your controller class use

	// action on selection
	$selection = Yii::$app->request->post('selection');		

	// list action
	return [
		...
		'$contextMenuItems' => [
			[
				'enabled' => $can_grant, 
				'caption' => Yii::t('app', 'Add'),
				'icon' => 'glyphicon-plus', 
				'class' => 'footer-form-show', 		// no action needed: button will show the footer form
				'title' => '...',
				'badge' => '3',                     // notification about new items under this menu
				'items' => []                       // drop-down subitems 
			],
			[
				'enabled'=>$can_grant, 
				'caption' => Yii::t('app', 'Delete'), 
				'icon'=>'glyphicon-trash',
				'data' => ['action'=>'...'], // Action will get keys of the selected rows (see above)
				'group'=>1, 	// Indicates this button is visible only and operates on selected rows. Uses data-action to send the form to
				'title' => '...',
			],
		],
		'footerForm' => new RoleForm(['userid'=>$this->itemid]),	// Model of footer form data
	];

In your view use

// Wrap into form (even if footer form is not used: use for row selection)
$form = ActiveForm::begin([
	...
    'layout' => 'inline',
    ...
]);

// Indicate using of context-menu and/or footer-form in class 
 <?= GridView::widget([ 
	'options' => ['class'=>'grid context-menu footer-form'],
	'showFooter' => true,
	'footerRowOptions' => ['class'=>'footer-form'],	// must be hidden first
	...
	'columns' => [
		// First column
		[
			'class' => 'yii\grid\CheckboxColumn',
			'footer' => Html::button(Html::tag('span', '', ['class' => 'glyphicon glyphicon-remove footer-form-close'])),
			'visible'=>...,	// If user has permission on any group action
		],
		// Other columns
		[
			...
			'footer'=>$form->field($roleForm, ...) ... 
			
		]
		// Last column
		[
			...
			'footer' => Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-primary']),
		],
	],
	'showOnEmpty' => true,
	'emptyText' => '...',
]);
?>
<?= Html::activeHiddenInput($roleForm, 'userid') ?>
<?= \uhi67\umenu\UMenu::showMenu($contextMenuItems, 'context-menu'); ?>
<?php ActiveForm::end() ?>

Change log

Version 1.1.4 -- 2021-06-18

  • separate linkClass for navItems

Version 1.1.3 -- 2020-05-20

  • using precompiled css
  • bootstrap3 dependency removed
  • detecting new fa~ classes

Version 1.1.2 -- 2019-01-29

  • Added notification badge support for nav export

Version 1.1.1 -- 2019-01-16

  • nav item class
  • nav icon support
  • icon support added

Version 1.1 -- 2019-01-15

  • navItems() method added

Version 1.0.3 -- 2018-11-26

  • php 7.2 compatibility

License

Copyright (c) 2017, Uherkovich Péter
uhisoft.hu
All rights reserved.

"uhi67/umenu" is licensed under GNU General Public License v3 https://www.gnu.org/licenses/gpl-3.0.txt

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. See the bundled LICENSE.md for details.