$(function() { getRoleList(); getModuleList(); function getModuleList(){ var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']}); $.ajax({ type : 'POST', url : restHost + "/module/findAllPerson.json", dataType : "json", data : { "sid" : sid }, success : function(json) { parent.layer.close(loadIndex); if (json.successful == true || json.successful == "true") { $("#permissionShowArea").empty(); $.each(json.data, function(index, item) { var moduleHtml = $("#module-list-item-template").html(); moduleHtml = moduleHtml.replaceAll("{moduleId}",item.id); moduleHtml = moduleHtml.replaceAll("{moduleName}",item.name); var operationListHtml = ""; $.each(item.operationList, function(index, obj) { var operationHtml = $("#operation-list-item-template").html(); operationHtml = operationHtml.replaceAll("{operationId}",obj.id); operationHtml = operationHtml.replaceAll("{operationName}",obj.name); operationListHtml += operationHtml; }); moduleHtml = moduleHtml.replaceAll("{operationListHtml}",operationListHtml); $("#permissionShowArea").append(moduleHtml); }); } else { ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(loadIndex); console.log(errorThrown); } }); } function getRoleList() { var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']}); $.ajax({ type : 'POST', url : restHost + "/role/getRoleList.json", dataType : "json", data : { "sid" : sid }, success : function(json) { parent.layer.close(loadIndex); if (json.successful == true || json.successful == "true") { $.each(json.data, function(index, obj) { var roleHtml = ""; roleHtml = roleHtml + '
'; roleHtml = roleHtml + '
'; roleHtml = roleHtml + ' '; roleHtml = roleHtml + ' ' + obj.name + ''; if(delflag || renameflag){ roleHtml = roleHtml + ' '; roleHtml = roleHtml + ' '; } roleHtml = roleHtml + '
'; roleHtml = roleHtml + '
'; $(".left-user").append(roleHtml); }); } else { ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(loadIndex); console.log(errorThrown); } }); } $(".left-user").on("mouseenter", '.user', function() { $(this).find('b').css("display", 'block').removeClass('write'); }) $(".left-user").on("mouseleave", '.user', function() { $(this).find('b').css("display", 'none'); $(this).find('i').css('display', "none"); $(this).find('ul').css("display", 'none'); $(this).find('div').removeClass('active'); }) $(".left-user").on("click",'b',function() { $(this).addClass('write').parent().addClass('active').find('i').css('display', "block"); $(this).parent().find('ul').css("display", 'block'); }); $(".left-user").on("click",'.roleName',function() { getPermissionByRole(this,$(this).data("id")); }); function choiceAll(id){//全选 var all=$("#"+id).parent().find('input')[0].checked; var check=$("#"+id).parent().nextAll(); for(var i=0;i= 30) { $(".right-user,.user-name").css({ "top" : $(window).scrollTop() + "px" }) } else { $(".right-user,.user-name").css({"top" : "0"}); } }); function addRole() { $("#id").val(""); $("#name").val(""); $(".modal-header h4").html("添加角色"); } function deleteRole(obj, roleId) { parent.layer.confirm('确认要删除该角色吗?', { title : "温馨提示", skin:"confirm-class", btn : [ '确认', '取消' ] //按钮 }, function(index) { parent.layer.close(index); $.ajax({ type : 'POST', url : restHost + "/role/delete.json", dataType : "json", data : { "sid" : sid, "id" : roleId }, async : false, success : function(json) { if (json.successful == true || json.successful == "true") { $(obj).parent().parent().parent().parent().remove(); toastrSuccess("操作成功!"); } else { ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); }); } function editRole(obj, roleId) { $(".left-user").find("span.current").removeClass("current"); var changeval = $(obj).parent("li").parent("ul").siblings("span").addClass("current").html(); $("#id").val(roleId); $("#name").val(changeval); $(".modal-header h4").html("重命名"); } function save(obj) { var id = $("#id").val(); var name = $("#name").val(); if(name.trim() == ""){ toastrError("请填写角色名!"); return; } $.ajax({ type : 'POST', url : restHost + "/role/update.json", dataType : "json", data : { "sid" : sid, "id" : id, "name" : name }, async : false, success : function(json) { if (json.successful == true || json.successful == "true") { if (id == "") { var roleId = json.data; var roleHtml = ""; roleHtml = roleHtml + '
'; roleHtml = roleHtml + '
'; roleHtml = roleHtml + ' '; roleHtml = roleHtml + ' ' + name + ''; if(delflag || renameflag) { roleHtml = roleHtml + ' '; roleHtml = roleHtml + '
    '; //删除权限 if (delflag) { roleHtml = roleHtml + '
  • 删除角色
  • '; } //重命名权限 if (renameflag) { roleHtml = roleHtml + '
  • 重命名
  • '; } roleHtml = roleHtml + '
'; } roleHtml = roleHtml + '
'; roleHtml = roleHtml + '
'; $(".left-user").append(roleHtml); } else { var newvalw = $("#name").val(); $(".left-user .current").html(newvalw); $(".left-user").find("span.current").removeClass("current"); } $("#add-n-tier").modal("hide"); toastrSuccess("操作成功!"); } else { ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); } function checkPermissionForm(){ var flag = true; var roleId = $("#roleId").val(); if(roleId == ""){ toastrError("请选择要维护的角色!"); return false; }else{ var length = $("#permissionShowArea input[type=checkbox][name=operationIds]:checked").length; if(length < 1){ toastrError("每个角色至少维护一个权限!"); return false; } } return flag; } function submitPermissionForm(flag){ var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']}); $.ajax({ type : 'POST', url : restHost + "/permission/save.json", dataType : "json", data : $("#permissionForm").serialize(), async : false,//有用不能注释掉 success : function(json) { flag = json.successful; if (json.successful == true || json.successful == "true") { parent.layer.close(loadIndex); // toastrSuccess("操作成功!"); } else { parent.layer.close(loadIndex); ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(loadIndex); console.log(errorThrown); } }); return flag; } function savePermission(flag){ flag = checkPermissionForm(); if( flag && editflag){ flag = submitPermissionForm(flag); } return flag; } function finishInit() { if (checkFinish() && end()) { var index = parent.layer.load(0, {shade: [0.3,'#808080']}); $.ajax({ type : 'POST', url : restHost + "/user/finishInit.json", dataType : "json", data : { "sid" : sid }, // async : false, success : function(json) { if (json.successful == true || json.successful == "true") { toastrSuccess("恭喜!公司的初始化信息已完成。"); parent.layer.close(index); setTimeout("parent.userInit();",3000); } else { parent.layer.close(index); ajaxError(json); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { parent.layer.close(index); console.log(errorThrown); } }); } } function end(){ var flag = true; var rid = $("#roleId").val(); if(rid !=""){ flag = savePermission(flag); } if(flag){ /*flag = false; $.each($(".roleName"), function(indexRole, objRole) { var roleId = $(objRole).data("id"); var loadIndex = parent.layer.load(0, {shade: [0.3,'#808080']}); $.ajax({ type : 'POST', url : restHost + "/permission/getByRole.json", dataType : "json", data : { "sid" : sid, "id" : roleId, "roletype":"1" }, async : false, success : function(json) { parent.layer.close(loadIndex); flag = json.successful; }, error: function(XMLHttpRequest, textStatus, errorThrown) { flag = false; parent.layer.close(loadIndex); console.log(errorThrown); } }); if(!flag){ toastrError("每个角色至少维护一个权限!"); return flag; } });*/ } return flag; } function checkFinish() { var flag = false; $.ajax({ type : 'POST', url : restHost + "/role/getRoleList.json", dataType : "json", data : { "sid" : sid }, async : false, success : function(json) { if (json.successful == true || json.successful == "true") { flag = true; } else { toastrError("请添加角色"); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown); } }); return flag; }