story.ui.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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('storyIdList[]', id));
  9. if($(this).hasClass('ajax-btn'))
  10. {
  11. $.ajaxSubmit({url, data: form});
  12. }
  13. else
  14. {
  15. postAndLoadPage(url, form);
  16. }
  17. }).off('click', '#taskModal button[type="submit"]').on('click', '#taskModal button[type="submit"]', function()
  18. {
  19. const taskType = $('[name=type]').val();
  20. if(taskType.length == 0)
  21. {
  22. zui.Modal.alert(typeNotEmpty);
  23. return false;
  24. }
  25. if($('[name=hourPointValue]').length)
  26. {
  27. let hourPoint = $('[name=hourPointValue]').val();
  28. if(typeof(hourPoint) == 'undefined') hourPoint = 0;
  29. if(hourPoint == 0)
  30. {
  31. zui.Modal.alert(hourPointNotEmpty);
  32. return false;
  33. }
  34. if(typeof(hourPoint) != 'undefined' && (isNaN(hourPoint) || hourPoint < 0))
  35. {
  36. zui.Modal.alert(hourPointNotError);
  37. return false;
  38. }
  39. }
  40. const checkedIdList = $('#storyIdList').val().split(',');
  41. let linkedTaskIdList = '';
  42. let unlinkTaskIdList = '';
  43. checkedIdList.forEach(function(storyID)
  44. {
  45. if(linkedTaskStories[storyID])
  46. {
  47. linkedTaskIdList += '[' + storyID +']';
  48. }
  49. else
  50. {
  51. unlinkTaskIdList += storyID + ',';
  52. }
  53. });
  54. if(linkedTaskIdList)
  55. {
  56. confirmStoryToTaskTip = confirmStoryToTask.replace('%s', linkedTaskIdList);
  57. if(confirm(confirmStoryToTaskTip))
  58. {
  59. console.log('ddd');
  60. $('#storyIdList').val(checkedIdList);
  61. }
  62. else
  63. {
  64. if(!unlinkTaskIdList)
  65. {
  66. loadCurrentPage();
  67. return false;
  68. }
  69. $('#storyIdList').val(unlinkTaskIdList);
  70. }
  71. }
  72. console.log('ccc');
  73. zui.Modal.hide('#taskModal');
  74. console.log('eee');
  75. const formData = new FormData($("#toTaskForm")[0]);
  76. console.log(formData);
  77. postAndLoadPage($('#toTaskForm').attr('action'), formData);
  78. return false;
  79. });
  80. $(document).off('click', '#linkStoryByPlan button[type="submit"]').on('click', '#linkStoryByPlan button[type="submit"]', function()
  81. {
  82. var planID = $('[name=plan]').val();
  83. if(planID)
  84. {
  85. $.ajaxSubmit({url: $.createLink('execution', 'importPlanStories', 'executionID=' + executionID + '&planID=' + planID)});
  86. }
  87. return false;
  88. })
  89. /**
  90. * 计算表格信息的统计。
  91. * Set summary for table footer.
  92. *
  93. * @param element element
  94. * @param array checkedIdList
  95. * @access public
  96. * @return object
  97. */
  98. window.setStatistics = function(element, checkedIdList)
  99. {
  100. const checkedTotal = checkedIdList.length;
  101. if(!checkedTotal) return {html: summary};
  102. $('#storyIdList').val(checkedIdList.join(','));
  103. let checkedEstimate = 0;
  104. let checkedCase = 0;
  105. let SRTotal = 0;
  106. let total = 0;
  107. let rateCount = 0;
  108. checkedIdList.forEach((rowID) => {
  109. const story = element.getRowInfo(rowID);
  110. if(storyType == 'requirement' && story.data.type == 'story') SRTotal += 1;
  111. if(storyType == story.data.type) total += 1;
  112. if(story)
  113. {
  114. if(cases[rowID]) checkedCase += 1;
  115. if(story.data.isParent == '0')
  116. {
  117. checkedEstimate += parseFloat(story.data.estimate);
  118. rateCount += 1;
  119. }
  120. }
  121. })
  122. const rate = rateCount ? Math.round(checkedCase / rateCount * 10000) / 100 + '' + '%' : 0 + '%';
  123. return {
  124. html: checkedSummary.replace('%total%', checkedTotal)
  125. .replace('%estimate%', checkedEstimate)
  126. .replace('%rate%', rate)
  127. };
  128. }
  129. window.renderStoryCell = function(result, info)
  130. {
  131. const story = info.row.data;
  132. if(info.col.name == 'title' && result)
  133. {
  134. let html = '';
  135. let gradeLabel = gradeGroup[story.type][story.grade];
  136. if(typeof modulePairs[story.moduleID] != 'undefined') html += "<span class='label gray-pale rounded-xl clip'>" + modulePairs[story.moduleID] + "</span> ";
  137. if(gradeLabel) html += "<span class='label gray-pale rounded-xl'>" + gradeLabel + "</span>";
  138. if(html) result.unshift({html});
  139. }
  140. if(info.col.name == 'status' && result)
  141. {
  142. if(info.row.data.URChanged == '1') result[0] = {html: "<span class='status-changed'>" + URChanged + "</span>"};
  143. }
  144. if(info.col.name == 'order')
  145. {
  146. result[0] = {html: "<i class='icon-move'></i>", className: 'text-gray cursor-move move-plan'};
  147. }
  148. return result;
  149. };
  150. window.setShowGrades = function()
  151. {
  152. const showGrades = $('[name^=showGrades]').zui('picker').$.state.value;
  153. if(oldShowGrades == showGrades) return;
  154. const link = $.createLink('product', 'ajaxSetShowGrades', 'module=execution&showGrades=' + showGrades);
  155. $.get(link, function() { loadCurrentPage(); });
  156. }
  157. window.firstRendered = false;
  158. window.toggleCheckRows = function(idList)
  159. {
  160. if(!idList?.length || firstRendered) return;
  161. firstRendered = true;
  162. const dtable = zui.DTable.query($('#table-execution-story'));
  163. dtable.$.toggleCheckRows(idList.split(','), true);
  164. }
  165. window.onSortEnd = function(from, to, type)
  166. {
  167. if(!from || !to) return false;
  168. const url = $.createLink('execution', 'storySort', `execution=${executionID}`);
  169. const form = new FormData();
  170. form.append('storyIdList', JSON.stringify(this.state.rowOrders));
  171. form.append('orderBy', orderBy);
  172. form.append('pageID', storyPageID);
  173. form.append('recPerPage', storyRecPerPage);
  174. $.ajaxSubmit({url, data:form});
  175. return true;
  176. }