batchedit.ui.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. let batchIgnoreTips = [];
  2. /**
  3. * 更新可用工作日天数。
  4. * Update work days.
  5. *
  6. * @access public
  7. * @return void
  8. */
  9. window.batchComputeWorkDays = function()
  10. {
  11. const $tr = $(this).closest('tr');
  12. if($tr.find('div[data-longtime="1"]').length > 0) return false;
  13. const $days = $tr.find('[data-name="days"] input');
  14. const endDate = $tr.find('[name^=end]').val();
  15. if(endDate == longTime)
  16. {
  17. $days.val('').addClass('disabled');
  18. $days.attr('disabled', 'disabled');
  19. return false;
  20. }
  21. $days.removeClass('disabled');
  22. $days.removeAttr('disabled');
  23. const beginDate = $tr.find('[name^=begin]').val();
  24. $tr.find('[name^=days]').val(computeDaysDelta(beginDate, endDate));
  25. }
  26. /**
  27. * 检查项目起止日期是否超出父项目集起止日期。
  28. * Check whether the start and end dates of the project exceed the start and end dates of the parent program.
  29. *
  30. * @access public
  31. * @return void
  32. */
  33. function batchCheckDate()
  34. {
  35. const $tr = $(this).closest('tr');
  36. const index = $tr.data('index');
  37. if(batchIgnoreTips[index]) return;
  38. const end = $tr.find('[name^=end]').val();
  39. const begin = $tr.find('[name^=begin]').val();
  40. if(!begin || !end) return;
  41. const selectedProgramID = $tr.find('[name^=parent]').val();
  42. const aclList = !disabledprograms && selectedProgramID ? programAclList : projectAclList;
  43. $tr.find('[name^=acl]').zui('picker').render({items: aclList, required: true});
  44. if(selectedProgramID == 0 || selectedProgramID == undefined)
  45. {
  46. $tr.next('tr.dateTip').remove();
  47. return;
  48. }
  49. const projectID = $tr.find('[name^=id]').val();
  50. $.get($.createLink('project', 'ajaxGetProjectFormInfo', 'objectType=project&objectID=' + projectID + '&selectedProgramID=' + selectedProgramID), function(response)
  51. {
  52. const data = JSON.parse(response);
  53. const parentEnd = new Date(data.selectedProgramEnd);
  54. const parentBegin = new Date(data.selectedProgramBegin);
  55. const projectEnd = new Date(end);
  56. const projectBegin = new Date(begin);
  57. if(projectBegin >= parentBegin && projectEnd <= parentEnd)
  58. {
  59. $tr.next('tr.dateTip').remove();
  60. return;
  61. }
  62. if($tr.next('tr.dateTip').length == 0) $tr.after($('#dateTipTemplate tr').clone());
  63. $tr.next('tr.dateTip').find('.beginLess').toggleClass('hidden', projectBegin >= parentBegin).text(beginLessThanParent.replace('%s', data.selectedProgramBegin));
  64. $tr.next('tr.dateTip').find('.endGreater').toggleClass('hidden', projectEnd <= parentEnd).text(endGreatThanParent.replace('%s', data.selectedProgramEnd));
  65. $tr.next('tr.dateTip').find('a').attr('onclick', 'batchIgnoreTip(' + index + ')');
  66. });
  67. }
  68. /**
  69. * 忽略日期提示。
  70. * Ignore date tips.
  71. *
  72. * @access public
  73. * @param int index
  74. * @return void
  75. */
  76. batchIgnoreTip = function(index)
  77. {
  78. $('tr[data-index="' + index + '"]').next('tr.dateTip').remove();
  79. batchIgnoreTips[index] = true;
  80. }
  81. window.renderRowData = function($row, index, row)
  82. {
  83. const aclList = !disabledprograms && row.parent ? programAclList : projectAclList;
  84. $row.find('[data-name="acl"]').find('.picker-box').on('inited', function(e, info)
  85. {
  86. let $acl = info[0];
  87. $acl.render({items: aclList, required: true});
  88. });
  89. if(row.end == longTime)
  90. {
  91. const $days = $row.find('[data-name="days"] input');
  92. $days.val('').addClass('disabled');
  93. $days.attr('disabled', 'disabled');
  94. }
  95. }