factory.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. starter.factory('Daily', function ($resource, cfg, formatFilter, Tool, showPopup) {
  2. var daily = {};
  3. daily.templateData = {};
  4. daily.templateId = -1;
  5. daily.fieldItems = []; //存放模板字段集合
  6. daily.templateDepts = [];
  7. daily.currentTemplate = {};
  8. daily.daily = {};
  9. daily.permissionUsers = [];
  10. daily.permissionUser = {};
  11. daily.previewData = {};
  12. daily.toDayViewUsers = [];
  13. daily.templatefield = $resource(formatFilter('{0}daily/templatefield/', cfg.api));
  14. daily.templateitem = $resource(formatFilter('{0}daily/templateitem/', cfg.api));
  15. daily.templatedept = $resource(formatFilter('{0}daily/templatedept/', cfg.api));
  16. daily.template = $resource(formatFilter('{0}daily/template/:id/', cfg.api));
  17. daily.dailytf = $resource(formatFilter('{0}daily/dailytf/', cfg.api), {}, {'save': {method: 'POST', isArray: true}, 'update': {method: 'PUT', isArray: true}});
  18. daily.dailymf = $resource(formatFilter('{0}daily/dailymf/:id/', cfg.api));
  19. daily.dailypermission = $resource(formatFilter('{0}daily/dailypermission/', cfg.api), {}, {'save': {method: 'POST', isArray: true}, 'patch': {method: 'PATCH', isArray: true}});
  20. daily.dailyread = $resource(formatFilter('{0}daily/dailyread/:id/', cfg.api));
  21. daily.dailyfile = $resource(formatFilter('{0}daily/dailyfile/:id/', cfg.api));
  22. daily.dailysummary = $resource(formatFilter('{0}daily/dailysummary/', cfg.api));
  23. daily.dailyview = $resource(formatFilter('{0}daily/dailyview/', cfg.api));
  24. daily.mouthsummary = $resource(formatFilter('{0}daily/monthsummary/', cfg.api));
  25. daily.dailydeptview = $resource(formatFilter('{0}daily/dailydeptview/', cfg.api));
  26. daily.todaysummary = $resource(formatFilter('{0}daily/todaysummary/', cfg.api));
  27. daily.readview = $resource(formatFilter('{0}daily/readview/', cfg.api));
  28. daily.get_name = function () {
  29. return daily.templateDepts.map(function (dept) {
  30. return dept.depname;
  31. }).join(',');
  32. }
  33. daily.get_fieldItems = function () {
  34. if (daily.templateId == -1) {
  35. return _.map(daily.fieldItems, function (fi) {
  36. return _.pick(fi, 'name', 'daily_template_field_id', 'required', 'extra');
  37. })
  38. } else {
  39. return _.map(daily.fieldItems, function (fi) {
  40. return _.pick(fi, 'id', 'name', 'daily_template_field_id', 'required', 'extra');
  41. })
  42. }
  43. }
  44. daily.get_description = function () {
  45. return _.map(daily.templateData.items, function (fi) {
  46. return fi.name;
  47. }).join(',')
  48. }
  49. daily.checkDaily = function (dailys) {
  50. var flag = true;
  51. var note = null;
  52. daily = _.find(dailys, function(daily){
  53. return (!daily.text || daily.text == '') && daily.required
  54. });
  55. if (daily) {
  56. if (parseInt(daily.t__type) in [1, 2, 4]) {
  57. note = '请填写';
  58. } else if (parseInt(daily.t__type) in [3, 5]) {
  59. note = '请选择';
  60. }
  61. note += daily.name;
  62. flag = false;
  63. showPopup.PopupWindow(0, note, false);
  64. }
  65. return flag;
  66. }
  67. daily.getDate = function (timer) {
  68. timer = timer || 7;
  69. var newDate = [];
  70. timer = timer - 2;
  71. for (var i = -timer; i < 2; i++) {
  72. var id = i + timer;
  73. var day = new Date();
  74. day.setDate(day.getDate() + i);
  75. var week_day = Tool.getTranslateByKey("weekdays", day.getDay());
  76. newDate.push({
  77. 'id':id,
  78. 'day':day,
  79. 'week':week_day
  80. });
  81. }
  82. return newDate.reverse();
  83. }
  84. return daily;
  85. });