selectWhoSeeCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. angular.module('push')
  2. .controller('selectWhoSeeCtrl', function ($scope, $stateParams, ResourceLibraryService, UtilService, UserService,
  3. $timeout, ConstantService, resourceLibraryModel,CommonService) {
  4. // // 默认权限:公开
  5. // $scope.ispublic = 2;
  6. var vm=$scope.vm={};
  7. vm.selectWho=[
  8. {
  9. selectType:'公开',
  10. selectContent:'任何push用户',
  11. signupid:11111,
  12. ispublic:2,
  13. isShowArrow:false
  14. },
  15. {
  16. selectType:'私密',
  17. selectContent:'仅自己可见',
  18. signupid:444444,
  19. ispublic:0,
  20. isChecked:false,
  21. isFirst:false,
  22. isShowArrow:false
  23. },
  24. // {
  25. // selectType:'部分可见',
  26. // selectContent:'选中的好友可见',
  27. // signupid:222222,
  28. // ispublic:1,
  29. // isShowArrow:true,
  30. // whitegroup:[],// 部分可见的群组
  31. // whiteuser:[],// 部分可见的选中成员
  32. // sectionList:[
  33. // {
  34. // checkBoxEd:false,
  35. // sectionWrap:'群组A',
  36. // sectionGroupLabelId:'255',
  37. // sectionContent:[
  38. // {name:'昵称'},
  39. // {name:'ww'},
  40. // {name:'meet_c'}
  41. // ]
  42. // },
  43. // {
  44. // checkBoxEd:false,
  45. // sectionWrap:'群组A',
  46. // sectionGroupLabelId:'235',
  47. // sectionContent:[
  48. // {name:'昵称'},
  49. // {name:'ww'},
  50. // {name:'meet_c'}
  51. // ]
  52. // },
  53. // {
  54. // checkBoxEd:false,
  55. // sectionWrap:'群组A',
  56. // sectionGroupLabelId:'265',
  57. // sectionContent:[
  58. // {name:'昵称'},
  59. // {name:'ww'},
  60. // {name:'meet_c'}
  61. // ]
  62. // },
  63. // {
  64. // checkBoxEd:false,
  65. // sectionWrap:'群组A',
  66. // sectionGroupLabelId:'295',
  67. // sectionContent:[
  68. // {name:'昵称'},
  69. // {name:'ww'},
  70. // {name:'meet_c'}
  71. // ]
  72. // },
  73. // {
  74. // checkBoxEd:false,
  75. // sectionWrap:'群组A',
  76. // sectionGroupLabelId:'135',
  77. // sectionContent:[
  78. // {name:'昵称'},
  79. // {name:'ww'},
  80. // {name:'meet_c'}
  81. // ]
  82. // }
  83. // ]
  84. // },
  85. // {
  86. // selectType:'不给谁看',
  87. // selectContent:'选择的朋友不可见',
  88. // signupid:33333,
  89. // ispublic:3,
  90. // isShowArrow:true,
  91. // blackgroup:[],// 不给谁看的群组
  92. // blackuser:[],// 不给谁看的选中成员
  93. // sectionList:[
  94. // {
  95. // checkBoxEd:'false',
  96. // sectionWrap:'群组A',
  97. // sectionGroupLabelId:'695',
  98. // sectionContent:[
  99. // {name:'昵称'},
  100. // {name:'ww'},
  101. // {name:'meet_c'}
  102. // ]
  103. // },
  104. // {
  105. // checkBoxEd:false,
  106. // sectionWrap:'群组A',
  107. // sectionGroupLabelId:'6',
  108. // sectionContent:[
  109. // {name:'昵称'},
  110. // {name:'ww'},
  111. // {name:'meet_c'}
  112. // ]
  113. // },
  114. // {
  115. // checkBoxEd:false,
  116. // sectionWrap:'群组A',
  117. // sectionGroupLabelId:'7',
  118. // sectionContent:[
  119. // {name:'昵称'},
  120. // {name:'ww'},
  121. // {name:'meet_c'}
  122. // ]
  123. // },
  124. // {
  125. // checkBoxEd:false,
  126. // sectionWrap:'群组A',
  127. // sectionGroupLabelId:'8',
  128. // sectionContent:[
  129. // {name:'昵称'},
  130. // {name:'ww'},
  131. // {name:'meet_c'}
  132. // ]
  133. // },
  134. // {
  135. // checkBoxEd:false,
  136. // sectionWrap:'群组A',
  137. // sectionGroupLabelId:'9',
  138. // sectionContent:[
  139. // {name:'昵称'},
  140. // {name:'ww'},
  141. // {name:'meet_c'}
  142. // ]
  143. // }
  144. // ]
  145. // }
  146. ];
  147. vm.selection= vm.selectWho[0];//默认显示公开
  148. // 传递给群组设置页的参数
  149. $scope.groupDetail={
  150. groupid:0,
  151. groupName:"",
  152. memberNum:0
  153. };
  154. // 添加成员的参数:从谁可以看界面进入
  155. $scope.sourcefrom = 2;
  156. // 保存时的权限设置
  157. $scope.requestModel=
  158. {
  159. userid:UserService.id,
  160. resid:1,
  161. rescode:1,
  162. data:{
  163. authority: {},
  164. group: [],
  165. user: []
  166. }
  167. };
  168. // 获取的权限设置
  169. $scope.authority= {
  170. ispublic: $stateParams.ispublic
  171. };
  172. // 创建权限传递的权限组参数
  173. $scope.authorityForCreate=
  174. {
  175. //TODO
  176. /*resid:0,
  177. rescode:"",
  178. data:{
  179. authorityid:1,
  180. authname:"",
  181. ispublic:2,
  182. creator:0,
  183. updater:0
  184. }*/
  185. resid:$stateParams.resid,
  186. rescode:$stateParams.rescode,
  187. data:{
  188. authorityid:$stateParams.authorityid,
  189. authname:$stateParams.authname,
  190. ispublic:$stateParams.ispublic,
  191. creator:$stateParams.creator,
  192. updater:$stateParams.updater
  193. }
  194. };
  195. console.log($scope.authorityForCreate);
  196. //TODO
  197. // 谁可以看选项
  198. // 获取谁可以看选项及部分可见群组及成员
  199. // 权限id
  200. $scope.authorityid = $stateParams.authorityid;
  201. // $scope.authorityid = 2;
  202. var getAuthority = function () {
  203. ResourceLibraryService.getAuthorityAndGroup($scope.authorityid).then(function (response) {
  204. if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){
  205. console.log(response);
  206. // 权限组信息
  207. $scope.authority = response.data.authority;
  208. // 群组信息
  209. // 部分可见
  210. if (response.data.authority.ispublic == 1){
  211. vm.selectWho[2].whitegroup = response.data.group;
  212. // 选择成员信息
  213. vm.selectWho[2].whiteuser = response.data.user;
  214. }else if (response.data.authority.ispublic == 3){
  215. // 不给谁看
  216. vm.selectWho[3].blackgroup = response.data.group;
  217. // 选择成员信息
  218. vm.selectWho[3].blackuser = response.data.user;
  219. }
  220. }
  221. }, function () {
  222. });
  223. };
  224. // flag:true 才刷新,从前一页面进入
  225. if(resourceLibraryModel.getFlag()){
  226. // 有设置过群组
  227. if($scope.authorityid != 0) {
  228. getAuthority();
  229. }else{
  230. // 未设置过群组:公开
  231. $scope.authority.ispublic = $stateParams.ispublic;
  232. }
  233. }else{
  234. // 设置群组/添加群组后返回
  235. // 权限信息
  236. $scope.authority = resourceLibraryModel.getAuthority();
  237. // 群组信息
  238. // 部分可见
  239. if ($scope.authority.ispublic == 1){
  240. vm.selectWho[2].whitegroup = resourceLibraryModel.getGroupList();
  241. // 选择成员信息
  242. vm.selectWho[2].whiteuser = resourceLibraryModel.getUserList();
  243. }else if ($scope.authority.ispublic == 3){
  244. // 不给谁看
  245. vm.selectWho[3].blackgroup = resourceLibraryModel.getGroupList();
  246. // 选择成员信息
  247. vm.selectWho[3].blackuser = resourceLibraryModel.getUserList();
  248. }
  249. resourceLibraryModel.setFlag(true);
  250. }
  251. // 保存编辑后的权限
  252. $scope.saveAuthInfo = function () {
  253. // 保存权限-更新
  254. // 群组设置
  255. // 部分可见
  256. if ($scope.authority.ispublic == 1) {
  257. // 将未选中的群组剔除
  258. var whoindex = 2;
  259. angular.forEach(vm.selectWho[whoindex].whitegroup, function (value, ind) {
  260. if (vm.selectWho[whoindex].whitegroup[ind].checkBoxEd == true) {
  261. $scope.requestModel.data.group.push(vm.selectWho[whoindex].whitegroup[ind]);
  262. }
  263. });
  264. // 选择的用户列表
  265. $scope.requestModel.data.user = vm.selectWho[whoindex].whiteuser;
  266. }else if ($scope.authority.ispublic == 3) {
  267. // 不给谁看
  268. // 将未选中的群组剔除
  269. var whoindex = 3;
  270. angular.forEach(vm.selectWho[whoindex].blackgroup, function (value, ind) {
  271. if (vm.selectWho[whoindex].blackgroup[ind].checkBoxEd == true) {
  272. $scope.requestModel.data.group.push(vm.selectWho[whoindex].blackgroup[ind]);
  273. }
  274. });
  275. // 选择的用户列表
  276. $scope.requestModel.data.user = vm.selectWho[whoindex].blackuser;
  277. }
  278. $timeout(function () {
  279. ResourceLibraryService.updateAuthority($scope.requestModel).then(function (response) {
  280. // console.log(response);
  281. // 保存后需初始化
  282. resourceLibraryModel.resetResourceLibraryData();
  283. if($scope.app){
  284. UtilService.showMess("设置成功");
  285. }else{
  286. CommonService.showMessage("设置成功",$scope);
  287. }
  288. $timeout(function () {
  289. $scope.goback();
  290. $scope.hideLoadingToast();
  291. }, 500);
  292. }, 1000);
  293. }, function () {
  294. $scope.hideLoadingToast();
  295. if($scope.app){
  296. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  297. }else{
  298. CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope);
  299. }
  300. })
  301. };
  302. // 保存编辑后的权限
  303. $scope.saveAuth = function () {
  304. $scope.showLoadingToast();
  305. // 未创建权限 且 选择了非公开,则创建权限
  306. if ($scope.authorityid == 0 && $scope.authority.ispublic != 2) {
  307. // 传参cloudauthority中的authname,ispublic,creator,updater
  308. // resid,rescode分别对该块记录id和该设置权限的code
  309. $scope.authorityForCreate.data.authorityid=$stateParams.authorityid;
  310. $scope.authorityForCreate.data.authname=$stateParams.authname;
  311. $scope.authorityForCreate.data.ispublic=$scope.authority.ispublic;// 更改后的选项
  312. $scope.authorityForCreate.data.creator=$stateParams.creator;
  313. $scope.authorityForCreate.data.updater=$stateParams.updater;
  314. $scope.authorityForCreate.resid=$stateParams.resid;
  315. $scope.authorityForCreate.rescode=$stateParams.rescode;
  316. console.log($scope.authorityForCreate);
  317. ResourceLibraryService.createAuthority($scope.authorityForCreate).then(function (response) {
  318. // console.log(response);
  319. // 取得创建好的权限组信息
  320. $scope.requestModel.data.authority = response.data;
  321. $timeout(function () {
  322. $scope.saveAuthInfo();
  323. }, 500);
  324. }, function () {
  325. });
  326. }else{
  327. // 若已有权限,则将其作为参数返回
  328. $scope.requestModel.data.authority = $scope.authority;
  329. $scope.saveAuthInfo();
  330. }
  331. }
  332. //记录选中列表索引,只能单选
  333. // 选择公开程度选项
  334. $scope.chooseNewType = function (value) {
  335. // 如果选择未变,值不变
  336. if(value.ispublic == $scope.authority.ispublic){
  337. return;
  338. }
  339. // 将选项值赋给结果集
  340. $scope.authority.ispublic = value.ispublic;
  341. // console.log($scope.authority);
  342. };
  343. // 记录选中群组列表索引
  344. $scope.selectedSectionLength = 0;
  345. // 选择群组(多选)
  346. $scope.selectLabelOrgType = function (group, parentIndex,index) {
  347. /* // 若本是选中,则去 未选中
  348. if (group[index].checkBoxEd == true) {
  349. var ind = group.indexOf(index);
  350. group.splice(ind,1);
  351. } else {
  352. group.push(group[index]);
  353. }*/
  354. group[index].checkBoxEd = !group[index].checkBoxEd;
  355. vm.selectedSectionLength = group.length;
  356. };
  357. //设置群组成员、名称、期限的按钮
  358. $scope.goSetAuthorityGp=function (groupName, groupid, memberNum, ind) {
  359. // 权限信息
  360. resourceLibraryModel.setAuthority($scope.authority);
  361. // 群组信息
  362. // 部分可见
  363. if ($scope.authority.ispublic == 1){
  364. // 群组
  365. resourceLibraryModel.setGroupList(vm.selectWho[2].whitegroup);
  366. // 选择成员信息
  367. resourceLibraryModel.setUserList(vm.selectWho[2].whiteuser);
  368. }else if ($scope.authority.ispublic == 3){
  369. // 群组
  370. resourceLibraryModel.setGroupList(vm.selectWho[3].blackgroup);
  371. // 选择成员信息
  372. resourceLibraryModel.setUserList(vm.selectWho[3].blackuser);
  373. }
  374. $scope.groupDetail.groupName = groupName;
  375. $scope.groupDetail.groupid = groupid;
  376. $scope.groupDetail.memberNum = memberNum;
  377. $scope.groupDetail.ind = ind;
  378. $scope.go('setAuthorityGroup', {groupDetail: $scope.groupDetail});
  379. };
  380. //从通讯录里直接选择好友
  381. $scope.selectFromMail=function () {
  382. // 权限信息
  383. resourceLibraryModel.setAuthority($scope.authority);
  384. // 群组信息
  385. // 部分可见
  386. if ($scope.authority.ispublic == 1){
  387. // 群组
  388. resourceLibraryModel.setGroupList(vm.selectWho[2].whitegroup);
  389. // 选择成员信息
  390. resourceLibraryModel.setUserList(vm.selectWho[2].whiteuser);
  391. }else if ($scope.authority.ispublic == 3){
  392. // 群组
  393. resourceLibraryModel.setGroupList(vm.selectWho[3].blackgroup);
  394. // 选择成员信息
  395. resourceLibraryModel.setUserList(vm.selectWho[3].blackuser);
  396. }
  397. $scope.go('selectAuthorityMember', {sourcefrom: $scope.sourcefrom});
  398. console.log("从通讯录里直接选择好友:" + resourceLibraryModel.getUserList());
  399. };
  400. });