controllers.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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($scope.Task, item.key).reverse();
  184. $scope.Task = _.sortBy($scope.Task, 'is_completed');
  185. $scope.rightdata[0].key = item.key;
  186. }
  187. } else {
  188. if ($scope.rightdata[1].id == item.id) {
  189. setrightcheck(false, true);
  190. Member.titlename = "选择单个成员";
  191. Member.routename = 'postedtask';
  192. Member.selectedemplst = [];
  193. $state.go('selectsinglemember');
  194. } else {
  195. $scope.nexturl = null;
  196. getdata();//all
  197. $scope.title[1].name = "全部成员";
  198. $scope.rightdata[1].name = '选择单个成员';
  199. setrightcheck(true, false);
  200. }
  201. }
  202. $scope.backhide();
  203. };
  204. $scope.todetails = function (item) {
  205. $state.go('task-details', {
  206. id: item.id
  207. });
  208. };
  209. $scope.loadMore = function () {
  210. if ($scope.nexturl != null) getdata();
  211. };
  212. function setrightcheck(allcheck, singlecheck) {
  213. $scope.rightdata[0].check = allcheck;
  214. $scope.rightdata[1].check = singlecheck;
  215. }
  216. function getdata(usrid) {
  217. var data = {'type': 'posted'};
  218. if (usrid != undefined)
  219. data.usrid = usrid;
  220. Task.task($scope.nexturl).get(data, function (res) {
  221. $scope.totalcount = res.count;
  222. var olddata = [];
  223. if ($scope.nexturl != null) {
  224. olddata = _.map($scope.Task, _.clone);
  225. }
  226. $scope.nexturl = res.next;
  227. $scope.Task = _.sortBy(res.results, 'is_completed');
  228. $scope.Task = olddata.concat($scope.Task);
  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 = Tool.cloneObj($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 (data) {
  637. $scope.image_list = $scope.image_list.concat(data);
  638. });
  639. };
  640. $scope.Camera = function () {
  641. if (!check_image()) return;
  642. ImageManage.Camera_getPicture().then(function (result) {
  643. $scope.image_list.push(result);
  644. });
  645. };
  646. $scope.shouBigImage = function (imageName, event) { //传递一个参数(图片的URl)
  647. if (event != undefined) {
  648. event.stopPropagation();
  649. }
  650. $scope.Url = imageName;
  651. $rootScope.commons.bigImage = true;
  652. };
  653. $scope.stopPropagation = function (event) {
  654. if (event != undefined) {
  655. event.stopPropagation();
  656. }
  657. }
  658. $rootScope.commons.bigImage = false; //初始默认大图是隐藏的
  659. $scope.hideBigImage = function () {
  660. $rootScope.commons.bigImage = false;
  661. };
  662. $scope.deleteimage = function () {
  663. $scope.image_list.splice(_.indexOf($scope.image_list, $scope.Url), 1);
  664. $rootScope.commons.bigImage = false;
  665. };
  666. $scope.nexturl = {'comment': null, 'history': null};
  667. $scope.loadMore = function (type) {
  668. if (type == 'history') {
  669. gettaskhistory();
  670. } else {
  671. getTaskComments();
  672. }
  673. };
  674. function check_image() {
  675. if ($scope.image_list.length >= 10) {
  676. showPopup.PopupWindow(0, formatFilter('最多可上传{0}张', $rootScope.commons.upload_maxcount), false);
  677. return false
  678. }
  679. return true;
  680. }
  681. function getTaskDetails() {
  682. Task.task(null).get({'id': $stateParams.id}, function (data) {
  683. $scope.data = Tool.cloneObj(data);
  684. var members = _.filter(data.task_members, function (item) {
  685. return data.leader.id != item.user.id;
  686. });
  687. data.membernames = _.map(members, function (m) {
  688. if (data.leader.id != m.user.id) return m.user.username;
  689. }).join('、');
  690. $scope.task = data;
  691. $scope.Isheader = ($scope.task.create_user.id == global.user.usrid);
  692. if ((data.create_user.id == global.user.usrid) || (data.leader.id == global.user.usrid)) {
  693. $scope.is_disabledmark = false;
  694. } else {
  695. Task.taskpreferences.get({'key': 'task_rule'}, function (data) {
  696. $scope.is_disabledmark = Boolean(data.value);
  697. });
  698. }
  699. }, function (err) {
  700. console.log(err)
  701. }).$promise.finally(function (res) {
  702. $scope.loading = false;
  703. });
  704. //get child task
  705. Task.taskchild.get({'id': $stateParams.id}, function (res) {
  706. $scope.childtasks = _.sortBy(res.results, 'is_completed');
  707. })
  708. }
  709. function marktask(data, is_completed) {
  710. var task = Tool.cloneObj(data);
  711. task.leader = task.leader.id;
  712. task = _.omit(task, 'create_user', 'childtasks', 'task_files');
  713. task.task_members = _.map(task.task_members, function (item) {
  714. return {'is_leader': item.is_leader, 'user': item.user.id};
  715. });
  716. task.is_completed = is_completed;
  717. showPopup.showLoading(1, '', false);
  718. Task.task(null).update({'id': task.id}, task, function (data) {
  719. $scope.nexturl.history = null;
  720. gettaskhistory();
  721. $scope.childtasks = _.sortBy($scope.childtasks, 'is_completed');
  722. if (data.parent == null) $scope.task.is_completed = is_completed;
  723. }, function (err) {
  724. showPopup.PopupWindow(0, 'mark task fail!', false);
  725. }).$promise.finally(function (res) {
  726. showPopup.hideLoading();
  727. })
  728. }
  729. function init_childtask() {
  730. var childtask = {
  731. content: '',
  732. end_dd: null,
  733. is_completed: 0,
  734. leader: null,
  735. parent: parseInt($stateParams.id),
  736. task_members: []
  737. };
  738. return childtask;
  739. }
  740. function init_comment() {
  741. return {"content": ''};
  742. }
  743. function getTaskComments() {
  744. Task.taskcomment($scope.nexturl.comment).get({'task_id': $stateParams.id}, function (res) {
  745. if ($scope.nexturl.comment != null)
  746. $scope.taskcomments = $scope.taskcomments.concat(res.results);
  747. else
  748. $scope.taskcomments = res.results;
  749. $scope.nexturl.comment = res.next;
  750. }).$promise.finally(function (f) {
  751. $scope.$broadcast('scroll.infiniteScrollComplete');
  752. });
  753. }
  754. function gettaskhistory() {
  755. Task.taskhistory($scope.nexturl.history).get({'task_id': $stateParams.id}, function (res) {
  756. if ($scope.nexturl.history != null)
  757. $scope.taskhistory = $scope.taskhistory.concat(res.results);
  758. else
  759. $scope.taskhistory = res.results;
  760. $scope.nexturl.history = res.next;
  761. }).$promise.finally(function (f) {
  762. $scope.$broadcast('scroll.infiniteScrollComplete');
  763. });
  764. }
  765. })
  766. .controller('TaskSetCtrl', function ($rootScope, $scope, $state, $cordovaDatePicker, $ionicHistory,
  767. $timeout, $q, _, global, showPopup, Task, Member, ImageManage, Tool, formatFilter) {
  768. var id = $state.params['id'];
  769. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  770. $scope.popup = {
  771. isPopup: false,
  772. isSetPopup: false
  773. };
  774. if (Member.selectedemplst.length > 0) {
  775. _.each(Member.selectedemplst, function (item) {
  776. item.is_leader = 'F';
  777. $scope.task.task_members.push(item)
  778. });
  779. Member.selectedemplst = [];
  780. update_task();
  781. } else {
  782. $scope.task = Tool.cloneObj(Task.taskdetail);
  783. $scope.user = global.user;
  784. $scope.task.task_members = _.sortBy(_.map($scope.task.task_members, function (item) {
  785. return {'user_id': item.user.id, 'username': item.user.username, 'is_leader': item.is_leader};
  786. }), 'is_leader').reverse();
  787. $scope.contentdata = $scope.task.content;
  788. }
  789. //获取是否为发布人
  790. $scope.Isheader = Boolean($state.params['isheader']);
  791. });
  792. $scope.showModal = function (type) {
  793. $scope.isremove = false;
  794. var templateurl = type == 'select' ? 'templates/modal-selectadmin.html' : 'templates/modal-content.html';
  795. showPopup.modalTemplate(templateurl, 'slide-in-right', $scope).then(function (modal) {
  796. $rootScope.commons.modal = modal;
  797. $rootScope.commons.modal.show();
  798. if (type == "content") $rootScope.commons.fun = clear_change;
  799. })
  800. };
  801. $scope.closeModal = function (type, flag) {
  802. $rootScope.commons.fun = null;
  803. $rootScope.commons.modal.hide();
  804. if (flag) clear_change();
  805. };
  806. function clear_change() {
  807. $scope.task.content = Task.taskdetail.content;
  808. $scope.task.task_files = Tool.cloneObj(Task.taskdetail.task_files);
  809. $scope.image_list = [];
  810. if ($rootScope.commons.bigImage) {
  811. $rootScope.commons.bigImage = false;
  812. } else {
  813. $rootScope.commons.modal.hide();
  814. $rootScope.commons.modal = null;
  815. }
  816. }
  817. $scope.selectmember = function () {
  818. $scope.isremove = false;
  819. Member.resourcemember = $scope.task.task_members;
  820. Member.routename = '';
  821. Member.titlename = '选择任务成员';
  822. $state.go('selectmember');
  823. };
  824. $scope.remove = function (_user, index) {
  825. if ($scope.task.task_members.length == 1) {
  826. showPopup.PopupWindow(0, '负责人不能为空', false);
  827. $scope.isremove = false;
  828. return;
  829. }
  830. $scope.task.task_members.splice(index, 1);
  831. update_task();
  832. };
  833. $scope.isremove = false;
  834. $scope.changeRemove = function (flag) {
  835. $scope.isremove = !flag;
  836. };
  837. $scope.changeAdmin = function (_user, index) {
  838. $scope.isremove = false;
  839. $scope.task.task_members.splice(index, 1);
  840. $scope.task.task_members.splice(0, 0, _user);
  841. _.each($scope.task.task_members, function (item) {
  842. item.is_leader = 'F';
  843. });
  844. _user.is_leader = 'T';
  845. $scope.task.leader.id = _user.user_id;
  846. update_task();
  847. };
  848. $scope.updatecontent = function () {
  849. if ($scope.image_list.length > 0) {
  850. showPopup.showLoading(1, '', false, 20000);
  851. ImageManage.uploadImage($scope.image_list, 'task', $scope.task.id, 'taskfile').then(function (res) {
  852. $q.all(res).then(function (res1) {
  853. $scope.image_list = [];
  854. $scope.task.task_files = _.sortBy($scope.task.task_files.concat(_.map(res1, function (item) {
  855. return JSON.parse(item.response);
  856. })), 'id');
  857. });
  858. update_task();
  859. })
  860. } else {
  861. update_task();
  862. }
  863. $rootScope.commons.fun = null;
  864. };
  865. var flag = true;
  866. $scope.chooseDate = function () {
  867. if (flag) {
  868. flag = false;
  869. var options = {
  870. mode: 'date',
  871. date: $scope.task.end_dd == null ? new Date() : new Date($scope.task.end_dd),
  872. androidTheme: 3
  873. };
  874. $cordovaDatePicker.show(options).then(function (date) {
  875. if (date == undefined) return;
  876. $scope.task.end_dd = date;
  877. update_task();
  878. flag = true;
  879. }, function (cancel) {
  880. flag = true;
  881. });
  882. }
  883. };
  884. $scope.deleteTask = function () {
  885. if ($scope.Isheader) {
  886. $scope.popup.isPopup = true;
  887. showPopup.confirm('是否删除该任务?', '是', '否').then(function (res) {
  888. if (res) {
  889. showPopup.showLoading(1, '', false);
  890. Task.task(null).delete({'id': $scope.task.id}, function (data) {
  891. $ionicHistory.goBack(-2);
  892. }, function (err) {
  893. showPopup.PopupWindow(0, 'delete task fail!', false);
  894. }).$promise.finally(function (f) {
  895. showPopup.hideLoading();
  896. });
  897. }
  898. })
  899. } else {
  900. //任务成员退出任务
  901. $scope.task.task_members.splice(_.findIndex($scope.task.task_members, {'user_id': global.user.usrid}), 1);
  902. update_task();
  903. $ionicHistory.goBack(-2);
  904. }
  905. };
  906. $scope.image_list = [];
  907. $scope.del_image_list = [];
  908. $scope.shouBigImage = function (imageName) {
  909. $scope.Url = imageName;
  910. $rootScope.commons.bigImage = true;
  911. };
  912. $rootScope.commons.bigImage = false;
  913. $scope.hideBigImage = function () {
  914. $rootScope.commons.bigImage = false;
  915. };
  916. $scope.deleteimage = function () {
  917. if (_.indexOf($scope.image_list, $scope.Url) >= 0) {
  918. $scope.image_list.splice(_.indexOf($scope.image_list, $scope.Url), 1);
  919. } else {
  920. var index = _.findIndex($scope.task.task_files, {'file_full_path': $scope.Url});
  921. $scope.del_image_list.push($scope.task.task_files[index].id);
  922. $scope.task.task_files.splice(index, 1);
  923. }
  924. $rootScope.commons.bigImage = false;
  925. };
  926. $scope.addphoto = function () {
  927. if (($scope.image_list.length + $scope.task.task_files.length) == $rootScope.commons.upload_maxcount) {
  928. showPopup.PopupWindow(0, formatFilter('最多可上传{0}张!', $rootScope.commons.upload_maxcount), false);
  929. return;
  930. }
  931. $scope.popup.optionsPopup = showPopup.showSelectImgPopup(Camera, ImagePicker, $scope);
  932. $scope.popup.isSetPopup = true;
  933. };
  934. function ImagePicker() { //打开相册
  935. $scope.popup.optionsPopup.close();
  936. ImageManage.ImagePicker_getPictures($rootScope.commons.upload_maxcount - ($scope.image_list.length + $scope.task.task_files.length)).then(function (data) {
  937. if (data.length == 0) return;
  938. $scope.image_list = $scope.image_list.concat(data);
  939. });
  940. }
  941. function Camera() {
  942. $scope.popup.optionsPopup.close();
  943. ImageManage.Camera_getPicture().then(function (result) {
  944. $scope.image_list.push(result);
  945. });
  946. }
  947. function update_task() {
  948. var task = Tool.cloneObj($scope.task);
  949. task.task_files = $scope.del_image_list;
  950. task.leader = task.leader.id;
  951. task = _.omit(task, 'create_user', 'childtasks', 'membernames');
  952. task.task_members = _.map(task.task_members, function (item) {
  953. return {'is_leader': item.is_leader, 'user': item.user_id};
  954. });
  955. showPopup.showLoading(1, '', false);
  956. Task.task(null).update({'id': task.id}, task, function (data) {
  957. if ($rootScope.commons.modal != null) {
  958. $rootScope.commons.modal.hide();
  959. $rootScope.commons.modal = null;
  960. }
  961. }, function (err) {
  962. showPopup.PopupWindow(0, 'update task fail!', false);
  963. }).$promise.finally(function (f) {
  964. showPopup.hideLoading();
  965. });
  966. }
  967. $scope.$on("$destroy", function () {
  968. beforeEnter = null;
  969. if ($rootScope.commons.modal != null) $rootScope.commons.modal.remove();
  970. Member.resourcemember = [];
  971. $rootScope.commons.fun = null;
  972. })
  973. })
  974. .controller('EditChildTaskCtrl', function ($scope, $state, $stateParams, $cordovaDatePicker, $timeout, $ionicHistory, $rootScope, Task, Member, showPopup, formatFilter, Tool) {
  975. $scope.data = _.pick(Task.taskdetail, 'childtasks', 'task_members');
  976. $scope.task = _.find($scope.data.childtasks, function (c) {
  977. return parseInt(c.id) == parseInt($stateParams.id)
  978. });
  979. $scope.task.task_members = $scope.data.task_members;
  980. $scope.childcontent = $scope.task.content;
  981. $scope.openmodal = function (type) {
  982. if (type == 'childcontent') $rootScope.commons.fun = clear_change;
  983. showPopup.modalTemplate(formatFilter('templates/modal-{0}.html', type), 'slide-in-right', $scope).then(function (modal) {
  984. $rootScope.commons.modal = modal;
  985. $rootScope.commons.modal.show();
  986. })
  987. };
  988. $scope.closeModal = function () {
  989. $rootScope.commons.modal.hide();
  990. $rootScope.commons.fun = null;
  991. };
  992. // Cleanup the modal when we're done with it!
  993. $scope.$on('$destroy', function () {
  994. if ($rootScope.commons.modal != null) {
  995. $rootScope.commons.modal.remove();
  996. $rootScope.commons.modal = null;
  997. }
  998. });
  999. $scope.checkend_dd = function () {
  1000. var options = {
  1001. mode: 'date',
  1002. date: $scope.task.end_dd == null ? new Date() : $scope.task.end_dd,
  1003. androidTheme: 3
  1004. };
  1005. $cordovaDatePicker.show(options).then(function (date) {
  1006. $timeout(function () {
  1007. if (date == undefined) return;
  1008. $scope.task.end_dd = date;
  1009. showPopup.showLoading(1, '', false);
  1010. Task.task(null).update({'id': $scope.task.id}, set_task(), function (data) {
  1011. $rootScope.commons.modal.hide();
  1012. }, function (err) {
  1013. showPopup.PopupWindow(0, 'fail', false);
  1014. }).$promise.finally(function (f) {
  1015. showPopup.hideLoading();
  1016. });
  1017. });
  1018. });
  1019. };
  1020. $scope.changeAdmin = function (user) {
  1021. var task = set_task();
  1022. task.leader = user.user.id;
  1023. showPopup.showLoading(1, '', false);
  1024. Task.task(null).update({'id': task.id}, task, function (data) {
  1025. $scope.task.leader = data.leader;
  1026. }, function (err) {
  1027. showPopup.PopupWindow(0, 'fail', false);
  1028. }).$promise.finally(function (f) {
  1029. $scope.closeModal();
  1030. showPopup.hideLoading();
  1031. });
  1032. };
  1033. $scope.cancel = function () {
  1034. $scope.task.content = $scope.childcontent;
  1035. $rootScope.commons.modal.hide();
  1036. };
  1037. $scope.ok = function () {
  1038. if ($scope.task.content == '') {
  1039. showPopup.PopupWindow(0, '请输入任务内容!', false);
  1040. return;
  1041. }
  1042. showPopup.showLoading(1, '', false);
  1043. Task.task(null).update({'id': $scope.task.id}, set_task(), function (data) {
  1044. $scope.closeModal();
  1045. }, function (err) {
  1046. showPopup.PopupWindow(0, 'fail', false);
  1047. }).$promise.finally(function (f) {
  1048. showPopup.hideLoading();
  1049. });
  1050. };
  1051. $scope.deletechildTask = function () {
  1052. showPopup.confirm('是否删除该任务?', '是', '否').then(function (res) {
  1053. if (res) {
  1054. showPopup.showLoading(1, '', false);
  1055. Task.task(null).delete({'id': $stateParams.id}, function (data) {
  1056. $scope.data.childtasks.splice(_.indexOf($scope.data.childtasks, $scope.task), 1);
  1057. $ionicHistory.goBack();
  1058. }, function (err) {
  1059. showPopup.PopupWindow(0, 'fail', false);
  1060. }).$promise.finally(function (f) {
  1061. showPopup.hideLoading();
  1062. });
  1063. }
  1064. })
  1065. };
  1066. function clear_change() {
  1067. $scope.task.content = $scope.childcontent;
  1068. $rootScope.commons.modal.hide();
  1069. $rootScope.commons.modal.remove();
  1070. $rootScope.commons.modal = null;
  1071. }
  1072. function set_task() {
  1073. var task = Tool.cloneObj($scope.task);
  1074. task.leader = task.leader.id;
  1075. task.task_members = [];
  1076. return task;
  1077. }
  1078. })