angular.module('push') .controller('authorityRecordSetCtrl', function ($scope, $stateParams, AuthorityService, AuthorityModel, UtilService, $timeout, $ionicPopup, UserService) { var authoritydata = angular.fromJson($stateParams.authoritydata); $scope.type = authoritydata.recourcetype; $scope.viplevel = UserService.viplevel; var authorityid = 0; var authoritycomefrom = ""; $scope.reclib = { name: AuthorityModel.getReclibName() == "" ? authoritydata.title : AuthorityModel.getReclibName() }; //获取权限信息 var getAuthorityInfomation = function () { AuthorityService.getRecordAuthority(1, authoritydata).then(function (response) { $scope.authority = response; $scope.memberlist = response.userList;//成员列表 $scope.adminlist = response.adminList;//管理员列表 $scope.issuperadmin = response.issuperadmin; $scope.superadminids = response.superadminList;//超级管理员列表 $scope.identity = response.identity;//当前用户身份 0:普通成员,1:所有者,2:管理员,3:系统管理员 $scope.ownername = $scope.authority.creator.userName;//所有者name $scope.ownerid = $scope.authority.creator.userId;//所有者id $scope.oldownerid = angular.copy($scope.authority.creator.userId);//旧所有者id $scope.settingsList = { checked: response.sort != 0,//置顶 publicflg: response.ispublic == 2 }; $scope.reclib.content = UtilService.isDefined(response.intro) ? response.intro : ""; //获取当前权限id,comefrom authorityid = response.cid; authoritycomefrom = response.ccomefrom; //保存权限信息 AuthorityModel.invite_url = response.invite_url;//邀请链接 AuthorityModel.setIdentity($scope.identity); AuthorityModel.setOwnerName($scope.ownername); AuthorityModel.setOldOwnerId($scope.ownerid); AuthorityModel.setOwnerId($scope.ownerid); AuthorityModel.setAuthorityId(authorityid); AuthorityModel.setAuthorityComefrom(authoritycomefrom); AuthorityModel.setContent(response.intro); }, function () { UtilService.showMess("网络不给力,请重试"); }) }; //恢复临时数据 if (AuthorityModel.getReclibName() == "") { getAuthorityInfomation(); } else { $scope.memberlist = AuthorityModel.getMemberList(); $scope.adminlist = AuthorityModel.getAdminList(); $scope.issuperadmin = AuthorityModel.getIsSuperAdmin(); $scope.superadminids = AuthorityModel.getSuperAdminList(); $scope.identity = AuthorityModel.getIdentity(); $scope.oldownerid = AuthorityModel.getOldOwnerId(); $scope.ownerid = AuthorityModel.getOwnerId(); $scope.ownername = AuthorityModel.getOwnerName(); $scope.reclib.content = AuthorityModel.getContent(); authorityid = AuthorityModel.getAuthorityId(); authoritycomefrom = AuthorityModel.getAuthorityComefrom(); $scope.settingsList = { checked: AuthorityModel.getToggle(), publicflg: AuthorityModel.getPublicFlg() } } /*//置顶按钮 if (AuthorityModel.getToggle() != "unchecked") { $scope.settingsList = { checked: AuthorityModel.getToggle(), publicflg:AuthorityModel.getPublicFlg() } }*/ var showConfirm = function () { $ionicPopup.show({ title: "确认退出", template: "
确认将所有权转让给\"" + $scope.ownername + "\",退出此资源将不再列表中显示
", scope: $scope, buttons: [ {text: "取消"}, { text: '确认', type: "button-positive", onTap: function () { quitAuth(1); } } ] }); }; if (AuthorityModel.quitauthflg == 2) { showConfirm(); AuthorityModel.quitauthflg = 1; } //获取成员列表 var getMemberlist = function () { AuthorityService.getAuthorityDetail(authorityid, authoritycomefrom).then(function (response) { $scope.memberlist = response.userList; AuthorityModel.setMemberList($scope.memberlist); AuthorityModel.editmemberflg = false; }, function () { UtilService.showMess("网络不给力,请稍后重试"); }); }; //成员变动时重新获取成员列表 if (AuthorityModel.editmemberflg) { getMemberlist(); } //编辑权限 $scope.setauthisover = 0; $scope.editAuthInfo = function () { var adminids = []; angular.forEach($scope.adminlist, function (value, index) { adminids.push(value.userId); }); AuthorityService.infoEditAdmin(authorityid, authoritycomefrom, adminids, $scope.ownerid, authoritydata, $scope.superadminids).then(function (response) { $scope.setauthisover++; }, function () { $scope.setauthisover += 3; }); /*--------------------------------以上修改管理员,所有权;以下修改置顶,简介------------------------------------------*/ //判断置顶按钮 var tempbool = AuthorityModel.getToggle(); var sort; if (tempbool) { sort = 1; } else { sort = 0; } if (tempbool == "unchecked") { sort = -1; } var tempcon = UtilService.isDefined($scope.reclib.content) ? $scope.reclib.content : ""; var ispublic = $scope.settingsList.publicflg ? 2 : 1; //组装参数 var tempobj = { sort: sort, ispublic: ispublic, infoid: authoritydata.recourceid, infotype: authoritydata.recourcetype, infocomefrom: authoritydata.recourcecomefrom, introtype: AuthorityModel.getIntroType(),//是否修了权限简介 1:修改,2:未修改 cid: authorityid, ccomefrom: authoritycomefrom, intro: encodeURI(tempcon), userid: UserService.id }; AuthorityService.editIntro(tempobj).then(function (response) { $scope.setauthisover++; }, function () { $scope.setauthisover += 3; }); }; //--监听编辑是否结束 var authwatch = $scope.$watch("setauthisover", function (newValue) { if (newValue == 2) { UtilService.showMess("设置成功"); $timeout(function () { AuthorityModel.resetAuthorityData(); $scope.goback(); }, 1000); $scope.setauthisover = 0; authwatch(); } if (newValue > 3) { UtilService.showMess("网络不给力,请重试"); $scope.setauthisover = 0; } }); //打开/关闭 公开开关 $scope.openPublic = function () { AuthorityModel.setIntroType(1); AuthorityModel.setPublicFlg($scope.settingsList.publicflg); }; //选择/取消 置顶 $scope.cloudToggle = function () { AuthorityModel.setToggle($scope.settingsList.checked); }; //保存临时数据 var saveTempData = function () { AuthorityModel.setReclibName($scope.reclib.name); AuthorityModel.setMemberList($scope.memberlist); AuthorityModel.setAdminList($scope.adminlist); AuthorityModel.setIsSuperAdmin($scope.issuperadmin); AuthorityModel.setSuperAdminList($scope.superadminids); AuthorityModel.setOwnerId($scope.ownerid); AuthorityModel.setOwnerName($scope.ownername); AuthorityModel.setIdentity($scope.identity); AuthorityModel.setToggle($scope.settingsList.checked); AuthorityModel.setPublicFlg($scope.settingsList.publicflg); }; var quitAuth = function (type) { AuthorityService.InfoAuthorityExit(type, authoritydata.recourceid, authoritydata.recourcetype, authorityid, authoritycomefrom, $scope.ownerid).then(function (response) { UtilService.showMess("退出成功"); $timeout(function () { // AuthorityModel.editmemberflg = false; // AuthorityModel.quitauthflg = 0; // AuthorityModel.invite_url = ""; AuthorityModel.resetAuthorityData(); $scope.backViews(-2); }, 1000); }, function () { UtilService.showMess("网络不给力,请稍后重试"); }); }; $scope.quitAuthority = function () { if ($scope.identity == 1) { if ($scope.ownerid != $scope.oldownerid) { showConfirm(); } else { if ($scope.memberlist.length > 1) { $ionicPopup.show({ title: '退出提示', template: "请先设置所有权给其他成员后
才可以退出
", buttons: [ {text: "取消"}, { text: '去设置所有权', type: "button-positive", onTap: function (e) { saveTempData(); AuthorityModel.quitauthflg = 1; $scope.go("authoritySetOwner"); } } ] }); } else { $ionicPopup.show({ title: "确认退出此信息", template: "退出后信息将不再显示在列表中
", scope: $scope, buttons: [ {text: "取消"}, { text: '确认', type: "button-positive", onTap: function () { quitAuth(3); } } ] }) } } } else { $ionicPopup.show({ title: "确认退出此信息", template: "退出后信息将不再显示在列表中
", scope: $scope, buttons: [ {text: "取消"}, { text: '确认', type: "button-positive", onTap: function () { quitAuth(2); } } ] }); } }; //返回 $scope.gobackback = function () { AuthorityModel.resetAuthorityData(); $scope.goback(); }; //跳转至添加成员页面 $scope.addResourceMember = function () { saveTempData(); $scope.go("authorityAddMember", {authid: authorityid, authcomefrom: authoritycomefrom}); }; //跳转至设置管理员页面 $scope.goSetManger = function () { if ($scope.identity != 1 && $scope.identity != 3) { return; } saveTempData(); $scope.go("authoritySetManger"); }; //跳转至设置所有者页面 $scope.goSetOwner = function () { if ($scope.identity != 1 && $scope.identity != 3) { return; } saveTempData(); AuthorityModel.quitauthflg = 0; $scope.go("authoritySetOwner"); }; //跳转到成员页面 $scope.goResourceMember = function () { saveTempData(); $scope.go("authorityMember", {identity: $scope.identity, authid: authorityid, authcomefrom: authoritycomefrom}); }; $scope.setIntroType2 = function () { AuthorityModel.setIntroType(1); }; $scope.goPublisher = function (member) { saveTempData(); $scope.go('publisher', {Id: member.userId}) }; $scope.goSetSuperAdmin = function () { saveTempData(); $scope.go("accountSetChild"); }; });