diff --git a/Bootstrap.Admin/Content/js/framework.js b/Bootstrap.Admin/Content/js/framework.js index b1a083ab..99ef379b 100644 --- a/Bootstrap.Admin/Content/js/framework.js +++ b/Bootstrap.Admin/Content/js/framework.js @@ -244,8 +244,9 @@ function success(result) { if ($.isFunction(data.callback)) { if ($.isArray(result)) { - var html = data.html(result); - data.callback(html); + var formatData = result; + if ($.isFunction(data.html)) formatData = data.html(result); + data.callback(formatData); $('div.checkbox label.tooltips').tooltip(); return; } @@ -335,15 +336,10 @@ //Menus Menu = { url: '../api/Menus/', - title: "授权菜单", - html: function (result) { - return $.map(result, function (element, index) { - return $.format(htmlTemplateForMenu, element.ID, element.Name, element.Active); - }).join(''); - } + title: "授权菜单" } Menu.getMenusByRoleId = function (roleId, callback) { - processData.call(this, { Id: roleId, callback: callback, remote: false }); + processData.call(this, { Id: roleId, callback: callback, data: { type: "role" } }); }; Menu.saveMenusByRoleId = function (roleId, menuIds, callback) { processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", menuIds: menuIds } }); diff --git a/Bootstrap.Admin/Scripts/Roles.js b/Bootstrap.Admin/Scripts/Roles.js index 75ba52bc..d8ca23dd 100644 --- a/Bootstrap.Admin/Scripts/Roles.js +++ b/Bootstrap.Admin/Scripts/Roles.js @@ -53,6 +53,13 @@ Menu.getMenusByRoleId(row.ID, function (data) { $(".menu-content .modal-header .modal-title").text($.format('{0}-菜单授权窗口', row.RoleName)); $('.menu-content button:last').data('type', 'menu'); + // set checkbox status + var menus = $('#nestable_menu').find('input:checkbox'); + menus.removeProp('checked'); + $.each(data, function (index, item) { + var selector = $.format('[value={0}]', item.ID); + menus.filter(selector).prop('checked', 'checked'); + }); $('#dialogMenu').modal('show'); $('.menu-content').show(); $('div.dd3-content :radio').hide(); diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index 85f6ef53..a3ff16e6 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -166,7 +166,7 @@ namespace Bootstrap.DataAccess List Menus = new List(); try { - string sql = "select n.ID,n.ParentId, n.Name,n.[Order],n.Icon,n.Url,n.Category, case nr.NavigationID when n.ID then 'active' else '' end [status] from Navigations n left join NavigationRole nr on n.ID = nr.NavigationID and RoleID = @RoleID"; + string sql = "select NavigationID from NavigationRole where RoleID = @RoleID"; using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) { cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId, ParameterDirection.Input)); @@ -176,14 +176,7 @@ namespace Bootstrap.DataAccess { Menus.Add(new Menu() { - ID = (int)reader[0], - ParentId = (int)reader[1], - Name = (string)reader[2], - Order = (int)reader[3], - Icon = LgbConvert.ReadValue(reader[4], string.Empty), - Url = LgbConvert.ReadValue(reader[5], string.Empty), - Category = (string)reader[6], - Active = (string)reader[7] == "" ? "" : "checked" + ID = (int)reader[0] }); } }