factory.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. starter.factory('WorkFlow', function ($ionicPopup, $resource, formatFilter, cfg, Tool, showPopup) {
  2. var workflow = {};
  3. workflow.templates = $resource(formatFilter('{0}workflow/template/:id', cfg.api));
  4. workflow.templateitem = $resource(formatFilter('{0}workflow/templateitem/', cfg.api));
  5. workflow.templatecc = $resource(formatFilter('{0}workflow/templatecc/', cfg.api));
  6. workflow.templatestep = $resource(formatFilter('{0}workflow/templatestep/', cfg.api));
  7. workflow.templatepermission = $resource(formatFilter('{0}workflow/templatepermission/', cfg.api));
  8. workflow.templatefield = $resource(formatFilter('{0}daily/templatefield/', cfg.api));
  9. workflow.templatedata = {template_id: -1, items: [], steps: [], cc: [], permission: {'depts': [], 'users': [], 'all': true}};
  10. workflow.create_template = function (templatedata) {
  11. var template = _.pick(templatedata, "name", "description");
  12. template.type = templatedata.template_id == -1 ? 1 : 0;
  13. workflow.templates.save(template, function (data) {
  14. var items = _.map(templatedata.items, function (item) {
  15. return _.pick(item, 'name', 'required')
  16. })
  17. })
  18. };
  19. workflow.showDialog = function (scope, titlename, placeholder, itemlabel, righttext) {
  20. var customTemplate = formatFilter(
  21. '<div set-popover-style><label class="item item-input"><input type="text" placeholder="{0}" ng-model="auditstep.name"></label>' +
  22. '<ion-item ng-click="toselect()" class="item item-icon-right">{1}<p class="label-right-text">{2}</p> <i class="icon ion-chevron-right icon-accessory"></i> </ion-item></div>', placeholder, itemlabel, righttext);
  23. var popup = $ionicPopup.show({
  24. scope: scope,
  25. template: customTemplate,
  26. title: '<div><h5>' + titlename + '</h5></div>',
  27. buttons: [{
  28. text: '取消',
  29. onTap: function (e) {
  30. return false;
  31. }
  32. }, {
  33. text: '<b>保存</b>',
  34. type: 'button-positive',
  35. onTap: function (e) {
  36. if (Tool.trim(scope.auditstep.name).length < 2) {
  37. showPopup.PopupWindow(0, "不能少于2个字!", false);
  38. e.preventDefault();
  39. } else
  40. return true;
  41. }
  42. }]
  43. });
  44. return popup;
  45. };
  46. return workflow;
  47. })
  48. ;