view.ui.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. window.handleClickBatchBtn = function($this)
  2. {
  3. const dtable = zui.DTable.query($this);
  4. const checkedList = dtable.$.getChecks();
  5. if(!checkedList.length) return;
  6. const tabType = $this.data('type');
  7. const url = $this.data('url');
  8. const form = new FormData();
  9. const field = $this.hasClass('bug-batch-close') ? 'unlinkBugs[]' : `${tabType}IdList[]`;
  10. checkedList.forEach((id) => form.append(field, id));
  11. if($this.hasClass('load-btn'))
  12. {
  13. postAndLoadPage(url, form);
  14. }
  15. else
  16. {
  17. $.ajaxSubmit({url, data: form});
  18. }
  19. };
  20. window.handleLinkObjectClick = function($this)
  21. {
  22. const type = $this.data('type');
  23. const dtable = zui.DTable.query($this);
  24. const checkedList = dtable.$.getChecks();
  25. if(!checkedList.length) return;
  26. const postKey = type == 'story' ? 'stories' : 'bugs';
  27. const postData = new FormData();
  28. checkedList.forEach((id) => postData.append(postKey + '[]', id));
  29. $.ajaxSubmit({url: $this.data('url'), data: postData});
  30. };
  31. /**
  32. * 计算表格任务信息的统计。
  33. * Set task summary for table footer.
  34. *
  35. * @param element element
  36. * @param array checkedIDList
  37. * @param string pageSummary
  38. * @access public
  39. * @return object
  40. */
  41. window.setStoryStatistics = function(element, checkedIDList, pageSummary)
  42. {
  43. const checkedTotal = checkedIDList.length;
  44. if(checkedTotal == 0) return {html: pageSummary};
  45. let checkedEstimate = 0;
  46. let checkedCase = 0;
  47. let rateCount = checkedTotal;
  48. const rows = element.layout.allRows;
  49. rows.forEach((row) => {
  50. if(checkedIDList.includes(row.id))
  51. {
  52. const story = row.data;
  53. const cases = storyCases[row.id];
  54. checkedEstimate += parseFloat(story.estimate);
  55. if(cases > 0)
  56. {
  57. checkedCase ++;
  58. }
  59. else if(story.children != undefined && story.children > 0)
  60. {
  61. rateCount --;
  62. }
  63. }
  64. })
  65. let rate = '0%';
  66. if(rateCount) rate = Math.round(checkedCase / rateCount * 100) + '%';
  67. return {html: checkedSummary.replace('%total%', checkedTotal).replace('%estimate%', checkedEstimate.toFixed(1)).replace('%rate%', rate)};
  68. }
  69. /**
  70. * 移除关联的对象。
  71. * Remove linked object.
  72. *
  73. * @param sting objectType
  74. * @param int objectID
  75. * @access public
  76. * @return void
  77. */
  78. window.unlinkObject = function(objectType, objectID)
  79. {
  80. objectType = objectType.toLowerCase();
  81. zui.Modal.confirm(eval(`confirmunlink${objectType}`)).then((res) => {
  82. if(res)
  83. {
  84. $.ajaxSubmit({url: eval(`unlink${objectType}url`).replace('%s', objectID)});
  85. }
  86. });
  87. }
  88. window.showLink = function(type, params, onlyUpdateTable)
  89. {
  90. let relatedParams = 'releaseID=' + releaseID + (params || '&browseType=&param=');
  91. let idName = 'finishedStory';
  92. if(type == 'bug')
  93. {
  94. idName = 'resolvedBug';
  95. relatedParams += '&type=bug';
  96. }
  97. else if(type == 'leftBug')
  98. {
  99. idName = 'leftBug';
  100. relatedParams += '&type=leftBug';
  101. }
  102. const url = $.createLink(releaseModule, type === 'story' ? 'linkStory' : 'linkBug', relatedParams);
  103. if(onlyUpdateTable)
  104. {
  105. loadComponent($('#' + idName).find('.dtable').attr('id'), {url: url, component: 'dtable', partial: true});
  106. return;
  107. }
  108. loadTarget({url: url, target: idName});
  109. };
  110. $(function()
  111. {
  112. if(initLink == 'true') window.showLink(type, linkParams);
  113. })
  114. window.onSearchLinks = function(type, result)
  115. {
  116. const params = $.parseLink(result.load).vars[3];
  117. showLink(type, params ? atob(params[1]) : null, true);
  118. return false;
  119. };
  120. window.renderStoryCell = function(result, info)
  121. {
  122. const story = info.row.data;
  123. if(info.col.name == 'title' && result)
  124. {
  125. let html = '';
  126. let gradeLabel = (showGrade || story.grade >= 2) ? grades[story.grade] : '';
  127. if(gradeLabel) html += "<span class='label gray-pale rounded-xl'>" + gradeLabel + "</span>";
  128. if(html) result.unshift({html});
  129. }
  130. return result;
  131. };