Skip to content

Instantly share code, notes, and snippets.

@metalagman
Created November 26, 2015 10:13
Show Gist options
  • Save metalagman/f0a891782010d4a4649d to your computer and use it in GitHub Desktop.
Save metalagman/f0a891782010d4a4649d to your computer and use it in GitHub Desktop.
<?php
/**
* @author Alexey Samoylov <alexey.samoylov@gmail.com>
*/
use yii\web\JsExpression;
use yii\helpers\Url;
use yii\helpers\Html;
Url::remember();
$this->title = 'Иерархия';
$this->params['breadcrumbs'][] = ['label' => 'Роли', 'url' => '/rbac'];
$this->params['breadcrumbs'][] = $this->title;
?>
<script>
var getMenu = function (node) {
console.log(node);
var items = {
aclRole: {
label: "Права доступа",
action: function(obj) {
window.location.href = '<?= Url::to(['role/acl']) ?>' + '?name=' + node.li_attr.name
},
icon: "fa fa-cog"
},
deleteRole: {
label: "Удалить роль",
action: function(obj) {
if (confirm('Удалить роль "'+node.li_attr.name+'"?'))
window.location.href = '<?= Url::to(['role/delete']) ?>' + '?name=' + node.li_attr.name
},
icon: "fa fa-trash"
}
}
return items;
}
</script>
<div class="row">
<div class="col-md-6">
<h4><?= \yii\helpers\Html::encode($this->title) ?></h4>
<div class="well">
<?= \yiidreamteam\jstree\JsTree::widget([
'containerOptions' => [
'class' => 'data-tree',
],
'jsOptions' => [
'core' => [
'multiple' => false,
'data' => [
'url' => \yii\helpers\Url::to(['role-tree']),
],
],
'types' => [
'role' => [
'icon' => 'fa fa-user',
],
],
'contextmenu' => [
'items' => new JsExpression('getMenu'),
],
'plugins' => [
'types',
'contextmenu',
],
]
]) ?>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="with-children"> учитывать дочерние роли
</label>
</div>
</div>
<div class="col-md-6">
<div id="ajax-info"></div>
</div>
</div>
<?php
$js = <<<JS
var currentRole;
$(".data-tree").bind("select_node.jstree", function (e, data) {
currentRole = data.node.li_attr.name;
refreshInfo();
});
$("#with-children").click(function() {
refreshInfo();
})
var refreshInfo = function() {
if (!currentRole)
return;
var url = "ajax-info?role=" + currentRole;
if ($("#with-children").is(":checked"))
url = url + '&withChildren=1';
$("#ajax-info").load(url);
}
JS;
$this->registerJs($js);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment