authoritySetCtrl.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. angular.module('push')
  2. .controller('authoritySetCtrl', function ($scope, $stateParams, AuthorityService, AuthorityModel, UtilService, $timeout, $ionicPopup, UserService) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. var reclibid = $stateParams.reclibid;
  7. var authorityid = $stateParams.authorityid;
  8. var authoritycomefrom = $stateParams.authoritycomefrom;
  9. var parentid = $stateParams.parentid;
  10. $scope.type = $stateParams.type;//0:记录,1:资源
  11. $scope.viplevel = UserService.viplevel;
  12. $scope.reclib = {
  13. name: AuthorityModel.getReclibName() == "" ? $stateParams.name : AuthorityModel.getReclibName(),
  14. content: AuthorityModel.getContent() == "" ? $stateParams.content : AuthorityModel.getContent()
  15. };
  16. //获取权限信息
  17. var getAuthorityInfomation = function () {
  18. AuthorityService.getAuthorityInfomation(authorityid, authoritycomefrom).then(function (response) {
  19. // console.log(response);
  20. $scope.authority = response;
  21. $scope.issuperadmin = response.issuperadmin;
  22. $scope.memberlist = response.userList;
  23. $scope.adminlist = response.adminList;
  24. $scope.superadminids = response.superadminList;//超级管理员列表
  25. $scope.identity = response.identity;
  26. AuthorityModel.invite_url = response.invite_url;
  27. AuthorityModel.setIdentity($scope.identity);
  28. $scope.ownername = $scope.authority.creator.userName;
  29. AuthorityModel.setOwnerName($scope.ownername);
  30. $scope.ownerid = $scope.authority.creator.userId;
  31. $scope.oldownerid = angular.copy($scope.authority.creator.userId);
  32. AuthorityModel.setOldOwnerId($scope.ownerid);
  33. AuthorityModel.setOwnerId($scope.ownerid);
  34. }, function () {
  35. UtilService.showMess("网络不给力,请重试");
  36. })
  37. };
  38. //恢复临时数据
  39. if (AuthorityModel.getReclibName() == "") {
  40. getAuthorityInfomation();
  41. } else {
  42. $scope.memberlist = AuthorityModel.getMemberList();
  43. $scope.adminlist = AuthorityModel.getAdminList();
  44. $scope.issuperadmin = AuthorityModel.getIsSuperAdmin();
  45. $scope.superadminids = AuthorityModel.getSuperAdminList();
  46. $scope.identity = AuthorityModel.getIdentity();
  47. angular.forEach($scope.memberlist, function (value, index) {
  48. if (value.iscreator == 1) {
  49. $scope.ownerid = value.userId;
  50. $scope.ownername = value.userName;
  51. }
  52. });
  53. $scope.oldownerid = AuthorityModel.getOldOwnerId();
  54. }
  55. //置顶按钮
  56. if (AuthorityModel.getToggle() == "unchecked") {
  57. $scope.settingsList = {
  58. checked: $stateParams.sort != 0
  59. };
  60. } else {
  61. $scope.settingsList = {
  62. checked: AuthorityModel.getToggle()
  63. }
  64. }
  65. var showConfirm = function () {
  66. $ionicPopup.show({
  67. title: "确认退出",
  68. template: "<p style='text-align: center;'>确认将所有权转让给\"" + $scope.ownername + "\",退出将不再列表中显示</p>",
  69. scope: $scope,
  70. buttons: [
  71. {text: "取消"},
  72. {
  73. text: '<span class="ionicAction_span">确认</span>',
  74. type: "button-positive",
  75. onTap: function () {
  76. quitAuth(1);
  77. }
  78. }
  79. ]
  80. });
  81. };
  82. if (AuthorityModel.quitauthflg == 2) {
  83. showConfirm();
  84. AuthorityModel.quitauthflg = 1;
  85. }
  86. //获取成员列表
  87. var getMemberlist = function () {
  88. AuthorityService.getAuthorityDetail(authorityid, authoritycomefrom).then(function (response) {
  89. // console.log(response);
  90. $scope.memberlist = response.userList;
  91. AuthorityModel.setMemberList($scope.memberlist);
  92. AuthorityModel.editmemberflg = false;
  93. }, function () {
  94. UtilService.showMess("网络不给力,请稍后重试");
  95. });
  96. };
  97. //成员变动时重新获取成员列表
  98. if (AuthorityModel.editmemberflg) {
  99. getMemberlist();
  100. }
  101. //编辑权限
  102. $scope.editAuthInfo = function () {
  103. if (!UtilService.isDefined($scope.reclib.name)) {
  104. UtilService.showMess("名称不能为空");
  105. return;
  106. }
  107. var adminids = [];
  108. angular.forEach($scope.adminlist, function (value, index) {
  109. adminids.push(value.userId);
  110. });
  111. var tempbool = AuthorityModel.getToggle();
  112. var sort;
  113. if (tempbool) {
  114. sort = 1;
  115. } else {
  116. sort = 0;
  117. }
  118. if (tempbool == "unchecked") {
  119. sort = -1;
  120. }
  121. AuthorityService.editAuthorityInfomation(reclibid, authorityid, authoritycomefrom, adminids, $scope.reclib.name, $scope.reclib.content, AuthorityModel.getOwnerId(), sort, parentid, $scope.superadminids).then(function (response) {
  122. // console.log(response);
  123. UtilService.showMess("设置成功");
  124. $timeout(function () {
  125. AuthorityModel.resetAuthorityData();
  126. // AuthorityModel.editmemberflg = false;
  127. // AuthorityModel.quitauthflg = 0;
  128. // AuthorityModel.invite_url = "";
  129. if ($stateParams.goflg == 1) {
  130. $scope.backViews(-2);
  131. } else {
  132. $scope.goback();
  133. }
  134. }, 1000);
  135. }, function () {
  136. UtilService.showMess("网络不给力,请重试");
  137. })
  138. };
  139. //选择/取消 置顶
  140. $scope.cloudToggle = function () {
  141. // console.log($scope.settingsList.checked);
  142. AuthorityModel.setToggle($scope.settingsList.checked);
  143. };
  144. //保存临时数据
  145. var saveTempData = function () {
  146. AuthorityModel.setReclibName($scope.reclib.name);
  147. AuthorityModel.setContent($scope.reclib.content);
  148. AuthorityModel.setMemberList($scope.memberlist);
  149. AuthorityModel.setAdminList($scope.adminlist);
  150. AuthorityModel.setIsSuperAdmin($scope.issuperadmin);
  151. AuthorityModel.setSuperAdminList($scope.superadminids);
  152. AuthorityModel.setOwnerId($scope.ownerid);
  153. AuthorityModel.setOwnerName($scope.ownername);
  154. AuthorityModel.setIdentity($scope.identity);
  155. };
  156. var quitAuth = function (type) {
  157. AuthorityService.quitAuthority(type, reclibid, authorityid, authoritycomefrom, $scope.ownerid).then(function (response) {
  158. // console.log(response);
  159. UtilService.showMess("退出成功");
  160. $timeout(function () {
  161. // AuthorityModel.editmemberflg = false;
  162. // AuthorityModel.quitauthflg = 0;
  163. // AuthorityModel.invite_url = "";
  164. AuthorityModel.resetAuthorityData();
  165. if ($stateParams.goflg == 1) {
  166. $scope.backViews(-2);
  167. } else {
  168. $scope.goback();
  169. }
  170. }, 1000);
  171. }, function () {
  172. UtilService.showMess("网络不给力,请稍后重试");
  173. });
  174. };
  175. //退出身份判断
  176. $scope.quitAuthority = function () {
  177. if ($scope.identity == 1) {
  178. if ($scope.ownerid != $scope.oldownerid) {
  179. showConfirm();
  180. } else {
  181. if ($scope.memberlist.length > 1) {
  182. $ionicPopup.show({
  183. title: '退出提示',
  184. template: "<p style='text-align: center;margin: 0;'>请先设置所有权给其他成员后</p><p style='text-align: center;margin-bottom: 5px;'>才可以退出</p>",
  185. buttons: [
  186. {text: "取消"},
  187. {
  188. text: '<span class="ionicAction_span">去设置所有权</span>',
  189. type: "button-positive",
  190. onTap: function (e) {
  191. saveTempData();
  192. AuthorityModel.quitauthflg = 1;
  193. $scope.go("authoritySetOwner");
  194. }
  195. }
  196. ]
  197. });
  198. } else {
  199. $ionicPopup.show({
  200. title: "确认退出此文件夹",
  201. template: "<p style='text-align: center;'>退出后文件夹将不再显示在列表中</p>",
  202. scope: $scope,
  203. buttons: [
  204. {text: "取消"},
  205. {
  206. text: '<span class="ionicAction_span">确认</span>',
  207. type: "button-positive",
  208. onTap: function () {
  209. quitAuth(3);
  210. }
  211. }
  212. ]
  213. })
  214. }
  215. }
  216. } else {
  217. $ionicPopup.show({
  218. title: "确认退出此文件夹",
  219. template: "<p style='text-align: center;'>退出后文件夹将不再显示在列表中</p>",
  220. scope: $scope,
  221. buttons: [
  222. {text: "取消"},
  223. {
  224. text: '<span class="ionicAction_span">确认</span>',
  225. type: "button-positive",
  226. onTap: function () {
  227. quitAuth(2);
  228. }
  229. }
  230. ]
  231. });
  232. }
  233. };
  234. //返回
  235. $scope.gobackback = function () {
  236. AuthorityModel.resetAuthorityData();
  237. $scope.goback();
  238. };
  239. //跳转至添加成员页面
  240. $scope.addResourceMember = function () {
  241. saveTempData();
  242. $scope.go("authorityAddMember", {authid: authorityid, authcomefrom: authoritycomefrom});
  243. };
  244. //跳转至设置管理员页面
  245. $scope.goSetManger = function () {
  246. if (($scope.identity != 1 && $scope.identity != 3) || $scope.memberlist.length <= 1) {
  247. return;
  248. }
  249. saveTempData();
  250. $scope.go("authoritySetManger");
  251. };
  252. //跳转至设置所有者页面
  253. $scope.goSetOwner = function () {
  254. if (($scope.identity != 1 && $scope.identity != 3) || $scope.memberlist.length <= 1) {
  255. return;
  256. }
  257. saveTempData();
  258. AuthorityModel.quitauthflg = 0;
  259. $scope.go("authoritySetOwner", {identity: $scope.identity});
  260. };
  261. $scope.goSetSuperAdmin = function () {
  262. saveTempData();
  263. $scope.go("accountSetChild");
  264. };
  265. //跳转到成员页面
  266. $scope.goResourceMember = function () {
  267. saveTempData();
  268. $scope.go("authorityMember", {identity: $scope.identity, authid: authorityid, authcomefrom: authoritycomefrom});
  269. };
  270. $scope.goPublisher = function (member) {
  271. saveTempData();
  272. $scope.go('publisher', {Id: member.userId})
  273. };
  274. });