controllers.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. starter.controller('TaskCtrl', function ($rootScope, $scope, $state, _, global, Task) {
  2. $scope.nexturl = null;
  3. $scope.goBack = function () {
  4. global.goBack();
  5. };
  6. $scope.toadd = function () {
  7. $state.go('task-create');
  8. };
  9. $scope.toman = function () {
  10. $state.go('task-man');
  11. };
  12. $scope.todetails = function (item) {
  13. $state.go('task-details', {
  14. id: item.id
  15. });
  16. };
  17. $scope.totansfer = function () {
  18. $state.go('transfer');
  19. };
  20. $scope.loadMore = function () {
  21. if ($scope.nexturl != null) {
  22. gettaskdata();
  23. }
  24. };
  25. function gettaskdata() {
  26. if (global.user.token != "") {
  27. Task.task($scope.nexturl).get({'type': 'received'}, function (res) {
  28. var olddata = [];
  29. if ($scope.nexturl != null) {
  30. olddata = _.map($scope.Task, _.clone);
  31. }
  32. $scope.nexturl = res.next;
  33. res.results = _.sortBy(res.results, 'create_date').reverse();
  34. res.results = _.sortBy(res.results, 'is_completed');
  35. $scope.Task = res.results;
  36. $scope.Task = olddata.concat($scope.Task);
  37. }, function (err) {
  38. $scope.loading = false;
  39. $scope.$broadcast('scroll.infiniteScrollComplete');
  40. alert(JSON.stringify(err));
  41. }).$promise.finally(function () {
  42. $scope.$broadcast('scroll.infiniteScrollComplete');
  43. $scope.loading = false;
  44. });
  45. }
  46. }
  47. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  48. if ($scope.Task == undefined) $scope.loading = true;
  49. global.fetch_user().then(function () {
  50. gettaskdata();
  51. $scope.roleid = global.user.roleid;
  52. }, function (err) {
  53. alert(JSON.stringify(err));
  54. $scope.loading = false;
  55. });
  56. });
  57. $scope.$on("$destroy", function () {
  58. beforeEnter = null;
  59. })
  60. })
  61. .controller('TaskManCtrl', function ($rootScope, $scope, $ionicModal, Task, global) {
  62. var modal = $ionicModal.fromTemplateUrl('templates/taskruleset-modal.html', {
  63. scope: $scope,
  64. animation: 'slide-in-right'
  65. });
  66. var old_data = null;
  67. $scope.openModal = function () {
  68. modal.then(function (m) {
  69. $rootScope.commons.modal = m;
  70. $rootScope.commons.modal.show();
  71. $scope.itemdata = _.clone(old_data);
  72. })
  73. };
  74. $scope.init = function () {
  75. global.fetch_user().then(function (data) {
  76. Task.taskpreferences.get({'key': 'task_rule'}, function (data) {
  77. old_data = _.clone(data);
  78. }, function (err) {
  79. old_data = {'key': 'task_rule', 'value': 1};
  80. }).$promise.finally(function () {
  81. $scope.itemdata = _.clone(old_data);
  82. });
  83. });
  84. };
  85. $scope.closeModal = function () {
  86. $rootScope.commons.modal.hide();
  87. };
  88. $scope.$on('$destroy', function () {
  89. $rootScope.commons.modal.remove();
  90. });
  91. $scope.ok = function () {
  92. $scope.closeModal();
  93. if (old_data.value == $scope.itemdata.value)
  94. return;
  95. Task.taskpreferences.save($scope.itemdata, function (data) {
  96. old_data = _.clone(data);
  97. $scope.itemdata = _.clone(old_data);
  98. });
  99. };
  100. })
  101. .controller('PostedTaskCtrl', function ($rootScope, $scope, $state, $ionicHistory, $ionicScrollDelegate, Task, Member, global) {
  102. $scope.nexturl = null;
  103. var taskall = [];
  104. $scope.totalcount = 0;
  105. $scope.Ishidded = true;
  106. $scope.headerion = {
  107. leftion: true,
  108. rightion: true
  109. };
  110. $scope.leftdata = [{
  111. id: 0,
  112. name: '最新发布',
  113. check: true,
  114. key: 'create_date'
  115. }, {
  116. id: 1,
  117. name: '最近更新',
  118. check: false,
  119. key: 'last_modified'
  120. }, {
  121. id: 2,
  122. name: '截止时间',
  123. check: false,
  124. key: 'end_dd'
  125. }];
  126. $scope.rightdata = [{
  127. id: 0,
  128. name: '全部成员',
  129. check: true,
  130. key: ''
  131. }, {
  132. id: 1,
  133. name: '选择单个成员',
  134. check: false
  135. }];
  136. $scope.title = [{
  137. id: 0,
  138. name: '最新发布'
  139. }, {
  140. id: 1,
  141. name: '全部成员'
  142. }];
  143. var beforeenter = $scope.$on('$ionicView.beforeEnter', function () {
  144. $rootScope.goBackRoute = 'postedtask';
  145. if ($scope.Task == undefined) $scope.loading = true;
  146. global.fetch_user().then(function () {
  147. if (Member.selectedemplst.length > 0) {
  148. $scope.rightdata[1].name = '选择单个成员(' + Member.selectedemplst[0].username + ')';
  149. $scope.title[1].name = Member.selectedemplst[0].username;
  150. getdata(Member.selectedemplst[0].user_id);
  151. Member.selectedemplst = [];
  152. } else {
  153. //打开的selecetmemer 页面但是点了取消
  154. if ($scope.rightdata[1].name.length > 6) {
  155. setrightcheck(false, true);
  156. } else {
  157. setrightcheck(true, false);
  158. getdata();
  159. }
  160. }
  161. });
  162. });
  163. $scope.leftdisplay = function () {
  164. setdisplay('rightion', 'leftion');
  165. };
  166. $scope.rightdisplay = function () {
  167. setdisplay('leftion', 'rightion');
  168. };
  169. $scope.toadd = function () {
  170. $state.go('task-create');
  171. };
  172. $scope.backhide = function () {
  173. $scope.headerion = {
  174. leftion: true,
  175. rightion: true
  176. };
  177. $scope.Ishidded = !$scope.Ishidded;
  178. };
  179. $scope.change = function (op, item) {
  180. if (op == 'f') {
  181. if ($scope.title[0].name != item.name) {
  182. $scope.title[0].name = item.name;
  183. $scope.Task = _.sortBy(_.sortBy($scope.Task, item.key).reverse(), 'is_completed');
  184. $scope.rightdata[0].key = item.key;
  185. }
  186. } else {
  187. if ($scope.rightdata[1].id == item.id) {
  188. setrightcheck(false, true);
  189. Member.titlename = "选择单个成员";
  190. Member.routename = 'postedtask';
  191. Member.selectedemplst = [];
  192. $state.go('selectsinglemember');
  193. } else {
  194. $scope.nexturl = null;
  195. getdata();//all
  196. $scope.title[1].name = "全部成员";
  197. $scope.rightdata[1].name = '选择单个成员';
  198. setrightcheck(true, false);
  199. }
  200. }
  201. $scope.backhide();
  202. };
  203. $scope.todetails = function (item) {
  204. $state.go('task-details', {
  205. id: item.id
  206. });
  207. };
  208. $scope.loadMore = function () {
  209. if ($scope.nexturl != null) getdata();
  210. };
  211. function setrightcheck(allcheck, singlecheck) {
  212. $scope.rightdata[0].check = allcheck;
  213. $scope.rightdata[1].check = singlecheck;
  214. }
  215. function getdata(usrid) {
  216. var data = {'type': 'posted'};
  217. if (usrid != undefined) {
  218. data.usrid = usrid;
  219. $scope.nexturl = null;
  220. }
  221. Task.task($scope.nexturl).get(data, function (res) {
  222. $scope.Task = usrid != undefined ? [] : $scope.Task;
  223. $scope.totalcount = res.count;
  224. var olddata = [];
  225. if ($scope.nexturl != null)
  226. olddata = _.map($scope.Task, _.clone);
  227. $scope.nexturl = res.next;
  228. $scope.Task = olddata.concat(_.sortBy(res.results, 'is_completed'));
  229. $scope.loading = false;
  230. }, function (err) {
  231. console.log(err);
  232. $scope.$broadcast('scroll.infiniteScrollComplete');
  233. }).$promise.finally(function () {
  234. $scope.$broadcast('scroll.infiniteScrollComplete');
  235. $ionicScrollDelegate.resize();
  236. $scope.loading = false;
  237. });
  238. }
  239. function setdisplay(key1, key2) {
  240. // $scope.headerion[key1] = $scope.headerion[key1] ? true : false;
  241. if (!$scope.Ishidded) {
  242. $scope.headerion[key1] = !$scope.headerion[key1];
  243. } else {
  244. $scope.Ishidded = !$scope.Ishidded;
  245. }
  246. if (!$scope.headerion[key2] && !$scope.Ishidded) {
  247. $scope.backhide();
  248. } else {
  249. $scope.headerion[key2] = !$scope.headerion[key2];
  250. }
  251. }
  252. $scope.$on('$destroy', function () {
  253. beforeenter = null;
  254. Member.selectedemplst = [];
  255. });
  256. })
  257. .controller('TaskCreateCtrl', function ($rootScope, $scope, $state, $ionicHistory, $ionicPopup,
  258. $cordovaDatePicker, $timeout, $q, _, Task, Member, showPopup, ImageManage, Tool, formatFilter) {
  259. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  260. $scope.popup = {
  261. isPopup: false
  262. };
  263. if (Member.selectedemplst.length > 0) {
  264. _.each(Member.selectedemplst, function (item) {
  265. item.is_leader = 'F';
  266. $scope.task.task_members.push(item);
  267. });
  268. Member.selectedemplst = [];
  269. } else {
  270. if (!$scope.task) {
  271. init_task();
  272. }
  273. }
  274. });
  275. $scope.goback = function () {
  276. if ($scope.task.content != null && $scope.task.content != '' || $scope.task.task_members.length > 0) {
  277. showPopup.confirm('是否取消创建?', '是', '否').then(function (res) {
  278. if (res) {
  279. $ionicHistory.goBack()
  280. }
  281. })
  282. } else {
  283. $ionicHistory.goBack();
  284. }
  285. };
  286. $scope.selectmember = function () {
  287. $scope.isremove = false;
  288. Member.titlename = '选择任务成员';
  289. Member.routename = '';
  290. Member.resourcemember = $scope.task.task_members;
  291. $state.go('selectmember');
  292. };
  293. $scope.remove = function (user, index) {
  294. $scope.task.task_members.splice(index, 1);
  295. if ($scope.task.task_members.length == 0) $scope.isremove = false;
  296. };
  297. $scope.isremove = false;
  298. $scope.changeRemove = function (flag) {
  299. $scope.isremove = !flag;
  300. };
  301. $scope.showModal = function () {
  302. showPopup.modalTemplate('templates/modal-selectadmin.html', 'slide-in-right', $scope).then(function (modal) {
  303. $rootScope.commons.modal = modal;
  304. $rootScope.commons.modal.show();
  305. });
  306. };
  307. $scope.closeModal = function () {
  308. $rootScope.commons.modal.hide();
  309. };
  310. $scope.changeAdmin = function (item, index) {
  311. $scope.isremove = false;
  312. $scope.closeModal();
  313. $scope.task.task_members.splice(index, 1);
  314. $scope.task.task_members.splice(0, 0, item);
  315. };
  316. $scope.addTask = function () {
  317. if (Task.check($scope.task)) {
  318. showPopup.showLoading(1, '正在提交', true, $scope.image_list.length > 0 ? 20000 : 10000);
  319. var task = angular.copy($scope.task);
  320. task.leader = task.task_members[0].user_id;
  321. task.task_members[0].is_leader = 'T';
  322. task.task_members = _.map(task.task_members, function (m) {
  323. return {'user': m.user_id, 'is_leader': m.is_leader}
  324. });
  325. Task.task(null).save(task, function (data) {
  326. if ($scope.image_list.length == 0) {
  327. showPopup.hideLoading();
  328. godetail(data.id);
  329. init_task();
  330. return;
  331. }
  332. ImageManage.uploadImage($scope.image_list, 'task', data.id, 'taskfile').then(function (res) {
  333. $q.all(res).then(function (res1) {
  334. showPopup.hideLoading();
  335. godetail(data.id);
  336. init_task();
  337. }, function (err) {
  338. showPopup.hideLoading();
  339. alert(JSON.stringify(err));
  340. });
  341. }, function (err) {
  342. showPopup.hideLoading();
  343. showPopup.PopupWindow(1, 'get upload token fail!');
  344. });
  345. }, function (err) {
  346. console.log(err);
  347. showPopup.hideLoading()
  348. });
  349. }
  350. };
  351. var flag = true;
  352. $scope.chooseDate = function () {
  353. if (flag) {
  354. flag = false;
  355. var options = {
  356. mode: 'date',
  357. date: $scope.task.end_dd == null ? new Date() : $scope.task.end_dd,
  358. androidTheme: 3
  359. };
  360. $cordovaDatePicker.show(options).then(function (date) {
  361. if (date == undefined) return;
  362. $scope.task.end_dd = date;
  363. flag = true;
  364. }, function (cancel) {
  365. flag = true;
  366. });
  367. }
  368. };
  369. $scope.shouBigImage = function (imageName) { //传递一个参数(图片的URl)
  370. $scope.Url = imageName; //$scope定义一个变量Url,这里会在大图出现后再次点击隐藏大图使用
  371. $rootScope.commons.bigImage = true; //显示大图
  372. };
  373. $rootScope.commons.bigImage = false; //初始默认大图是隐藏的
  374. $scope.hideBigImage = function () {
  375. $rootScope.commons.bigImage = false;
  376. };
  377. $scope.deleteimage = function () {
  378. $scope.image_list.splice(_.indexOf($scope.image_list, $scope.Url), 1);
  379. $rootScope.commons.bigImage = false;
  380. };
  381. $scope.image_list = [];
  382. $scope.addphoto = function () {
  383. if ($scope.image_list.length == $rootScope.commons.upload_maxcount) {
  384. showPopup.PopupWindow(0, formatFilter('最多可上传{0}张!', $rootScope.commons.upload_maxcount), false);
  385. return;
  386. }
  387. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  388. $scope.popup.isPopup = true;
  389. };
  390. var ImagePicker = function () { //打开相册
  391. $scope.popup.optionsPopup.close();
  392. ImageManage.ImagePicker_getPictures($rootScope.commons.upload_maxcount - $scope.image_list.length).then(function (promises) {
  393. $q.all(promises).then(function (res) {
  394. $scope.image_list = $scope.image_list.concat(res);
  395. }, function (error) {
  396. alert(error);
  397. });
  398. });
  399. };
  400. var Camera = function () {
  401. $scope.popup.optionsPopup.close();
  402. ImageManage.Camera_getPicture().then(function (result) {
  403. $scope.image_list.push(result);
  404. });
  405. };
  406. function godetail(id) {
  407. $ionicHistory.goBack();
  408. $timeout(function () {
  409. $state.go('task-details', {
  410. id: id
  411. })
  412. });
  413. Member.resourcemember = [];
  414. }
  415. function init_task() {
  416. $scope.task = {
  417. content: null,
  418. end_dd: null,
  419. create_date: null,
  420. is_completed: 0,
  421. task_members: []
  422. };
  423. $scope.image_list = [];
  424. }
  425. $scope.$on("$destroy", function () {
  426. beforeEnter = null;
  427. if ($rootScope.commons.modal != null) $rootScope.commons.modal.remove();
  428. Member.resourcemember = [];
  429. })
  430. })
  431. .controller('TaskDetailsCtrl', function ($rootScope, $scope, $state, $stateParams, $ionicSlideBoxDelegate,
  432. $ionicPopup, $ionicScrollDelegate, $timeout, $cordovaDatePicker, $ionicHistory, $q, showPopup, global, ImageManage, Member, Tool, Task, formatFilter) {
  433. $scope.activeIndex = 0;
  434. $scope.change = function (index) {
  435. $scope.activeIndex = index;
  436. };
  437. $scope.goBack = function () {
  438. global.goBack();
  439. };
  440. $scope.taskcomments = [];
  441. $scope.taskhistory = [];
  442. $scope.childtask = init_childtask();
  443. $scope.postcommentdata = init_comment();
  444. $scope.data = {};
  445. $scope.childtasks = [];
  446. $scope.lockSlide = function () {
  447. $ionicSlideBoxDelegate.enableSlide(false);
  448. };
  449. var beforeenter = $scope.$on('$ionicView.beforeEnter', function () {
  450. if ($scope.task == undefined) $scope.loading = true;
  451. global.fetch_user().then(function () {
  452. getTaskDetails();
  453. getTaskComments();
  454. gettaskhistory();
  455. }, function (err) {
  456. alert(JSON.stringify(err));
  457. });
  458. $scope.popup = {
  459. isPopup: false
  460. };
  461. });
  462. $scope.deletecomment = function (comment, index) {
  463. if (comment.create_user.id == global.user.usrid) {
  464. $scope.popup.optionsPopup = $ionicPopup.show({
  465. template: '<div class="center customer-op" rj-close-back-drop><h4>用户操作</h4></div>',
  466. scope: $scope,
  467. buttons: [{
  468. text: '删除',
  469. type: 'button-positive',
  470. onTap: function (e) {
  471. $scope.taskcomments.splice(index, 1);
  472. Task.taskcomment(null).delete({'id': comment.id}, function (res) {
  473. });
  474. }
  475. }]
  476. });
  477. $scope.popup.isPopup = true;
  478. }
  479. };
  480. $scope.closeModal = function (op) {
  481. if (op == 'select') {//选择负责人
  482. $rootScope.commons.modal.hide();
  483. return;
  484. }
  485. showPopup.confirm('是否取消创建?', '是', '否').then(function (res) {
  486. if (res) {
  487. $rootScope.commons.modal.hide();
  488. }
  489. });
  490. };
  491. // Cleanup the modal when we're done with it!
  492. $scope.$on('$destroy', function () {
  493. beforeenter = null;
  494. if ($rootScope.commons.modal != null) $rootScope.commons.modal.remove();
  495. });
  496. //子任务复选框
  497. $scope.changecheck = function (childtask) {
  498. childtask.parent = $scope.task.id;
  499. marktask(childtask, childtask.is_completed);
  500. };
  501. $scope.tocomment = function () {
  502. $scope.postcommentdata = init_comment();
  503. $scope.image_list = [];
  504. $rootScope.commons.bigImage = false;
  505. showPopup.modalTemplate('templates/modal-taskcomment.html', 'slide-in-up', $scope).then(function (modal) {
  506. $rootScope.commons.modal = modal;
  507. $rootScope.commons.modal.show();
  508. })
  509. };
  510. var addchildmodal = null;
  511. $scope.toaddchildtask = function () {
  512. $scope.childtask = init_childtask();
  513. showPopup.modalTemplate('templates/modal-addchildtask.html', 'slide-in-up', $scope).then(function (modal) {
  514. $rootScope.commons.modal = modal;
  515. $rootScope.commons.modal.show();
  516. addchildmodal = _.clone(modal);
  517. });
  518. };
  519. $scope.addchildtask = function () {
  520. if (Tool.trim($scope.childtask.content).length == 0) {
  521. showPopup.PopupWindow(0, '请输入任务内容!', false);
  522. return;
  523. }
  524. showPopup.showLoading(1, '正在提交', true);
  525. var leader = $scope.childtask.leader;
  526. if ($scope.childtask.leader != null) {
  527. $scope.childtask.leader = $scope.childtask.leader.id;
  528. }
  529. Task.task(null).save($scope.childtask, function (data) {
  530. showPopup.hideLoading();
  531. data.leader = leader;
  532. $scope.childtasks.splice(0, 0, data);
  533. $scope.nexturl.history = null;
  534. gettaskhistory();
  535. $rootScope.commons.modal.hide();
  536. }, function (error) {
  537. showPopup.hideLoading();
  538. alert("add childtask error:" + JSON.stringify(error));
  539. });
  540. };
  541. var flag_end_dd = true;
  542. $scope.checkend_dd = function () {
  543. if (flag_end_dd) {
  544. flag_end_dd = false;
  545. var options = {
  546. mode: 'date',
  547. date: new Date($scope.childtask.end_dd == null ? new Date() : $scope.childtask.end_dd),
  548. androidTheme: 3
  549. };
  550. $cordovaDatePicker.show(options).then(function (date) {
  551. $timeout(function () {
  552. if (date == undefined) return;
  553. $scope.childtask.end_dd = date;
  554. });
  555. flag_end_dd = true;
  556. });
  557. }
  558. };
  559. $scope.setTask = function () {
  560. Task.taskdetail = $scope.task;
  561. Task.taskdetail.childtasks = $scope.childtasks;
  562. Member.selectedemplst = [];
  563. $state.go('task-set', {
  564. id: $stateParams.id,
  565. isheader: $scope.Isheader ? 1 : 0
  566. });
  567. };
  568. $scope.postcomment = function () {
  569. if ($scope.postcommentdata.content == '') {
  570. showPopup.PopupWindow(0, '请输入评论内容!', false);
  571. return;
  572. }
  573. showPopup.showLoading(1, '正在提交', true, $scope.image_list.length > 0 ? 20000 : 10000);
  574. Task.taskcomment(null).save({'task_id': $stateParams.id}, $scope.postcommentdata, function (data) {
  575. $scope.taskcomments.splice(0, 0, data);
  576. if ($scope.image_list.length == 0) {
  577. showPopup.hideLoading();
  578. $rootScope.commons.modal.hide();
  579. return;
  580. }
  581. ImageManage.uploadImage($scope.image_list, 'task', data.id, 'taskcommentfile').then(function (res) {
  582. $q.all(res).then(function (res1) {
  583. data.task_comment_files = _.sortBy(_.map(res1, function (item) {
  584. return JSON.parse(item.response);
  585. }), 'id');
  586. showPopup.hideLoading();
  587. $rootScope.commons.modal.hide();
  588. })
  589. }, function (err) {
  590. alert('upload image error' + err);
  591. showPopup.hideLoading();
  592. });
  593. }, function (err) {
  594. alert('commnet fail!');
  595. });
  596. };
  597. $scope.toeditchildtask = function (id) {
  598. if (($scope.data.leader.id == global.user.usrid) || ($scope.data.create_user.id == global.user.usrid)) {
  599. Task.taskdetail = $scope.task;
  600. Task.taskdetail.childtasks = $scope.childtasks;
  601. $state.go('editchildtask', {
  602. 'id': id
  603. });
  604. }
  605. };
  606. $scope.checkheader = function () {
  607. showPopup.modalTemplate('templates/modal-selectadmin.html', 'slide-in-right', $scope).then(function (modal) {
  608. $rootScope.commons.modal = modal;
  609. $rootScope.commons.modal.show();
  610. });
  611. };
  612. //标记任务完成或未完成
  613. $scope.marktask = function (completeid) {
  614. if (completeid == 1) {
  615. if (_.findWhere($scope.childtasks, {is_completed: false}) == undefined) {
  616. marktask($scope.data, completeid);
  617. return;
  618. }
  619. showPopup.confirm('还有未完成的子任务,确定要完成吗?', '确定', '取消').then(function (res) {
  620. if (res) {
  621. marktask($scope.data, completeid);
  622. }
  623. });
  624. } else {
  625. marktask($scope.data, completeid);
  626. }
  627. };
  628. $scope.changeAdmin = function (user) {
  629. $scope.childtask.leader = user.user;
  630. $rootScope.commons.modal.hide();
  631. $rootScope.commons.modal = addchildmodal;
  632. };
  633. $scope.image_list = [];
  634. $scope.imagePicker = function () { //打开相册
  635. if (!check_image()) return;
  636. ImageManage.ImagePicker_getPictures($rootScope.commons.upload_maxcount).then(function (promises) {
  637. $q.all(promises).then(function (res) {
  638. $scope.image_list = $scope.image_list.concat(res);
  639. }, function (error) {
  640. alert(error);
  641. });
  642. });
  643. };
  644. $scope.Camera = function () {
  645. if (!check_image()) return;
  646. ImageManage.Camera_getPicture().then(function (result) {
  647. $scope.image_list.push(result);
  648. });
  649. };
  650. $scope.shouBigImage = function (imageName, event) { //传递一个参数(图片的URl)
  651. if (event != undefined) {
  652. event.stopPropagation();
  653. }
  654. $scope.Url = imageName;
  655. $rootScope.commons.bigImage = true;
  656. };
  657. $scope.stopPropagation = function (event) {
  658. if (event != undefined) {
  659. event.stopPropagation();
  660. }
  661. }
  662. $rootScope.commons.bigImage = false; //初始默认大图是隐藏的
  663. $scope.hideBigImage = function () {
  664. $rootScope.commons.bigImage = false;
  665. };
  666. $scope.deleteimage = function () {
  667. $scope.image_list.splice(_.indexOf($scope.image_list, $scope.Url), 1);
  668. $rootScope.commons.bigImage = false;
  669. };
  670. $scope.nexturl = {'comment': null, 'history': null};
  671. $scope.loadMore = function (type) {
  672. if (type == 'history') {
  673. gettaskhistory();
  674. } else {
  675. getTaskComments();
  676. }
  677. };
  678. function check_image() {
  679. if ($scope.image_list.length >= $rootScope.commons.upload_maxcount) {
  680. showPopup.PopupWindow(0, formatFilter('最多可上传{0}张', $rootScope.commons.upload_maxcount), false);
  681. return false
  682. }
  683. return true;
  684. }
  685. function getTaskDetails() {
  686. Task.task(null).get({'id': $stateParams.id}, function (data) {
  687. $scope.data = angular.copy(data);
  688. var members = _.filter(data.task_members, function (item) {
  689. return data.leader.id != item.user.id;
  690. });
  691. data.membernames = _.map(members, function (m) {
  692. if (data.leader.id != m.user.id) return m.user.username;
  693. }).join('、');
  694. $scope.task = data;
  695. $scope.Isheader = ($scope.task.create_user.id == global.user.usrid);
  696. if ((data.create_user.id == global.user.usrid) || (data.leader.id == global.user.usrid)) {
  697. $scope.is_disabledmark = false;
  698. } else {
  699. Task.taskpreferences.get({'key': 'task_rule'}, function (data) {
  700. $scope.is_disabledmark = data.value == '1';
  701. });
  702. }
  703. }, function (err) {
  704. console.log(err)
  705. }).$promise.finally(function (res) {
  706. $scope.loading = false;
  707. });
  708. //get child task
  709. Task.taskchild.get({'id': $stateParams.id}, function (res) {
  710. $scope.childtasks = _.sortBy(res.results, 'is_completed');
  711. })
  712. }
  713. function marktask(data, is_completed) {
  714. var task = angular.copy(data);
  715. task.leader = task.leader.id;
  716. task = _.omit(task, 'create_user', 'childtasks', 'task_files');
  717. task.task_members = _.map(task.task_members, function (item) {
  718. return {'is_leader': item.is_leader, 'user': item.user.id};
  719. });
  720. task.is_completed = is_completed;
  721. showPopup.showLoading(1, '', false);
  722. Task.task(null).update({'id': task.id}, task, function (data) {
  723. $scope.nexturl.history = null;
  724. gettaskhistory();
  725. $scope.childtasks = _.sortBy($scope.childtasks, 'is_completed');
  726. if (data.parent == null) $scope.task.is_completed = is_completed;
  727. }, function (err) {
  728. showPopup.PopupWindow(0, 'mark task fail!', false);
  729. }).$promise.finally(function (res) {
  730. showPopup.hideLoading();
  731. })
  732. }
  733. function init_childtask() {
  734. var childtask = {
  735. content: '',
  736. end_dd: null,
  737. is_completed: 0,
  738. leader: null,
  739. parent: parseInt($stateParams.id),
  740. task_members: []
  741. };
  742. return childtask;
  743. }
  744. function init_comment() {
  745. return {"content": ''};
  746. }
  747. function getTaskComments() {
  748. Task.taskcomment($scope.nexturl.comment).get({'task_id': $stateParams.id}, function (res) {
  749. if ($scope.nexturl.comment != null)
  750. $scope.taskcomments = $scope.taskcomments.concat(res.results);
  751. else
  752. $scope.taskcomments = res.results;
  753. $scope.nexturl.comment = res.next;
  754. }).$promise.finally(function (f) {
  755. $scope.$broadcast('scroll.infiniteScrollComplete');
  756. });
  757. }
  758. function gettaskhistory() {
  759. Task.taskhistory($scope.nexturl.history).get({'task_id': $stateParams.id}, function (res) {
  760. if ($scope.nexturl.history != null)
  761. $scope.taskhistory = $scope.taskhistory.concat(res.results);
  762. else
  763. $scope.taskhistory = res.results;
  764. $scope.nexturl.history = res.next;
  765. }).$promise.finally(function (f) {
  766. $scope.$broadcast('scroll.infiniteScrollComplete');
  767. });
  768. }
  769. })
  770. .controller('TaskSetCtrl', function ($rootScope, $scope, $state, $cordovaDatePicker, $ionicHistory,
  771. $timeout, $q, _, global, showPopup, Task, Member, ImageManage, Tool, formatFilter) {
  772. var id = $state.params['id'];
  773. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  774. $scope.popup = {
  775. isPopup: false,
  776. isSetPopup: false
  777. };
  778. if (Member.selectedemplst.length > 0) {
  779. _.each(Member.selectedemplst, function (item) {
  780. item.is_leader = 'F';
  781. $scope.task.task_members.push(item)
  782. });
  783. Member.selectedemplst = [];
  784. update_task();
  785. } else {
  786. $scope.task = angular.copy(Task.taskdetail);
  787. $scope.user = global.user;
  788. $scope.task.task_members = _.sortBy(_.map($scope.task.task_members, function (item) {
  789. return {'user_id': item.user.id, 'username': item.user.username, 'is_leader': item.is_leader};
  790. }), 'is_leader').reverse();
  791. $scope.contentdata = $scope.task.content;
  792. }
  793. //获取是否为发布人
  794. $scope.Isheader = $state.params['isheader'] == '1';
  795. });
  796. $scope.showModal = function (type) {
  797. $scope.isremove = false;
  798. var templateurl = type == 'select' ? 'templates/modal-selectadmin.html' : 'templates/modal-content.html';
  799. showPopup.modalTemplate(templateurl, 'slide-in-right', $scope).then(function (modal) {
  800. $rootScope.commons.modal = modal;
  801. $rootScope.commons.modal.show();
  802. if (type == "content") $rootScope.commons.fun = clear_change;
  803. })
  804. };
  805. $scope.closeModal = function (type, flag) {
  806. $rootScope.commons.fun = null;
  807. $rootScope.commons.modal.hide();
  808. if (flag) clear_change();
  809. };
  810. $scope.selectmember = function () {
  811. $scope.isremove = false;
  812. Member.resourcemember = $scope.task.task_members;
  813. Member.routename = '';
  814. Member.titlename = '选择任务成员';
  815. $state.go('selectmember');
  816. };
  817. $scope.remove = function (_user, index) {
  818. if ($scope.task.task_members.length == 1) {
  819. showPopup.PopupWindow(0, '负责人不能为空', false);
  820. $scope.isremove = false;
  821. return;
  822. }
  823. $scope.task.task_members.splice(index, 1);
  824. update_task();
  825. };
  826. $scope.isremove = false;
  827. $scope.changeRemove = function (flag) {
  828. $scope.isremove = !flag;
  829. };
  830. $scope.changeAdmin = function (_user, index) {
  831. $scope.isremove = false;
  832. $scope.task.task_members.splice(index, 1);
  833. $scope.task.task_members.splice(0, 0, _user);
  834. _.each($scope.task.task_members, function (item) {
  835. item.is_leader = 'F';
  836. });
  837. _user.is_leader = 'T';
  838. $scope.task.leader.id = _user.user_id;
  839. update_task();
  840. };
  841. $scope.updatecontent = function () {
  842. if ($scope.image_list.length > 0) {
  843. showPopup.showLoading(1, '', false, 20000);
  844. ImageManage.uploadImage($scope.image_list, 'task', $scope.task.id, 'taskfile').then(function (res) {
  845. $q.all(res).then(function (res1) {
  846. $scope.image_list = [];
  847. $scope.task.task_files = _.sortBy($scope.task.task_files.concat(_.map(res1, function (item) {
  848. return JSON.parse(item.response);
  849. })), 'id');
  850. });
  851. update_task();
  852. })
  853. } else {
  854. update_task();
  855. }
  856. $rootScope.commons.fun = null;
  857. };
  858. var flag = true;
  859. $scope.chooseDate = function () {
  860. if (flag) {
  861. flag = false;
  862. var options = {
  863. mode: 'date',
  864. date: $scope.task.end_dd == null ? new Date() : new Date($scope.task.end_dd),
  865. androidTheme: 3
  866. };
  867. $cordovaDatePicker.show(options).then(function (date) {
  868. if (date == undefined) return;
  869. $scope.task.end_dd = date;
  870. update_task();
  871. flag = true;
  872. }, function (cancel) {
  873. flag = true;
  874. });
  875. }
  876. };
  877. $scope.deleteTask = function () {
  878. if ($scope.Isheader) {
  879. $scope.popup.isPopup = true;
  880. showPopup.confirm('是否删除该任务?', '是', '否').then(function (res) {
  881. if (res) {
  882. showPopup.showLoading(1, '', false);
  883. Task.task(null).delete({'id': $scope.task.id}, function (data) {
  884. $ionicHistory.goBack(-2);
  885. }, function (err) {
  886. showPopup.PopupWindow(0, 'delete task fail!', false);
  887. }).$promise.finally(function (f) {
  888. showPopup.hideLoading();
  889. });
  890. }
  891. })
  892. } else {
  893. //任务成员退出任务
  894. $scope.task.task_members.splice(_.findIndex($scope.task.task_members, {'user_id': global.user.usrid}), 1);
  895. update_task();
  896. $ionicHistory.goBack(-2);
  897. }
  898. };
  899. $scope.image_list = [];
  900. $scope.del_image_list = [];
  901. $scope.shouBigImage = function (imageName) {
  902. $scope.Url = imageName;
  903. $rootScope.commons.bigImage = true;
  904. };
  905. $rootScope.commons.bigImage = false;
  906. $scope.hideBigImage = function () {
  907. $rootScope.commons.bigImage = false;
  908. };
  909. $scope.deleteimage = function () {
  910. if (_.indexOf($scope.image_list, $scope.Url) >= 0) {
  911. $scope.image_list.splice(_.indexOf($scope.image_list, $scope.Url), 1);
  912. } else {
  913. var index = _.findIndex($scope.task.task_files, {'file_full_path': $scope.Url});
  914. $scope.del_image_list.push($scope.task.task_files[index].id);
  915. $scope.task.task_files.splice(index, 1);
  916. }
  917. $rootScope.commons.bigImage = false;
  918. };
  919. $scope.addphoto = function () {
  920. if (($scope.image_list.length + $scope.task.task_files.length) == $rootScope.commons.upload_maxcount) {
  921. showPopup.PopupWindow(0, formatFilter('最多可上传{0}张!', $rootScope.commons.upload_maxcount), false);
  922. return;
  923. }
  924. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  925. $scope.popup.isSetPopup = true;
  926. };
  927. function ImagePicker() { //打开相册
  928. $scope.popup.optionsPopup.close();
  929. ImageManage.ImagePicker_getPictures($rootScope.commons.upload_maxcount - ($scope.image_list.length + $scope.task.task_files.length)).then(function (promises) {
  930. if (promises.length == 0) return;
  931. $q.all(promises).then(function (res) {
  932. $scope.image_list = $scope.image_list.concat(res);
  933. }, function (error) {
  934. alert(error);
  935. });
  936. });
  937. }
  938. function Camera() {
  939. $scope.popup.optionsPopup.close();
  940. ImageManage.Camera_getPicture().then(function (result) {
  941. $scope.image_list.push(result);
  942. });
  943. }
  944. function update_task() {
  945. var task = angular.copy($scope.task);
  946. task.task_files = $scope.del_image_list;
  947. task.leader = task.leader.id;
  948. task = _.omit(task, 'create_user', 'childtasks', 'membernames');
  949. task.task_members = _.map(task.task_members, function (item) {
  950. return {'is_leader': item.is_leader, 'user': item.user_id};
  951. });
  952. showPopup.showLoading(1, '', false);
  953. Task.task(null).update({'id': task.id}, task, function (data) {
  954. if ($rootScope.commons.modal != null) {
  955. $rootScope.commons.modal.hide();
  956. $rootScope.commons.modal = null;
  957. }
  958. }, function (err) {
  959. showPopup.PopupWindow(0, 'update task fail!', false);
  960. }).$promise.finally(function (f) {
  961. showPopup.hideLoading();
  962. });
  963. }
  964. function clear_change() {
  965. $scope.task.content = Task.taskdetail.content;
  966. $scope.task.task_files = angular.copy(Task.taskdetail.task_files);
  967. $scope.image_list = [];
  968. if ($rootScope.commons.bigImage) {
  969. $rootScope.commons.bigImage = false;
  970. } else {
  971. $rootScope.commons.modal.hide();
  972. $rootScope.commons.modal = null;
  973. }
  974. }
  975. $scope.$on("$destroy", function () {
  976. beforeEnter = null;
  977. if ($rootScope.commons.modal != null) $rootScope.commons.modal.remove();
  978. Member.resourcemember = [];
  979. $rootScope.commons.fun = null;
  980. })
  981. })
  982. .controller('EditChildTaskCtrl', function ($scope, $state, $stateParams, $cordovaDatePicker, $timeout, $ionicHistory, $rootScope, Task, Member, showPopup, formatFilter, Tool) {
  983. $scope.data = _.pick(Task.taskdetail, 'childtasks', 'task_members');
  984. $scope.task = _.find($scope.data.childtasks, function (c) {
  985. return parseInt(c.id) == parseInt($stateParams.id)
  986. });
  987. $scope.task.task_members = $scope.data.task_members;
  988. $scope.childcontent = $scope.task.content;
  989. $scope.openmodal = function (type) {
  990. if (type == 'childcontent') $rootScope.commons.fun = clear_change;
  991. showPopup.modalTemplate(formatFilter('templates/modal-{0}.html', type), 'slide-in-right', $scope).then(function (modal) {
  992. $rootScope.commons.modal = modal;
  993. $rootScope.commons.modal.show();
  994. })
  995. };
  996. $scope.closeModal = function () {
  997. $rootScope.commons.modal.hide();
  998. $rootScope.commons.fun = null;
  999. };
  1000. // Cleanup the modal when we're done with it!
  1001. $scope.$on('$destroy', function () {
  1002. if ($rootScope.commons.modal != null) {
  1003. $rootScope.commons.modal.remove();
  1004. $rootScope.commons.modal = null;
  1005. }
  1006. });
  1007. $scope.checkend_dd = function () {
  1008. var options = {
  1009. mode: 'date',
  1010. date: $scope.task.end_dd == null ? new Date() : $scope.task.end_dd,
  1011. androidTheme: 3
  1012. };
  1013. $cordovaDatePicker.show(options).then(function (date) {
  1014. $timeout(function () {
  1015. if (date == undefined) return;
  1016. $scope.task.end_dd = date;
  1017. showPopup.showLoading(1, '', false);
  1018. Task.task(null).update({'id': $scope.task.id}, set_task(), function (data) {
  1019. $rootScope.commons.modal.hide();
  1020. }, function (err) {
  1021. showPopup.PopupWindow(0, 'fail', false);
  1022. }).$promise.finally(function (f) {
  1023. showPopup.hideLoading();
  1024. });
  1025. });
  1026. });
  1027. };
  1028. $scope.changeAdmin = function (user) {
  1029. var task = set_task();
  1030. task.leader = user.user.id;
  1031. showPopup.showLoading(1, '', false);
  1032. Task.task(null).update({'id': task.id}, task, function (data) {
  1033. $scope.task.leader = data.leader;
  1034. }, function (err) {
  1035. showPopup.PopupWindow(0, 'fail', false);
  1036. }).$promise.finally(function (f) {
  1037. $scope.closeModal();
  1038. showPopup.hideLoading();
  1039. });
  1040. };
  1041. $scope.cancel = function () {
  1042. $scope.task.content = $scope.childcontent;
  1043. $rootScope.commons.modal.hide();
  1044. };
  1045. $scope.ok = function () {
  1046. if ($scope.task.content == '') {
  1047. showPopup.PopupWindow(0, '请输入任务内容!', false);
  1048. return;
  1049. }
  1050. showPopup.showLoading(1, '', false);
  1051. Task.task(null).update({'id': $scope.task.id}, set_task(), function (data) {
  1052. $scope.closeModal();
  1053. }, function (err) {
  1054. showPopup.PopupWindow(0, 'fail', false);
  1055. }).$promise.finally(function (f) {
  1056. showPopup.hideLoading();
  1057. });
  1058. };
  1059. $scope.deletechildTask = function () {
  1060. showPopup.confirm('是否删除该任务?', '是', '否').then(function (res) {
  1061. if (res) {
  1062. showPopup.showLoading(1, '', false);
  1063. Task.task(null).delete({'id': $stateParams.id}, function (data) {
  1064. $scope.data.childtasks.splice(_.indexOf($scope.data.childtasks, $scope.task), 1);
  1065. $ionicHistory.goBack();
  1066. }, function (err) {
  1067. showPopup.PopupWindow(0, 'fail', false);
  1068. }).$promise.finally(function (f) {
  1069. showPopup.hideLoading();
  1070. });
  1071. }
  1072. })
  1073. };
  1074. function clear_change() {
  1075. $scope.task.content = $scope.childcontent;
  1076. $rootScope.commons.modal.hide();
  1077. $rootScope.commons.modal.remove();
  1078. $rootScope.commons.modal = null;
  1079. }
  1080. function set_task() {
  1081. var task = angular.copy($scope.task);
  1082. task.leader = task.leader.id;
  1083. task.task_members = [];
  1084. return task;
  1085. }
  1086. })