123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- /**
- * 用户角色分配管理
- *
- */
- $.namespace("user.userrole");
- user.userrole.allData = null;
- user.userrole.data;
- // 页面初始化展示
- 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 += "<td ><input codeid='" + all.roleCode
- + "' id='" + all.id
- + "' type='checkbox' class='roleClass' "+(all.sel?"checked='checked'":"")+" isShowrelating='"+(all.sfcytb=="1")+"' value='"
- + all.id + "'onclick=\"user.userrole.liandong('"
- + all.id + "',this)\"></td>";
- if (all.sfcytb=="1"){
- str +="<td class='hidetdClass'><input type='checkbox' isShowrelating='true' "+(all.sftb?"checked='checked'":"")+" codeid='" + all.roleCode
- + "' id='a"
- + all.id + "' class='sfClass' value='" + all.roleCode
- + "' onclick=\"user.userrole.liandong('"
- + all.id + "',this)\"></td>"
- str += "<td><span class='synStatusClass'></span></td>";
- }else{
- str += "<td class='hidetdClass'>--</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);
- //需求取消同步
- $(this).prop("checked", false);
- });
- };
- // 全不选按钮功能实现
- user.userrole.notall = function() {
- $(".roleClass").each(function() {
- $(this).prop("checked", false);
- });
- $(".sfClass").each(function() {
- $(this).prop("checked", false);
- });
-
- };
-
- };
- user.userrole.isNotBlank=function(value){
- if(typeof(value)!='undefined'){
- value=value+"";
- for(var i=0; i<value.length; i++) {
- var c = value.charAt(i);
- if ((c!=' ')&&(c!='\n')&&(c!='\t')) return true;
- }
- }
- return false;
- }
- //保存分配给该用户的角色的功能实现
- user.userrole.synSave = 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());
- }
- });
- */
-
- var info = {};
- info.userId=$("#userId").val();
- info.roles=new Array();
- info.needsyssyn=false;
- $(".roleClass").each(function() {
- if ($(this).prop("checked")) {
- //roleids.push($(this).val());
- //rolecodes.push($('#a'+$(this)[0].id).val()||'');
- var tobj={};
- tobj.userId=$("#userId").val();
- tobj.roleId=$(this).val();
- tobj.sftb="0";
-
- var jobj=$('#a'+$(this)[0].id);
- if(jobj&&jobj.length){
- //alert(jobj[0].id+"--"+jobj.prop("checked"));
- if(jobj.prop("checked")){
- tobj.sftb="1";
- info.needsyssyn=true;
- }
-
- }
- info.roles.push(tobj);
- }
- });
-
-
- $.ajax({
- type : 'post',
- dataType : 'json',
- contentType : 'application/json;charset=utf-8',
- //timeout : 10000, //超时时间设置,单位毫秒
- cache : false,// 不从缓存中去数据
- async : true,
- url : $.app + "/user/saveuserroleSyn.html",
- data : JSON.stringify(info),
- //headers:headinfo,
- success : function(data) {
- /*
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- if (data.success) {
- location.href = $.app + "/user/querylist.html";
- }
- }
- });
- */
- var message="";
-
- if(data&&data.jsonInfo){
- console.log(data.jsonInfo);
- console.log("user.userrole.data:",user.userrole.data);
- if(data.jsonInfo.isfail||data.jsonInfo.userIdisNull){
- message="提交参数错误";
- }else if(!data.jsonInfo.userexist){
- message="用户不存在";
- }else{
- for(var n in data){
- if(n=='jsonInfo'){
- continue;
- }
-
- var pass=true;
- if(user.userrole.data&&user.userrole.data[n]){
- pass=false;
- }
-
- var d=data[n];
- //alert(d.success);alert(d.sysname);
- //d.success=false;
- console.log(pass,d);
- if(pass
- &&typeof(d.success)=="boolean"&&!d.success&&user.userrole.isNotBlank(d.sysname)){
- message=message+d.sysname+"、";
- }
- }
-
- if(!user.userrole.isNotBlank(message)){
- message="保存成功";
- if(info&&info.needsyssyn){
- message="同步成功";
- }
- }else{
- message=message.substring(0, message.length-1)+"更新失败"
- }
- }
- }
- $.alert({
- title : '提示',
- content : message,
- confirm : function() {
- /*
- if (data.success) {
- location.href = $.app + "/user/querylist.html";
- }
- */
- user.userrole.synStatus();
- }
- });
- },
- error : function(jqXHR, textStatus, errorThrown) {
- //alert(jqXHR.responseText);
- }
- });
-
-
- /*
- 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.save = function() {
- var xyqrxx=false;
- var jqueryObjArray=[];
- $(".sfClass").each(function() {
- //$(this).prop("checked", true);
-
- if($(this).is(":checked")&&$(this).attr("isShowrelating")&&$(this).attr("isShowrelating")=="true"){
- console.log($(this).attr("id"),$(this).is(":checked")+":"+$(this).attr("isShowrelating"));
- jqueryObjArray.push($(this));
- }
-
- });
-
- if(jqueryObjArray&&jqueryObjArray.length){
- for(var i=0;i<jqueryObjArray.length;i++){
- var key=jqueryObjArray[i].attr("codeid");
- if(key&&user.userrole.data&&user.userrole.data[key]){
- xyqrxx=true;
- break;
- }
- }
- }
-
- if(xyqrxx){
- $.confirm({
- title : '确认框',
- content : '同步系统中存在相同用户,待用户确认?',
- confirm : function() {
- user.userrole.synSave();
- },
- cancel: function(){
-
- }
- });
- }else{
- user.userrole.synSave();
- }
- }
- user.userrole.liandong = function(data,thisck) {
- var checkObj=$('#' + data);
- if(checkObj&&checkObj.length){
- if ($('#' + data + '').is(":checked")) {
- //$('#a' + data + '').prop("checked", true);
-
- } else {
- $('#a' + data + '').prop("checked", false);
- }
-
- checkObj=$(thisck);
- if(checkObj.attr("isShowrelating")&&checkObj.attr("isShowrelating")=="true"){
- //console.log()
- if(checkObj.parents("tr").find(".synStatusClass").is(":hidden")){
- user.userrole.synStatus();
- }else{
- checkObj.parents("tr").find(".synStatusClass").hide();
- }
-
-
- }
-
- }
- }
- user.userrole.synStatus = function() {
- var jqueryObjArray=[];
- var roleObj={};
- $('.synStatusClass').hide();
- //$('.hidetdClass').hide();
- //$(".roleClass").each(function() {
- $(".sfClass").each(function() {
- //$(this).prop("checked", true);
-
- if($(this).is(":checked")&&$(this).attr("isShowrelating")&&$(this).attr("isShowrelating")=="true"){
- console.log($(this).attr("id"),$(this).is(":checked")+":"+$(this).attr("isShowrelating"));
- //$(this).parents("tr").find(".synStatusClass").show();
- //$(this).parents("tr").find(".synStatusClass").text("");
- //console.log($(this).parents("tr").find(".synStatusClass").html());
- jqueryObjArray.push($(this));
- roleObj[$(this).attr("codeid")]=$(this).attr("value");
- }
-
- });
-
-
- if(jqueryObjArray&&jqueryObjArray.length){
- console.log("1.",{roleObj:roleObj,userId:$("#userId").val()});
- //alert($(".btn").length);
- $(".btn").attr("disabled",true);
- $.ajax({
- type : 'post',
- dataType : 'json',
- contentType : 'application/json;charset=utf-8',
- //timeout : 10000, //超时时间设置,单位毫秒
- cache : false,// 不从缓存中去数据
- async : true,
- url : $.app + "/user/relating.html",
- data : JSON.stringify({roleObj:roleObj,userId:$("#userId").val()}),
- //headers:headinfo,
- success : function(data) {
- console.log("2.",data);
- user.userrole.data=data;
- for(var i=0;i<jqueryObjArray.length;i++){
- jqueryObjArray[i].parents("tr").find(".synStatusClass").show();
- jqueryObjArray[i].parents("tr").find(".synStatusClass").text("不存在此用户,同步后将创建");
-
- //console.log("3.",jqueryObjArray[i].attr("codeid"));
- var key=jqueryObjArray[i].attr("codeid");
- if(key&&user.userrole.data){
- //console.log(key,user.userrole.data);
-
- if(user.userrole.data[key+"_error"]){
- jqueryObjArray[i].parents("tr").find(".synStatusClass").text("联系管理员,接口调用异常");//,请管理员确认操作
- }else if(user.userrole.data[key]){
- jqueryObjArray[i].parents("tr").find(".synStatusClass").text("已存在此用户");//,请管理员确认操作
- }
- }
- /*
- if(key&&user.userrole.data&&user.userrole.data[key]){
- jqueryObjArray[i].parents("tr").find(".synStatusClass").text("已存在此用户");//,请管理员确认操作
- }
- */
- }
- $(".btn").attr("disabled",false);
- },
- error : function(jqXHR, textStatus, errorThrown) {
- //alert(jqXHR.responseText);
- }
- });
-
- }
- }
- user.userrole.sfliandong=function(data) {
- if ($('#a' + data + '').is(":checked")) {
- $('#' + data + '').prop("checked", true);
- }
- }
|