view.ui.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. window.unlinkObject = function(objectType, objectID)
  2. {
  3. zui.Modal.confirm({message: confirmLang[objectType], icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) =>
  4. {
  5. if(res) $.ajaxSubmit({'url': unlinkURL[objectType].replace('%s', objectID)});
  6. });
  7. };
  8. window.renderStoryCell = function(result, info)
  9. {
  10. const story = info.row.data;
  11. if(info.col.name == 'title' && result)
  12. {
  13. let html = '';
  14. let gradeLabel = gradeGroup[story.type][story.grade];
  15. if(gradeLabel) html += "<span class='label gray-pale rounded-xl clip'>" + gradeLabel + "</span> ";
  16. if(html) result.unshift({html});
  17. }
  18. if(info.col.name == 'sort')
  19. {
  20. result[0] = {html: "<i class='icon-move'></i>", className: 'text-gray cursor-move move-plan'};
  21. }
  22. return result;
  23. };
  24. window.ajaxConfirmLoad = function(obj)
  25. {
  26. var $this = $(obj);
  27. var action = $this.data('action');
  28. zui.Modal.confirm({message: confirmLang[action], icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) =>
  29. {
  30. if(res) $.get($this.data('url'), function(){loadCurrentPage()});
  31. });
  32. };
  33. window.showLink = function(type, params, onlyUpdateTable)
  34. {
  35. const url = $.createLink('productplan', type === 'story' ? 'linkStory' : 'linkBug', 'planID=' + planID + (params || '&browseType=&param='));
  36. if(onlyUpdateTable)
  37. {
  38. loadComponent($('#' + (type === 'story' ? 'stories' : 'bugs')).find('.dtable').attr('id'), {url: url, component: 'dtable', partial: true});
  39. return;
  40. }
  41. loadTarget({url: url, target: type === 'story' ? 'stories' : 'bugs'});
  42. $('.detail-header .open-url').attr('href', $.createLink('productplan', 'view', 'planID=' + planID + '&type=' + type)).removeAttr('data-back');
  43. };
  44. window.onSearchLinks = function(type, result)
  45. {
  46. const params = $.parseLink(result.load).vars[4];
  47. showLink(type, params ? atob(params[1]) : null, true);
  48. return false;
  49. };
  50. /**
  51. * 计算表格信息的统计。
  52. * Set summary for table footer.
  53. *
  54. * @param element element
  55. * @param array checkedIdList
  56. * @access public
  57. * @return object
  58. */
  59. window.setStatistics = function(element, checkedIdList, pageSummary)
  60. {
  61. if(checkedIdList == undefined || checkedIdList.length == 0) return {html: pageSummary};
  62. let checkedEstimate = 0;
  63. let checkedCase = 0;
  64. let total = 0;
  65. const rows = element.layout.allRows;
  66. rows.forEach((row) => {
  67. if(checkedIdList.includes(row.id))
  68. {
  69. const story = element.getRowInfo(row.id);
  70. if(story.data.type == 'story')
  71. {
  72. total += 1;
  73. if(story.data.isParent == '0') checkedEstimate += parseFloat(story.data.estimate);
  74. if(cases[row.id]) checkedCase += 1;
  75. }
  76. }
  77. });
  78. const rate = total == 0 ? '0%' : Math.round(checkedCase / total * 10000) / 100 + '' + '%';
  79. return {html: checkedSummary.replace('%total%', total)
  80. .replace('%estimate%', checkedEstimate.toFixed(1))
  81. .replace('%rate%', rate)};
  82. }
  83. $(document).off('click', '.batch-btn > a, .batch-btn').on('click', '.batch-btn > a, .batch-btn', function()
  84. {
  85. const $this = $(this);
  86. const type = $this.data('type');
  87. const dtable = zui.DTable.query($('#' + type + 'DTable'));
  88. const checkedList = dtable.$.getChecks();
  89. if(!checkedList.length) return;
  90. const postData = new FormData();
  91. const url = $this.data('url');
  92. checkedList.forEach((id) => postData.append(type + 'IdList[]', id));
  93. if($this.data('account')) postData.append('assignedTo', $this.data('account'));
  94. if($this.data('page') == 'batch')
  95. {
  96. postAndLoadPage(url, postData);
  97. }
  98. else
  99. {
  100. $.ajaxSubmit({url: url, data: postData});
  101. }
  102. });
  103. window.handleLinkObjectClick = function($this)
  104. {
  105. const type = $this.data('type');
  106. const dtable = zui.DTable.query($this);
  107. const checkedList = dtable.$.getChecks();
  108. if(!checkedList.length) return;
  109. const postKey = type == 'story' ? 'stories' : 'bugs';
  110. const postData = new FormData();
  111. checkedList.forEach((id) => postData.append(postKey + '[]', id));
  112. $.ajaxSubmit({url: $this.data('url'), data: postData});
  113. };
  114. $(function()
  115. {
  116. if(initLink == 'true') window.showLink(type, linkParams);
  117. });
  118. window.onSortEnd = function(from, to, type)
  119. {
  120. if(!from || !to) return false;
  121. const url = $.createLink('productplan', 'ajaxStorySort', `planID=${planID}`);
  122. const form = new FormData();
  123. form.append('storyIdList', JSON.stringify(this.state.rowOrders));
  124. form.append('orderBy', orderBy);
  125. form.append('pageID', storyPageID);
  126. form.append('recPerPage', storyRecPerPage);
  127. $.ajaxSubmit({url, data:form});
  128. $.apps.updateAppUrl($.createLink('productplan', 'view', `planID=${planID}&type=story&orderBy=order_desc`));
  129. return true;
  130. }