controllers.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. starter.controller('WorkFlowCtrl', function ($scope, $state, global) {
  2. $scope.goBack = function () {
  3. global.goBack();
  4. };
  5. $scope.toman = function () {
  6. $state.go('workflow-manage');
  7. };
  8. $scope.toapply = function () {
  9. $state.go('workflow-apply');
  10. };
  11. })
  12. .controller('WorkFlowManageCtrl', function ($scope, global, WorkFlow, Tool) {
  13. $scope.ordering = false;
  14. global.fetch_user().then(function () {
  15. if (!$scope.templates) $scope.loading = true;
  16. WorkFlow.templates.get({'type': 1}, function (res) {
  17. $scope.templates = res;
  18. }, function (err) {
  19. alert(JSON.stringify(err));
  20. }
  21. ).$promise.finally(function (f) {
  22. $scope.loading = false;
  23. })
  24. });
  25. $scope.ordering = function () {
  26. $scope.ordering = !$scope.ordering;
  27. };
  28. $scope.loadMore = function () {
  29. Tool.get_nextpage($scope.templates.nexturl).then(function (res) {
  30. var old_data = angular.copy($scope.templates.results);
  31. $scope.templates = res;
  32. $scope.templates.results = old_data.concat(res.results);
  33. }).finally(function (f) {
  34. $scope.$broadcast('scroll.infiniteScrollComplete');
  35. })
  36. }
  37. })
  38. .controller('WorkFlowTemplateCreateCtrl', function ($scope, $stateParams, $state, $ionicSlideBoxDelegate, $ionicHistory, $rootScope, global, Member, WorkFlow, showPopup, Tool) {
  39. $scope.datatext = {
  40. leftbtn: [{
  41. text: '取消',
  42. click: "cancel",
  43. params: "c"
  44. }, {
  45. text: '上一步',
  46. click: 'back'
  47. }],
  48. rightbtn: [{
  49. text: '下一步',
  50. click: 'down'
  51. }, {
  52. text: '完成',
  53. click: 'ok'
  54. }]
  55. };
  56. $scope.titleName = ['填写流程名称', '选择流程模板', '创建审批人步骤', '添加流程介绍'];
  57. $scope.leftIndex = 0;
  58. $scope.rightIndex = 0;
  59. $scope.activeIndex = 0;
  60. $scope.template = WorkFlow.templatedata;
  61. var beforeEnter = $scope.$on("$ionicView.beforeEnter", function () {
  62. if (Member.customerop == "cc" && Member.selectedemplst.length > 0)
  63. $scope.template.cc = $scope.template.cc.concat(Member.selectedemplst);
  64. else if (Member.customerop == "permission" && Member.selectedemplst.length > 0) {
  65. $scope.template.permission.users = $scope.template.permission.users.concat(Member.selectedemplst);
  66. $scope.template.permission.all = false;
  67. }
  68. Member.customerop = null;
  69. });
  70. global.fetch_user().then(function () {
  71. WorkFlow.templates.query({'type': 0}, function (data) {
  72. var temp_templates = _.map(data, function (item) {
  73. return _.extend(item, {'show': false});
  74. });
  75. var temps = [];
  76. $scope.templates_already = [];
  77. _.each(temp_templates, function (item, index) {
  78. if (index % 2 == 0 && index != 0) {
  79. $scope.templates_already.push(angular.copy(temps));
  80. temps = [];
  81. }
  82. temps.push(item);
  83. });
  84. if (temps.length <= 2) $scope.templates_already.push(temps);
  85. });
  86. });
  87. $scope.down = function () {
  88. if ($scope.activeIndex == 0 && Tool.trim($scope.template.name).length < 2) {
  89. showPopup.PopupWindow(0, "名称长度不能少于2!", false);
  90. return;
  91. }
  92. if ($scope.activeIndex == 2 && $scope.template.steps.length == 0) {
  93. showPopup.PopupWindow(0, "请添加审批步骤!", false);
  94. return;
  95. }
  96. $ionicSlideBoxDelegate.next();
  97. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  98. if ($scope.activeIndex >= 1) {
  99. $scope.leftIndex = 1;
  100. $scope.rightIndex = 0;
  101. if ($scope.activeIndex == 3) {
  102. $scope.rightIndex = 1;
  103. }
  104. } else {
  105. $scope.leftIndex = 0;
  106. $scope.rightIndex = 1;
  107. }
  108. };
  109. $scope.cancel = function (op) {
  110. $ionicHistory.goBack();
  111. };
  112. $scope.back = function () {
  113. if ($scope.activeIndex != 0) {
  114. $ionicSlideBoxDelegate.previous();
  115. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  116. $scope.rightIndex = 0;
  117. if ($scope.activeIndex == 0) {
  118. $scope.leftIndex = 0;
  119. }
  120. } else {
  121. $ionicHistory.goBack();
  122. }
  123. };
  124. $scope.lockSlide = function () {
  125. $ionicSlideBoxDelegate.enableSlide(false);
  126. };
  127. $scope.customer_template = {id: -1, show: true};
  128. $scope.checktemplate = function (item) {
  129. _.each(_.flatten($scope.templates_already).concat($scope.customer_template), function (item) {
  130. item.show = false;
  131. });
  132. item.show = true;
  133. };
  134. $scope.toSetItem = function (id) {
  135. if (WorkFlow.templatedata.template_id != id) WorkFlow.templatedata.items = [];
  136. WorkFlow.templatedata.template_id = id;
  137. $state.go('workflow-templateitemset', {
  138. id: id
  139. });
  140. };
  141. $scope.auditstep = {name: "", verifier: null, ordering: WorkFlow.templatedata.steps.length + 1};
  142. $scope.toaddstep = function (value) {
  143. $scope.auditsteps = WorkFlow.templatedata.steps;
  144. $scope.popup = WorkFlow.showDialog($scope, "第" + (WorkFlow.templatedata.steps.length + 1) + "步", '步骤名称', '审批人', value == undefined ? "选填" : value);
  145. $scope.popup.then(function (popup) {
  146. if (popup) {
  147. $scope.auditstep.verifier = Member.selectedemplst[0];
  148. $scope.auditsteps.push(angular.copy($scope.auditstep));
  149. $scope.auditstep.name = "";
  150. $scope.auditstep.verifier = null;
  151. Member.selectedemplst = [];
  152. }
  153. });
  154. };
  155. //选择审批人
  156. $scope.toselect = function () {
  157. $scope.popup.close();
  158. Member.routename = "";
  159. Member.selectedemplst = [];
  160. Member.emit.is_have = true;
  161. Member.emit.name = "show_popup_open";
  162. $state.go('selectsinglemember');
  163. };
  164. $scope.select_cc_or_permission = function (op) {
  165. Member.customerop = op;
  166. Member.routename = "";
  167. Member.selectedemplst = [];
  168. $state.go('selectmember');
  169. };
  170. $scope.ok_template=function () {
  171. };
  172. var p = $rootScope.$on('show_popup_open', function () {
  173. if ($scope.popup != undefined)
  174. $scope.toaddstep(Member.selectedemplst.length > 0 ? Member.selectedemplst[0].username : "选填");
  175. Member.emit = {"is_have": false, "name": ""};
  176. });
  177. $scope.$on('$destroy', function (e) {
  178. p = null;
  179. });
  180. })
  181. .controller('WorkFlowTemplateDetailCtrl', function ($scope, global, WorkFlow) {
  182. global.fetch_user().then(function () {
  183. if (!$scope.templates) $scope.loding = true;
  184. WorkFlow.templates.query(function (res) {
  185. $scope.templates = res;
  186. })
  187. })
  188. })
  189. .controller('WorkFlowApplyCtrl', function ($scope, global, WorkFlow) {
  190. })
  191. .controller('WorkFlowTemplateItemSetCtrl', function ($scope, $state, $ionicHistory, $ionicPopup, $rootScope, WorkFlow, global) {
  192. $scope.is_customer = $state.params['id'] < 0;
  193. beforeEnter = $scope.$on("$ionicView.beforeEnter", function (event, data) {
  194. $scope.template_items = WorkFlow.templatedata.items;
  195. });
  196. global.fetch_user().then(function () {
  197. if (!$scope.is_customer)
  198. WorkFlow.templateitem.query({"template_id": $state.params['id']}, function (data) {
  199. $scope.template_items = data;
  200. WorkFlow.templatedata.items = data;
  201. }, function (err) {
  202. alert(JSON.stringify(err))
  203. }).$promise.finally(function (f) {
  204. });
  205. });
  206. $scope.ok = function () {
  207. $ionicHistory.goBack();
  208. };
  209. $scope.cancel = function () {
  210. $ionicHistory.goBack();
  211. };
  212. $scope.toSetItem = function (id) {
  213. $state.go('workflow-templateitemfield', {id: id});
  214. };
  215. $scope.$on("$destroy", function () {
  216. beforeEnter = null;
  217. });
  218. })
  219. .controller('FormFieldTypeCtrl', function ($scope, $state, $ionicHistory, global, WorkFlow, showPopup) {
  220. $scope.isNew = $state.params['id'] < 0;
  221. $scope.template_item = $scope.isNew ? {name: "", required: true, t__type: 1, extra: "", select_texts: []} : angular.copy(_.find(WorkFlow.templatedata.items, {'id': id}));
  222. global.fetch_user().then(function () {
  223. WorkFlow.templatefield.get(function (res) {
  224. $scope.template_fields = _.map(res.results, function (item) {
  225. return _.extend(item, {'checked': false});
  226. });
  227. if ($scope.isNew) {
  228. $scope.template_field_active = $scope.template_fields[0];
  229. $scope.template_field_active.checked = true;
  230. }
  231. }, function (err) {
  232. alert(JSON.stringify(err));
  233. })
  234. });
  235. $scope.change = function (item_field) {
  236. $scope.template_field_active = item_field;
  237. if (item_field.showlist) $scope.template_item.select_texts.push({"text": ""});
  238. };
  239. $scope.remove = function (index) {
  240. $scope.template_item.select_texts.splice(index, 1);
  241. };
  242. $scope.add = function () {
  243. $scope.template_item.select_texts.push({'text': ""});
  244. };
  245. $scope.ok = function () {
  246. if ($scope.isNew) WorkFlow.templatedata.items.push($scope.template_item);
  247. else {
  248. var item = _.find(WorkFlow.templatedata.items, {'id': $state.params['id']});
  249. item = $scope.template_item;
  250. }
  251. $ionicHistory.goBack();
  252. }
  253. });