authorityRecordSetCtrl.js 11 KB

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