123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /**
- * 用户角色分配管理
- *
- */
- $.namespace("user.userrole");
- user.userrole.allData = null;
- // 页面初始化展示
- user.userrole.init = function() {
- var str = "";
- var jsonallData = $.parseJSON(user.userrole.allData);
- if (jsonallData) {
- for ( var i = 0; i < jsonallData.length; i++) {
- var all = jsonallData[i];
- str += "<tr>";
- str += "<td style='text-align: center;'>" + all.roleName + "</td>";
- /*一个问题 怎么加是否同步判断,数据库没有这个字*/
- if (all.sel&&all.sfcytb=="1"&&all.sftb) {
- str += "<td ><input id='"
- + all.id
- + "' type='checkbox' checked='checked' class='roleClass' value='"
- + all.id + "' onclick=\"user.userrole.liandong('"
- + all.id + "')\"></td><td><input type='checkbox' id='a"
- + all.id + "' class='sfClass' value='" + all.roleCode
- + "' onclick=\"user.userrole.sfliandong('"
- + all.id + "')\" style='display:none'>已同步</td>";
- } else if(all.sel&&all.sfcytb=="1"&&!all.sftb){
- str += "<td ><input id='" + all.id
- + "' type='checkbox' checked='checked' class='roleClass' value='"
- + all.id + "'onclick=\"user.userrole.liandong('"
- + all.id + "')\"></td><td><input type='checkbox' id='a"
- + all.id + "' class='sfClass' value='" + all.roleCode
- + "' onclick=\"user.userrole.sfliandong('"
- + all.id + "')\"></td>";
- }else if(all.sel&&all.sfcytb!="1"){
- str += "<td ><input id='" + all.id
- + "' type='checkbox' checked='checked' class='roleClass' value='"
- + all.id + "'onclick=\"user.userrole.liandong('"
- + all.id + "')\"></td><td></td>";
-
- }else if(!all.sel&&all.sfcytb=="1"&&all.sftb){
- str += "<td ><input id='"
- + all.id
- + "' type='checkbox' class='roleClass' value='"
- + all.id + "' onclick=\"user.userrole.liandong('"
- + all.id + "')\"></td><td><input type='checkbox' id='a"
- + all.id + "' class='sfClass' value='" + all.roleCode
- + "' onclick=\"user.userrole.sfliandong('"
- + all.id + "')\" style='display:none'>已同步</td>";
-
- }else if(!all.sel&&all.sfcytb=="1"&&!all.sftb){
- str += "<td ><input id='" + all.id
- + "' type='checkbox' class='roleClass' value='"
- + all.id + "'onclick=\"user.userrole.liandong('"
- + all.id + "')\"></td><td><input type='checkbox' id='a"
- + all.id + "' class='sfClass' value='" + all.roleCode
- + "' onclick=\"user.userrole.sfliandong('"
- + all.id + "')\"></td>";
- }else if(!all.sel&&all.sfcytb!="1"){
- str += "<td ><input id='" + all.id
- + "' type='checkbox' class='roleClass' value='"
- + all.id + "'onclick=\"user.userrole.liandong('"
- + all.id + "')\"></td><td></td>";
- }
- str += "</tr>";
- }
- $("#divcontent").empty();
- $("#divcontent").append(str);
- }
- // 返回按钮功能实现
- user.userrole.back = function() {
- location.href = $.app + "/user/querylist.html";
- };
- // 全选按钮功能实现
- user.userrole.all = function() {
- $(".roleClass").each(function() {
- $(this).prop("checked", true);
- });
- $(".sfClass").each(function() {
- $(this).prop("checked", true);
- });
- };
- // 全不选按钮功能实现
- user.userrole.notall = function() {
- $(".roleClass").each(function() {
- $(this).prop("checked", false);
- });
- $(".sfClass").each(function() {
- $(this).prop("checked", false);
- });
-
- };
-
- };
- //保存分配给该用户的角色的功能实现
- user.userrole.save = function() {
- var roleids = new Array();
- var rolecodes=new Array();
- $(".roleClass").each(function() {
- if ($(this).prop("checked")) {
- roleids.push($(this).val());
- rolecodes.push($('#a'+$(this)[0].id).val()||'');
- }
- });
- var sfids = new Array();
- $(".sfClass").each(function() {
- if ($(this).prop("checked")) {
- sfids.push($(this).val());
- }
- });
- /*
- console.log({
- userId : $("#userId").val(),
- roles : roleids.join(","),
- sfids : sfids.join(","),
- rolecodes:rolecodes.join(",")
- })
- */
- $.ajax({
- type : 'POST',
- url : $.app + "/user/saveuserrole.html",
- dataType:"json",
- data : {
- userId : $("#userId").val(),
- roles : roleids.join(","),
- sfids : sfids.join(","),
- rolecodes:rolecodes.join(",")
- },
- success : function(data) {
- if (data.success) {
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- location.href = $.app + "/user/querylist.html";
- }
- });
- } else {
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- }
- });
- }
- }
-
- });
- };
- user.userrole.liandong = function(data) {
- if ($('#' + data + '').is(":checked")) {
- $('#a' + data + '').prop("checked", true);
- } else {
- $('#a' + data + '').prop("checked", false);
- }
- }
- user.userrole.sfliandong=function(data) {
- if ($('#a' + data + '').is(":checked")) {
- $('#' + data + '').prop("checked", true);
- }
- }
|