angular.module('push') .controller('selectWhoSeeCtrl', function ($scope, $stateParams, ResourceLibraryService, UtilService, UserService, $timeout, ConstantService, resourceLibraryModel,CommonService) { // // 默认权限:公开 // $scope.ispublic = 2; var vm=$scope.vm={}; vm.selectWho=[ { selectType:'公开', selectContent:'任何push用户', signupid:11111, ispublic:2, isShowArrow:false }, { selectType:'私密', selectContent:'仅自己可见', signupid:444444, ispublic:0, isChecked:false, isFirst:false, isShowArrow:false }, // { // selectType:'部分可见', // selectContent:'选中的好友可见', // signupid:222222, // ispublic:1, // isShowArrow:true, // whitegroup:[],// 部分可见的群组 // whiteuser:[],// 部分可见的选中成员 // sectionList:[ // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'255', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'235', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'265', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'295', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'135', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // } // ] // }, // { // selectType:'不给谁看', // selectContent:'选择的朋友不可见', // signupid:33333, // ispublic:3, // isShowArrow:true, // blackgroup:[],// 不给谁看的群组 // blackuser:[],// 不给谁看的选中成员 // sectionList:[ // { // checkBoxEd:'false', // sectionWrap:'群组A', // sectionGroupLabelId:'695', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'6', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'7', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'8', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // }, // { // checkBoxEd:false, // sectionWrap:'群组A', // sectionGroupLabelId:'9', // sectionContent:[ // {name:'昵称'}, // {name:'ww'}, // {name:'meet_c'} // ] // } // ] // } ]; vm.selection= vm.selectWho[0];//默认显示公开 // 传递给群组设置页的参数 $scope.groupDetail={ groupid:0, groupName:"", memberNum:0 }; // 添加成员的参数:从谁可以看界面进入 $scope.sourcefrom = 2; // 保存时的权限设置 $scope.requestModel= { userid:UserService.id, resid:1, rescode:1, data:{ authority: {}, group: [], user: [] } }; // 获取的权限设置 $scope.authority= { ispublic: $stateParams.ispublic }; // 创建权限传递的权限组参数 $scope.authorityForCreate= { //TODO /*resid:0, rescode:"", data:{ authorityid:1, authname:"", ispublic:2, creator:0, updater:0 }*/ resid:$stateParams.resid, rescode:$stateParams.rescode, data:{ authorityid:$stateParams.authorityid, authname:$stateParams.authname, ispublic:$stateParams.ispublic, creator:$stateParams.creator, updater:$stateParams.updater } }; console.log($scope.authorityForCreate); //TODO // 谁可以看选项 // 获取谁可以看选项及部分可见群组及成员 // 权限id $scope.authorityid = $stateParams.authorityid; // $scope.authorityid = 2; var getAuthority = function () { ResourceLibraryService.getAuthorityAndGroup($scope.authorityid).then(function (response) { if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){ console.log(response); // 权限组信息 $scope.authority = response.data.authority; // 群组信息 // 部分可见 if (response.data.authority.ispublic == 1){ vm.selectWho[2].whitegroup = response.data.group; // 选择成员信息 vm.selectWho[2].whiteuser = response.data.user; }else if (response.data.authority.ispublic == 3){ // 不给谁看 vm.selectWho[3].blackgroup = response.data.group; // 选择成员信息 vm.selectWho[3].blackuser = response.data.user; } } }, function () { }); }; // flag:true 才刷新,从前一页面进入 if(resourceLibraryModel.getFlag()){ // 有设置过群组 if($scope.authorityid != 0) { getAuthority(); }else{ // 未设置过群组:公开 $scope.authority.ispublic = $stateParams.ispublic; } }else{ // 设置群组/添加群组后返回 // 权限信息 $scope.authority = resourceLibraryModel.getAuthority(); // 群组信息 // 部分可见 if ($scope.authority.ispublic == 1){ vm.selectWho[2].whitegroup = resourceLibraryModel.getGroupList(); // 选择成员信息 vm.selectWho[2].whiteuser = resourceLibraryModel.getUserList(); }else if ($scope.authority.ispublic == 3){ // 不给谁看 vm.selectWho[3].blackgroup = resourceLibraryModel.getGroupList(); // 选择成员信息 vm.selectWho[3].blackuser = resourceLibraryModel.getUserList(); } resourceLibraryModel.setFlag(true); } // 保存编辑后的权限 $scope.saveAuthInfo = function () { // 保存权限-更新 // 群组设置 // 部分可见 if ($scope.authority.ispublic == 1) { // 将未选中的群组剔除 var whoindex = 2; angular.forEach(vm.selectWho[whoindex].whitegroup, function (value, ind) { if (vm.selectWho[whoindex].whitegroup[ind].checkBoxEd == true) { $scope.requestModel.data.group.push(vm.selectWho[whoindex].whitegroup[ind]); } }); // 选择的用户列表 $scope.requestModel.data.user = vm.selectWho[whoindex].whiteuser; }else if ($scope.authority.ispublic == 3) { // 不给谁看 // 将未选中的群组剔除 var whoindex = 3; angular.forEach(vm.selectWho[whoindex].blackgroup, function (value, ind) { if (vm.selectWho[whoindex].blackgroup[ind].checkBoxEd == true) { $scope.requestModel.data.group.push(vm.selectWho[whoindex].blackgroup[ind]); } }); // 选择的用户列表 $scope.requestModel.data.user = vm.selectWho[whoindex].blackuser; } $timeout(function () { ResourceLibraryService.updateAuthority($scope.requestModel).then(function (response) { // console.log(response); // 保存后需初始化 resourceLibraryModel.resetResourceLibraryData(); if($scope.app){ UtilService.showMess("设置成功"); }else{ CommonService.showMessage("设置成功",$scope); } $timeout(function () { $scope.goback(); $scope.hideLoadingToast(); }, 500); }, 1000); }, function () { $scope.hideLoadingToast(); if($scope.app){ UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); }else{ CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); } }) }; // 保存编辑后的权限 $scope.saveAuth = function () { $scope.showLoadingToast(); // 未创建权限 且 选择了非公开,则创建权限 if ($scope.authorityid == 0 && $scope.authority.ispublic != 2) { // 传参cloudauthority中的authname,ispublic,creator,updater // resid,rescode分别对该块记录id和该设置权限的code $scope.authorityForCreate.data.authorityid=$stateParams.authorityid; $scope.authorityForCreate.data.authname=$stateParams.authname; $scope.authorityForCreate.data.ispublic=$scope.authority.ispublic;// 更改后的选项 $scope.authorityForCreate.data.creator=$stateParams.creator; $scope.authorityForCreate.data.updater=$stateParams.updater; $scope.authorityForCreate.resid=$stateParams.resid; $scope.authorityForCreate.rescode=$stateParams.rescode; console.log($scope.authorityForCreate); ResourceLibraryService.createAuthority($scope.authorityForCreate).then(function (response) { // console.log(response); // 取得创建好的权限组信息 $scope.requestModel.data.authority = response.data; $timeout(function () { $scope.saveAuthInfo(); }, 500); }, function () { }); }else{ // 若已有权限,则将其作为参数返回 $scope.requestModel.data.authority = $scope.authority; $scope.saveAuthInfo(); } } //记录选中列表索引,只能单选 // 选择公开程度选项 $scope.chooseNewType = function (value) { // 如果选择未变,值不变 if(value.ispublic == $scope.authority.ispublic){ return; } // 将选项值赋给结果集 $scope.authority.ispublic = value.ispublic; // console.log($scope.authority); }; // 记录选中群组列表索引 $scope.selectedSectionLength = 0; // 选择群组(多选) $scope.selectLabelOrgType = function (group, parentIndex,index) { /* // 若本是选中,则去 未选中 if (group[index].checkBoxEd == true) { var ind = group.indexOf(index); group.splice(ind,1); } else { group.push(group[index]); }*/ group[index].checkBoxEd = !group[index].checkBoxEd; vm.selectedSectionLength = group.length; }; //设置群组成员、名称、期限的按钮 $scope.goSetAuthorityGp=function (groupName, groupid, memberNum, ind) { // 权限信息 resourceLibraryModel.setAuthority($scope.authority); // 群组信息 // 部分可见 if ($scope.authority.ispublic == 1){ // 群组 resourceLibraryModel.setGroupList(vm.selectWho[2].whitegroup); // 选择成员信息 resourceLibraryModel.setUserList(vm.selectWho[2].whiteuser); }else if ($scope.authority.ispublic == 3){ // 群组 resourceLibraryModel.setGroupList(vm.selectWho[3].blackgroup); // 选择成员信息 resourceLibraryModel.setUserList(vm.selectWho[3].blackuser); } $scope.groupDetail.groupName = groupName; $scope.groupDetail.groupid = groupid; $scope.groupDetail.memberNum = memberNum; $scope.groupDetail.ind = ind; $scope.go('setAuthorityGroup', {groupDetail: $scope.groupDetail}); }; //从通讯录里直接选择好友 $scope.selectFromMail=function () { // 权限信息 resourceLibraryModel.setAuthority($scope.authority); // 群组信息 // 部分可见 if ($scope.authority.ispublic == 1){ // 群组 resourceLibraryModel.setGroupList(vm.selectWho[2].whitegroup); // 选择成员信息 resourceLibraryModel.setUserList(vm.selectWho[2].whiteuser); }else if ($scope.authority.ispublic == 3){ // 群组 resourceLibraryModel.setGroupList(vm.selectWho[3].blackgroup); // 选择成员信息 resourceLibraryModel.setUserList(vm.selectWho[3].blackuser); } $scope.go('selectAuthorityMember', {sourcefrom: $scope.sourcefrom}); console.log("从通讯录里直接选择好友:" + resourceLibraryModel.getUserList()); }; });