task.ui.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. $(document).off('click', '.batch-btn').on('click', '.batch-btn', function()
  2. {
  3. const dtable = zui.DTable.query($(this).target);
  4. const checkedList = dtable.$.getChecks();
  5. if(!checkedList.length) return;
  6. const url = $(this).data('url');
  7. const form = new FormData();
  8. checkedList.forEach((id) => form.append('taskIdList[]', id));
  9. if($(this).hasClass('ajax-btn'))
  10. {
  11. $.ajaxSubmit({url, data: form});
  12. }
  13. else
  14. {
  15. postAndLoadPage(url, form);
  16. }
  17. });
  18. /**
  19. * 计算表格任务信息的统计。
  20. * Set todo summary for table footer.
  21. *
  22. * @param element element
  23. * @param array checkedIDList
  24. * @access public
  25. * @return object
  26. */
  27. window.setStatistics = function(element, checks)
  28. {
  29. let waitCount = 0;
  30. let doingCount = 0;
  31. let estimate = 0;
  32. let consumed = 0;
  33. let left = 0;
  34. checks.forEach((checkID) => {
  35. const task = element.getRowInfo(checkID).data;
  36. if(task.rawStatus == 'wait') waitCount ++;
  37. if(task.rawStatus == 'doing') doingCount ++;
  38. if(task.isParent > 0) return false;
  39. estimate += parseFloat(task.estimate);
  40. consumed += parseFloat(task.consumed);
  41. left += parseFloat(task.left);
  42. })
  43. if(checks.length) return {html: element.options.checkedSummary.replaceAll('%total%', `${checks.length}`).replaceAll('%wait%', waitCount).replaceAll('%doing%', doingCount).replaceAll('%estimate%', estimate).replaceAll('%consumed%', consumed).replaceAll('%left%', left)};
  44. return zui.formatString(element.options.defaultSummary);
  45. }
  46. /**
  47. * 对部分列进行重定义。
  48. * Redefine the partial column.
  49. *
  50. * @param array result
  51. * @param array info
  52. * @access public
  53. * @return string|array
  54. */
  55. window.renderCell = function(result, info)
  56. {
  57. const task = info.row.data;
  58. if(info.col.name == 'name' && result)
  59. {
  60. if(typeof result[0] == 'object') result[0].props.className = 'overflow-hidden';
  61. let html = '';
  62. if(task.team)
  63. {
  64. html += "<span class='label gray-pale rounded-xl nowrap'>" + multipleAB + "</span>";
  65. }
  66. if(task.isParent > 0)
  67. {
  68. html += "<span class='label gray-pale rounded p-0 size-sm whitespace-nowrap'>" + parentAB + "</span>";
  69. }
  70. else if(task.parent > 0)
  71. {
  72. html += "<span class='label gray-pale rounded p-0 size-sm whitespace-nowrap'>" + childrenAB + "</span>";
  73. }
  74. if(html) result.unshift({html});
  75. if(typeof task.delay != 'undefined' && task.delay > 0)
  76. {
  77. result[result.length] = {html:'<span class="label danger-pale ml-1 flex-none nowrap">' + delayWarning.replace('%s', task.delay) + '</span>', className:'flex items-end', style:{flexDirection:"column"}};
  78. }
  79. }
  80. if(info.col.name == 'deadline' && result[0])
  81. {
  82. if(['done', 'cancel', 'close'].includes(task.rawStatus)) return result;
  83. const today = zui.formatDate(zui.createDate(), 'yyyy-MM-dd');
  84. const yesterday = zui.formatDate(convertStringToDate(today) - 24 * 60 * 60 * 1000, 'yyyy-MM-dd');
  85. if(result[0] == today)
  86. {
  87. result[0] = {html: '<span class="label warning-pale rounded-full size-sm">' + todayLabel + '</span>'};
  88. }
  89. else if(result[0] == yesterday)
  90. {
  91. result[0] = {html: '<span class="label danger-pale rounded-full size-sm">' + yesterdayLabel + '</span>'};
  92. }
  93. else if(result[0] < yesterday)
  94. {
  95. result[0] = {html: '<span class="label danger-pale rounded-full size-sm">' + result[0] + '</span>'};
  96. }
  97. }
  98. if(info.col.name == 'status' && result)
  99. {
  100. result[0] = {html: `<span class='status-${info.row.data.rawStatus}'>` + info.row.data.status + "</span>"};
  101. }
  102. return result;
  103. }
  104. function convertStringToDate(dateString)
  105. {
  106. dateString = dateString.split('-');
  107. dateString = dateString[1] + '/' + dateString[2] + '/' + dateString[0];
  108. return Date.parse(dateString);
  109. }
  110. $(document).off('click', '.switchButton').on('click', '.switchButton', function()
  111. {
  112. var taskViewType = $(this).attr('data-type');
  113. $.cookie.set('taskViewType', taskViewType, {expires:config.cookieLife, path:config.webRoot});
  114. loadCurrentPage();
  115. });