2016-10-26 14:02:40 +08:00
|
|
|
|
$(function () {
|
2016-11-18 20:49:44 +08:00
|
|
|
|
var $dialog = $('#dialogNew');
|
|
|
|
|
var $pickIcon = $('#pickIcon');
|
|
|
|
|
var $iconList = $('#iconTab').find('div.fontawesome-icon-list');
|
|
|
|
|
var $dialogNew = $dialog.find('div.modal-dialog');
|
|
|
|
|
var $dialogIcon = $('#dialogIcon');
|
|
|
|
|
var $dialogMenu = $('#dialogSubMenu').find('.modal-content');
|
|
|
|
|
var $dialogRole = $('#dialogRole');
|
|
|
|
|
var $dialogRoleHeader = $('#myRoleModalLabel');
|
|
|
|
|
var $dialogRoleForm = $('#roleForm');
|
|
|
|
|
var $btnSubmitMenu = $('#btnSubmitMenu');
|
|
|
|
|
var $btnPickIcon = $('#btnIcon');
|
|
|
|
|
var $inputIcon = $('#icon');
|
|
|
|
|
var $nestMenu = $('#nestable_menu');
|
|
|
|
|
var $nestMenuInput = $nestMenu.find('div.dd3-content');
|
|
|
|
|
var $parentMenuID = $('#parentId');
|
|
|
|
|
var $parentMenuName = $('#parentName');
|
|
|
|
|
$nestMenuInput.find('label:first').hide();
|
|
|
|
|
|
2016-10-26 14:02:40 +08:00
|
|
|
|
var bsa = new BootstrapAdmin({
|
|
|
|
|
url: '../api/Menus',
|
|
|
|
|
dataEntity: new DataEntity({
|
|
|
|
|
map: {
|
|
|
|
|
ID: "menuID",
|
|
|
|
|
ParentId: "parentId",
|
2016-11-15 11:03:07 +08:00
|
|
|
|
ParentName: "parentName",
|
2016-10-26 14:02:40 +08:00
|
|
|
|
Name: "name",
|
|
|
|
|
Order: "order",
|
|
|
|
|
Icon: "icon",
|
|
|
|
|
Url: "url",
|
2016-11-24 20:58:47 +08:00
|
|
|
|
Category: "category",
|
|
|
|
|
Target: "target"
|
2016-10-26 14:02:40 +08:00
|
|
|
|
}
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}),
|
|
|
|
|
click: {
|
|
|
|
|
assign: [{
|
|
|
|
|
id: 'btn_assignRole',
|
|
|
|
|
click: function (row) {
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$.bc({
|
|
|
|
|
Id: row.ID, url: Role.url, data: { type: "menu" }, swal: false,
|
|
|
|
|
callback: function (result) {
|
|
|
|
|
var htmlTemplate = this.htmlTemplate;
|
|
|
|
|
var html = $.map(result, function (element, index) {
|
|
|
|
|
return $.format(htmlTemplate, element.ID, element.RoleName, element.Checked, element.Description);
|
|
|
|
|
}).join('')
|
|
|
|
|
$dialogRoleHeader.text($.format('{0}-角色授权窗口', row.Name));
|
|
|
|
|
$dialogRoleForm.html(html);
|
|
|
|
|
$dialogRole.modal('show');
|
|
|
|
|
}
|
2016-10-28 11:12:25 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2016-10-31 11:13:46 +08:00
|
|
|
|
id: 'btnSubmitRole',
|
2016-10-28 11:12:25 +08:00
|
|
|
|
click: function (row) {
|
|
|
|
|
var menuId = row.ID;
|
2016-11-18 20:49:44 +08:00
|
|
|
|
var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
|
2016-10-28 11:12:25 +08:00
|
|
|
|
return $(element).val();
|
|
|
|
|
}).toArray().join(',');
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$.bc({ Id: menuId, url: Role.url, method: "PUT", data: { type: "menu", roleIds: roleIds }, title: Role.title, modal: 'dialogRole' });
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}
|
|
|
|
|
}]
|
2016-11-15 14:31:53 +08:00
|
|
|
|
},
|
|
|
|
|
callback: function (result) {
|
|
|
|
|
if (!result.success) return;
|
|
|
|
|
if ((result.oper == "save") || result.oper == "del") {
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$.bc({
|
|
|
|
|
Id: 0, url: Menu.url, data: { type: "user" }, swal: false,
|
|
|
|
|
callback: function (result) {
|
|
|
|
|
var html = "";
|
|
|
|
|
if ($.isArray(result)) html = cascadeMenu(result);
|
|
|
|
|
$nestMenu.find('ol:first').html(html);
|
|
|
|
|
$nestMenuInput = $nestMenu.find('div.dd3-content');
|
|
|
|
|
$nestMenuInput.find('label:first').hide();
|
|
|
|
|
}
|
2016-11-15 14:31:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}
|
2016-10-26 14:02:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-18 20:49:44 +08:00
|
|
|
|
var cascadeMenu = function (menus) {
|
|
|
|
|
var html = "";
|
|
|
|
|
$.each(menus, function (index, menu) {
|
|
|
|
|
if (menu.Menus.length == 0) {
|
|
|
|
|
html += $.format('<li class="dd-item dd3-item" data-id="{0}" data-category="{3}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><input type="checkbox" value="{0}"><span><i class="{1}"></i>{2}</span></label><label><input type="radio" name="menu" value="{0}"><span><i class="{1}"></i>{2}</span></label></div></li>', menu.ID, menu.Icon, menu.Name, menu.Category);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2016-11-23 13:31:03 +08:00
|
|
|
|
html += $.format('<li class="dd-item dd3-item" data-id="{0}" data-category="{3}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><input type="checkbox" value="{0}"><span><i class="{1}"></i>{2}</span></label><label><input type="radio" name="menu" value="{0}"><span><i class="{1}"></i>{2}</span></label></div></li><ol class="dd-list">{4}</ol>', menu.ID, menu.Icon, menu.Name, menu.Category, cascadeSubMenu(menu.Menus));
|
2016-11-18 20:49:44 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return html;
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-23 13:31:03 +08:00
|
|
|
|
var cascadeSubMenu = function (menus) {
|
|
|
|
|
var html = ""
|
|
|
|
|
$.each(menus, function (index, menu) {
|
|
|
|
|
html += $.format('<li class="dd-item dd3-item" data-id="{0}" data-category="{3}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><input type="checkbox" value="{0}"><span><i class="{1}"></i>{2}</span></label><label><input type="radio" name="menu" value="{0}"><span><i class="{1}"></i>{2}</span></label></div></li>', menu.ID, menu.Icon, menu.Name, menu.Category);
|
|
|
|
|
});
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 14:02:40 +08:00
|
|
|
|
$('table').smartTable({
|
2016-11-18 20:49:44 +08:00
|
|
|
|
url: Menu.url, //请求后台的URL(*)
|
2016-11-06 00:48:08 +08:00
|
|
|
|
sortName: 'Order',
|
2016-11-08 11:08:10 +08:00
|
|
|
|
queryParams: function (params) { return $.extend(params, { parentName: $('#txt_parent_menus_name').val(), name: $("#txt_menus_name").val(), category: $('#sel_menus_category').val() }); }, //传递参数(*)
|
2016-10-26 14:02:40 +08:00
|
|
|
|
columns: [{ checkbox: true },
|
|
|
|
|
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
|
2016-11-06 00:48:08 +08:00
|
|
|
|
{ title: "父级菜单", field: "ParentName", sortable: true },
|
2016-10-26 14:02:40 +08:00
|
|
|
|
{ title: "菜单名称", field: "Name", sortable: true },
|
2016-11-03 21:29:32 +08:00
|
|
|
|
{ title: "菜单序号", field: "Order", sortable: true },
|
2016-10-26 14:02:40 +08:00
|
|
|
|
{ title: "菜单图标", field: "Icon", sortable: false },
|
|
|
|
|
{ title: "菜单路径", field: "Url", sortable: false },
|
2016-11-24 20:58:47 +08:00
|
|
|
|
{ title: "菜单类别", field: "CategoryName", sortable: true },
|
|
|
|
|
{
|
|
|
|
|
title: "目标", field: "Target", sortable: true, formatter: function (value, row, index) {
|
|
|
|
|
var ret = value;
|
|
|
|
|
switch (value) {
|
|
|
|
|
case "_self":
|
|
|
|
|
ret = "本窗口";
|
|
|
|
|
break;
|
|
|
|
|
case "_blank":
|
|
|
|
|
ret = "新窗口";
|
|
|
|
|
break;
|
|
|
|
|
case "_parent":
|
|
|
|
|
ret = "父级窗口";
|
|
|
|
|
break;
|
|
|
|
|
case "_top":
|
|
|
|
|
ret = "顶级窗口";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-26 14:02:40 +08:00
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
$('#dataForm').autoValidate({
|
|
|
|
|
name: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
},
|
2016-11-03 11:19:40 +08:00
|
|
|
|
order: {
|
|
|
|
|
digits: true
|
|
|
|
|
},
|
2016-10-26 14:02:40 +08:00
|
|
|
|
url: {
|
2016-11-23 18:26:22 +08:00
|
|
|
|
required: true
|
2016-10-26 14:02:40 +08:00
|
|
|
|
},
|
|
|
|
|
category: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-28 01:39:24 +08:00
|
|
|
|
|
2016-11-21 00:33:07 +08:00
|
|
|
|
$iconList.find('ul li').addClass('col-md-3 col-sm-4 col-xs-6');
|
|
|
|
|
$iconList.find('div').addClass('col-xs-6');
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$iconList.on('click', 'div.fa-hover a, ul li', function () {
|
|
|
|
|
$pickIcon.attr('class', $(this).find('i, span:first').attr('class'));
|
2016-10-28 01:39:24 +08:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$btnPickIcon.on('click', function () {
|
|
|
|
|
$dialogIcon.show();
|
2016-10-28 01:39:24 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$dialogIcon.find('div.modal-header, div.modal-footer').on('click', 'button', function () {
|
|
|
|
|
$dialogIcon.hide();
|
2016-10-28 01:39:24 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$dialogIcon.find('div.modal-footer').on('click', 'button:last', function () {
|
|
|
|
|
var icon = $pickIcon.attr('class');
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('#icon').val(icon);
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$('#btnIcon').find('i').attr('class', icon);
|
2016-10-28 01:39:24 +08:00
|
|
|
|
});
|
2016-11-03 11:19:40 +08:00
|
|
|
|
|
2016-11-03 16:28:05 +08:00
|
|
|
|
// 排序按钮
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$('#btnMenuOrder').on('click', function () {
|
|
|
|
|
$dialogNew.hide();
|
|
|
|
|
$btnSubmitMenu.data('type', 'order');
|
2016-11-14 22:12:23 +08:00
|
|
|
|
$nestMenuInput.find('label:last').find('input').hide();
|
|
|
|
|
$nestMenu.find('li.dd-item').hide().remove('[data-id="0"]');
|
|
|
|
|
$nestMenu.find('li[data-category="' + $('#category').selectpicker('val') + '"]').show();
|
2016-11-03 16:28:05 +08:00
|
|
|
|
// handler new menu
|
2016-11-14 22:12:23 +08:00
|
|
|
|
var did = $('#menuID').val();
|
|
|
|
|
if (did == "") did = 0;
|
|
|
|
|
if (did == 0) {
|
2016-11-03 16:28:05 +08:00
|
|
|
|
var menuName = $('#name').val();
|
2016-11-14 22:12:23 +08:00
|
|
|
|
var menuCate = $('select').selectpicker('val');
|
2016-11-03 16:28:05 +08:00
|
|
|
|
if (menuName == "") menuName = "新建菜单-未命名";
|
2016-11-14 22:12:23 +08:00
|
|
|
|
$nestMenu.find('ol.dd-list:first').append($.format('<li class="dd-item dd3-item" data-id="0" data-category="{1}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><span>{0}</span></label></div></li>', menuName, menuCate));
|
2016-11-03 16:28:05 +08:00
|
|
|
|
}
|
2016-11-14 23:00:05 +08:00
|
|
|
|
$nestMenu.find('li[data-id="' + did + '"] > div.dd3-content span').addClass('active');
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$dialogMenu.show().adjustDialog();
|
2016-11-03 16:28:05 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 选择父节点按钮
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$('#btnMenuParent').on('click', function () {
|
|
|
|
|
$dialogNew.hide();
|
|
|
|
|
$btnSubmitMenu.data('type', 'parent');
|
2016-11-14 22:12:23 +08:00
|
|
|
|
$nestMenuInput.find('label:last').find('input').show();
|
|
|
|
|
$nestMenu.find('li.dd-item').hide().remove('[data-id="0"]');
|
|
|
|
|
$nestMenu.find('li[data-category="' + $('#category').selectpicker('val') + '"]').show();
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$dialogMenu.show().adjustDialog();
|
2016-11-03 11:19:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$dialogMenu.find('div.modal-header, div.modal-footer').on('click', 'button', function () {
|
2016-11-03 16:28:05 +08:00
|
|
|
|
// remove active css
|
2016-11-14 22:12:23 +08:00
|
|
|
|
$nestMenu.find('li span').removeClass('active');
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$dialogMenu.hide();
|
|
|
|
|
$dialogNew.show();
|
2016-11-03 11:19:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-24 20:58:47 +08:00
|
|
|
|
$('#btnClearIcon, #btnMenuClearParent').on('click', function () {
|
|
|
|
|
$(this).parent().prev().val("");
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 19:30:30 +08:00
|
|
|
|
$btnSubmitMenu.on('click', function () {
|
|
|
|
|
var type = $(this).data('type');
|
2016-11-03 16:28:05 +08:00
|
|
|
|
switch (type) {
|
|
|
|
|
case "parent":
|
2016-11-15 12:15:12 +08:00
|
|
|
|
$('#parentId').val($('.dd3-content :radio:checked').val());
|
|
|
|
|
$('#parentName').val($('.dd3-content :radio:checked').next('span').text());
|
2016-11-03 16:28:05 +08:00
|
|
|
|
break;
|
|
|
|
|
case "order":
|
|
|
|
|
var data = $('#nestable_menu').nestable('serialize');
|
|
|
|
|
var mid = $('#menuID').val();
|
|
|
|
|
for (index in data) {
|
|
|
|
|
if (data[index].id == mid || data[index] == 0) {
|
|
|
|
|
$('#order').val(10 + index * 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-11-03 11:19:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 19:30:30 +08:00
|
|
|
|
// Dialog shown event
|
|
|
|
|
$dialog.on('show.bs.modal', function () {
|
|
|
|
|
var icon = $inputIcon.val();
|
|
|
|
|
if (icon == "") icon = "fa fa-dashboard";
|
|
|
|
|
$btnPickIcon.find('i').attr('class', icon);
|
|
|
|
|
});
|
2016-11-14 22:12:23 +08:00
|
|
|
|
$nestMenu.nestable();
|
2016-11-08 11:17:36 +08:00
|
|
|
|
// select
|
|
|
|
|
$('select').selectpicker();
|
2016-10-25 18:54:20 +08:00
|
|
|
|
});
|