angular.module('push') .controller('authoritySetCtrl', function ($scope, $stateParams, AuthorityService, AuthorityModel, UtilService, $timeout, $ionicPopup, UserService) { if($scope.app){ $scope.setStatusBar(0); } var reclibid = $stateParams.reclibid; var authorityid = $stateParams.authorityid; var authoritycomefrom = $stateParams.authoritycomefrom; var parentid = $stateParams.parentid; $scope.type = $stateParams.type;//0:记录,1:资源 $scope.viplevel = UserService.viplevel; $scope.reclib = { name: AuthorityModel.getReclibName() == "" ? $stateParams.name : AuthorityModel.getReclibName(), content: AuthorityModel.getContent() == "" ? $stateParams.content : AuthorityModel.getContent() }; //获取权限信息 var getAuthorityInfomation = function () { AuthorityService.getAuthorityInfomation(authorityid, authoritycomefrom).then(function (response) { // console.log(response); $scope.authority = response; $scope.issuperadmin = response.issuperadmin; $scope.memberlist = response.userList; $scope.adminlist = response.adminList; $scope.superadminids = response.superadminList;//超级管理员列表 $scope.identity = response.identity; AuthorityModel.invite_url = response.invite_url; AuthorityModel.setIdentity($scope.identity); $scope.ownername = $scope.authority.creator.userName; AuthorityModel.setOwnerName($scope.ownername); $scope.ownerid = $scope.authority.creator.userId; $scope.oldownerid = angular.copy($scope.authority.creator.userId); AuthorityModel.setOldOwnerId($scope.ownerid); AuthorityModel.setOwnerId($scope.ownerid); }, 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(); angular.forEach($scope.memberlist, function (value, index) { if (value.iscreator == 1) { $scope.ownerid = value.userId; $scope.ownername = value.userName; } }); $scope.oldownerid = AuthorityModel.getOldOwnerId(); } //置顶按钮 if (AuthorityModel.getToggle() == "unchecked") { $scope.settingsList = { checked: $stateParams.sort != 0 }; } else { $scope.settingsList = { checked: AuthorityModel.getToggle() } } 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) { // console.log(response); $scope.memberlist = response.userList; AuthorityModel.setMemberList($scope.memberlist); AuthorityModel.editmemberflg = false; }, function () { UtilService.showMess("网络不给力,请稍后重试"); }); }; //成员变动时重新获取成员列表 if (AuthorityModel.editmemberflg) { getMemberlist(); } //编辑权限 $scope.editAuthInfo = function () { if (!UtilService.isDefined($scope.reclib.name)) { UtilService.showMess("名称不能为空"); return; } var adminids = []; angular.forEach($scope.adminlist, function (value, index) { adminids.push(value.userId); }); var tempbool = AuthorityModel.getToggle(); var sort; if (tempbool) { sort = 1; } else { sort = 0; } if (tempbool == "unchecked") { sort = -1; } AuthorityService.editAuthorityInfomation(reclibid, authorityid, authoritycomefrom, adminids, $scope.reclib.name, $scope.reclib.content, AuthorityModel.getOwnerId(), sort, parentid, $scope.superadminids).then(function (response) { // console.log(response); UtilService.showMess("设置成功"); $timeout(function () { AuthorityModel.resetAuthorityData(); // AuthorityModel.editmemberflg = false; // AuthorityModel.quitauthflg = 0; // AuthorityModel.invite_url = ""; if ($stateParams.goflg == 1) { $scope.backViews(-2); } else { $scope.goback(); } }, 1000); }, function () { UtilService.showMess("网络不给力,请重试"); }) }; //选择/取消 置顶 $scope.cloudToggle = function () { // console.log($scope.settingsList.checked); AuthorityModel.setToggle($scope.settingsList.checked); }; //保存临时数据 var saveTempData = function () { AuthorityModel.setReclibName($scope.reclib.name); AuthorityModel.setContent($scope.reclib.content); 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); }; var quitAuth = function (type) { AuthorityService.quitAuthority(type, reclibid, authorityid, authoritycomefrom, $scope.ownerid).then(function (response) { // console.log(response); UtilService.showMess("退出成功"); $timeout(function () { // AuthorityModel.editmemberflg = false; // AuthorityModel.quitauthflg = 0; // AuthorityModel.invite_url = ""; AuthorityModel.resetAuthorityData(); if ($stateParams.goflg == 1) { $scope.backViews(-2); } else { $scope.goback(); } }, 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) || $scope.memberlist.length <= 1) { return; } saveTempData(); $scope.go("authoritySetManger"); }; //跳转至设置所有者页面 $scope.goSetOwner = function () { if (($scope.identity != 1 && $scope.identity != 3) || $scope.memberlist.length <= 1) { return; } saveTempData(); AuthorityModel.quitauthflg = 0; $scope.go("authoritySetOwner", {identity: $scope.identity}); }; $scope.goSetSuperAdmin = function () { saveTempData(); $scope.go("accountSetChild"); }; //跳转到成员页面 $scope.goResourceMember = function () { saveTempData(); $scope.go("authorityMember", {identity: $scope.identity, authid: authorityid, authcomefrom: authoritycomefrom}); }; $scope.goPublisher = function (member) { saveTempData(); $scope.go('publisher', {Id: member.userId}) }; });