2016-10-26 14:02:40 +08:00
|
|
|
|
$(function () {
|
|
|
|
|
var bsa = new BootstrapAdmin({
|
|
|
|
|
url: '../api/Menus',
|
|
|
|
|
dataEntity: new DataEntity({
|
|
|
|
|
map: {
|
|
|
|
|
ID: "menuID",
|
|
|
|
|
ParentId: "parentId",
|
|
|
|
|
Name: "name",
|
|
|
|
|
Order: "order",
|
|
|
|
|
Icon: "icon",
|
|
|
|
|
Url: "url",
|
|
|
|
|
Category: "category"
|
|
|
|
|
}
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}),
|
|
|
|
|
click: {
|
|
|
|
|
assign: [{
|
|
|
|
|
id: 'btn_assignRole',
|
|
|
|
|
click: function (row) {
|
2016-10-28 14:45:09 +08:00
|
|
|
|
Role.getRolesByMenuId(row.ID, function (data) {
|
2016-10-28 11:12:25 +08:00
|
|
|
|
$("#dialogRole .modal-title").text($.format('{0}-角色授权窗口', row.Name));
|
|
|
|
|
$('#dialogRole form').html(data);
|
|
|
|
|
$('#dialogRole').modal('show');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
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;
|
|
|
|
|
var roleIds = $('#dialogRole :checked').map(function (index, element) {
|
|
|
|
|
return $(element).val();
|
|
|
|
|
}).toArray().join(',');
|
2016-10-28 21:26:13 +08:00
|
|
|
|
Role.saveRolesByMenuId(menuId, roleIds, { modal: 'dialogRole' });
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
2016-10-26 14:02:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('table').smartTable({
|
|
|
|
|
url: '../api/Menus', //请求后台的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-03 21:29:32 +08:00
|
|
|
|
{ title: "菜单类别", field: "CategoryName", sortable: true }
|
2016-10-26 14:02:40 +08:00
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
$('#dataForm').autoValidate({
|
|
|
|
|
name: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
},
|
|
|
|
|
icon: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
},
|
2016-11-03 11:19:40 +08:00
|
|
|
|
order: {
|
|
|
|
|
required: true,
|
|
|
|
|
digits: true
|
|
|
|
|
},
|
2016-10-26 14:02:40 +08:00
|
|
|
|
url: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
},
|
|
|
|
|
category: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-28 01:39:24 +08:00
|
|
|
|
|
|
|
|
|
$('.fontawesome-icon-list ul li').addClass('col-md-3 col-sm-4 col-sm-6');
|
|
|
|
|
|
|
|
|
|
$('.fontawesome-icon-list .fa-hover a, .fontawesome-icon-list ul li').click(function () {
|
|
|
|
|
$('.icon-content .modal-footer i').attr('class', $(this).children('i, span:first').attr('class'));
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('#btnIcon').click(function () {
|
2016-10-28 01:39:24 +08:00
|
|
|
|
$('.icon-content').show();
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('.icon-content button').click(function () {
|
2016-10-28 01:39:24 +08:00
|
|
|
|
$('.icon-content').hide();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.icon-content button:last').click(function () {
|
|
|
|
|
var icon = $('.icon-content .modal-footer i').attr('class');
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('#icon').val(icon);
|
|
|
|
|
$('#btnIcon 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
|
|
|
|
// 排序按钮
|
|
|
|
|
$('#btnMenuOrder').click(function () {
|
|
|
|
|
$('li.dd-item').remove('[data-id="0"]');
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('#dialogNew div.modal-dialog').hide();
|
2016-11-03 16:28:05 +08:00
|
|
|
|
$('.menu-content button:last').data('type', 'order');
|
|
|
|
|
// handler new menu
|
|
|
|
|
if ($('#menuID').val() == "") {
|
|
|
|
|
var menuName = $('#name').val();
|
|
|
|
|
if (menuName == "") menuName = "新建菜单-未命名";
|
|
|
|
|
$('.dd-list').append($.format('<li class="dd-item dd3-item" data-id="0"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><span>{0}</span></label></div></li>', menuName));
|
|
|
|
|
}
|
|
|
|
|
var did = $('#menuID').val();
|
|
|
|
|
if (did == "") did = 0;
|
|
|
|
|
$('.dd-list li[data-id="' + did + '"] span').addClass('active');
|
|
|
|
|
$('.menu-content').show();
|
|
|
|
|
$('div.dd3-content input').hide();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 选择父节点按钮
|
|
|
|
|
$('#btnMenuParent').click(function () {
|
|
|
|
|
$('li.dd-item').remove('[data-id="0"]');
|
|
|
|
|
$('#dialogNew div.modal-dialog').hide();
|
|
|
|
|
$('.menu-content button:last').data('type', 'parent');
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('.menu-content').show();
|
2016-11-03 16:28:05 +08:00
|
|
|
|
$('div.dd3-content :checkbox').hide();
|
|
|
|
|
$('div.dd3-content :radio').show();
|
2016-11-03 11:19:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.menu-content button').click(function () {
|
2016-11-03 16:28:05 +08:00
|
|
|
|
// remove active css
|
|
|
|
|
$('.dd3-content span').removeClass('active');
|
2016-11-03 11:19:40 +08:00
|
|
|
|
$('.menu-content').hide();
|
|
|
|
|
$('#dialogNew div.modal-dialog').show();
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-03 16:28:05 +08:00
|
|
|
|
//$('.dd3-content label').click(function (e) {
|
|
|
|
|
// var c = $(this).parents('div').children('label').children('input:not(:hidden)');
|
|
|
|
|
// if (c.length == 1) c.get(0).click();
|
|
|
|
|
// window.console.log($(this).html());
|
|
|
|
|
//});
|
2016-11-03 11:19:40 +08:00
|
|
|
|
|
2016-11-03 16:28:05 +08:00
|
|
|
|
$('.menu-content button:last').click(function () {
|
|
|
|
|
var type = $('.menu-content button:last').data('type');
|
|
|
|
|
switch (type) {
|
|
|
|
|
case "parent":
|
|
|
|
|
$('#parentId').val($('.dd3-content :radio:checked').val());
|
|
|
|
|
$('#parentName').val($('.dd3-content :radio:checked').next('span').text());
|
|
|
|
|
break;
|
|
|
|
|
case "order":
|
|
|
|
|
var data = $('#nestable_menu').nestable('serialize');
|
|
|
|
|
var mid = $('#menuID').val();
|
|
|
|
|
for (index in data) {
|
|
|
|
|
window.console.log(index);
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#nestable_menu').nestable();
|
2016-10-25 18:54:20 +08:00
|
|
|
|
});
|