view.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. function showLink(roadmapID, type, orderBy, param)
  2. {
  3. var method = 'linkUR';
  4. loadURL(createLink('roadmap', method, 'roadmapID=' + roadmapID + (typeof(param) == 'undefined' ? '' : param) + (typeof(orderBy) == 'undefined' ? '' : "&orderBy=" + orderBy)), type)
  5. $('.actions').find("a[href*='" + type + "']").addClass('hidden');
  6. }
  7. /**
  8. * Load URL.
  9. *
  10. * @param string $url
  11. * @param string $type
  12. * @access public
  13. * @return void
  14. */
  15. function loadURL(url, type)
  16. {
  17. $.get(url, function(data)
  18. {
  19. var $pane = $('#stories');
  20. $pane.find('.main-table').hide();
  21. var $linkBox = $pane.find('.linkBox').html(data).removeClass('hidden');
  22. $linkBox.html(data).removeClass('hidden');
  23. $linkBox.find('[data-ride="table"]').table();
  24. $linkBox.find('[data-ride="pager"]').pager();
  25. $linkBox.find('[data-ride="pager"] li a.pager-item').click(function()
  26. {
  27. loadURL($(this).attr('href'), type);
  28. return false;
  29. });
  30. $linkBox.find('[data-ride="pager"] .pager-size-menu a[data-size]').off('click');
  31. $linkBox.find('[data-ride="pager"] .pager-size-menu a[data-size]').click(function()
  32. {
  33. line = $linkBox.find('[data-ride="pager"]').attr('data-link-creator');
  34. line = line.replace('{recPerPage}', $(this).attr('data-size')).replace('{page}', $linkBox.find('[data-ride="pager"]').attr('data-page'));
  35. $.cookie($linkBox.find('[data-ride="pager"]').attr('data-page-cookie'), $(this).attr('data-size'), {expires:config.cookieLife, path:config.webRoot});
  36. loadURL(line, type);
  37. return false;
  38. });
  39. $.toggleQueryBox(true, $linkBox.find('#queryBox'));
  40. });
  41. }
  42. $(function()
  43. {
  44. /* Recalculate the maximum width of the title. */
  45. var maxWidth = $('#mainMenu').width() - $('#actionsBox').width() - $('#mainMenu .btn-toolbar .page-title .label-info').width() - 177;
  46. $('#mainMenu .btn-toolbar .page-title .text').css('max-width', maxWidth.toString() + 'px');
  47. if(link == 'true') showLink(roadmapID, type, orderBy, param);
  48. var infoShowed = false;
  49. $('.nav.nav-tabs a[data-toggle="tab"]').on('shown.zui.tab', function(e)
  50. {
  51. var href = $(e.target).attr('href');
  52. var tabPane = $(href + '.tab-pane');
  53. if(tabPane.size() == 0) return;
  54. var formID = tabPane.find('.linkBox').find('form:last');
  55. if(formID.size() == 0) formID = tabPane.find('form:last');
  56. if(href == '#roadmapInfo' && !infoShowed)
  57. {
  58. $('#roadmapInfo img').each(function()
  59. {
  60. var $tr = $('#roadmapInfo .detail-content .table-data tbody tr:first');
  61. width = $tr.width() - $tr.find('th').width();
  62. if($(this).parent().prop('tagName').toLowerCase() == 'a') $(this).unwrap();
  63. setImageSize($(this), width, 0);
  64. });
  65. infoShowed = true;
  66. }
  67. });
  68. $('#storyList').on('sort.sortable', function(e, data)
  69. {
  70. var list = '';
  71. for(i = 0; i < data.list.length; i++) list += $(data.list[i].item).attr('data-id') + ',';
  72. $.post(createLink('roadmap', 'ajaxStorySort', 'roadmapID=' + roadmapID), {'stories' : list, 'orderBy' : orderBy, 'pageID' : storyPageID, 'recPerPage' : storyRecPerPage, 'recTotal' : storyRecTotal}, function()
  73. {
  74. var $target = $(data.element[0]);
  75. $target.hide();
  76. $target.fadeIn(1000);
  77. order = 'order_desc';
  78. history.pushState({}, 0, createLink('roadmap', 'view', "roadmapID=" + roadmapID + '&type=story&orderBy=' + order));
  79. });
  80. });
  81. $('.table-story').table(
  82. {
  83. statisticCreator: function(table)
  84. {
  85. var $checkedRows = table.getTable().find(table.isDataTable ? '.datatable-row-left.checked' : 'tbody>tr.checked');
  86. var $originTable = table.isDataTable ? table.$.find('.datatable-origin') : null;
  87. var checkedTotal = $checkedRows.length;
  88. if(!checkedTotal) return;
  89. var checkedEstimate = 0;
  90. var checkedCase = 0;
  91. var rateCount = checkedTotal;
  92. $checkedRows.each(function()
  93. {
  94. var $row = $(this);
  95. if($originTable)
  96. {
  97. $row = $originTable.find('tbody>tr[data-id="' + $row.data('id') + '"]');
  98. }
  99. var data = $row.data();
  100. checkedEstimate += data.estimate;
  101. if(data.cases > 0)
  102. {
  103. checkedCase += 1;
  104. }
  105. else if(data.children != undefined && data.children > 0)
  106. {
  107. rateCount -= 1;
  108. }
  109. });
  110. var rate = '0%';
  111. if(rateCount) rate = Math.round(checkedCase / rateCount * 100) + '%';
  112. if(checkedTotal == 0) return storySummary;
  113. return checkedSummary.replace('%total%', checkedTotal)
  114. .replace('%estimate%', checkedEstimate.toFixed(1))
  115. .replace('%rate%', rate);
  116. }
  117. });
  118. $('#batchUnlinkBtn').click(function()
  119. {
  120. if($('#batchUnlinkBtn').hasClass('disabled')) return false;
  121. var storyIdList = $("input[name^='storyIdList']:checked").map(function()
  122. {
  123. return $(this).val();
  124. }).get();
  125. var confirmMsg = confirm(confirmBatchUnlinkStory);
  126. if(confirmMsg == true)
  127. {
  128. $.post(createLink('roadmap', 'batchUnlinkUR', "roadmapID=" + roadmapID), {"storyIdList": storyIdList}, function(data)
  129. {
  130. if(data) alert(data);
  131. if(storyListSession) location.href = storyListSession;
  132. location.href = createLink('roadmap', 'view', "roadmapID=" + roadmapID);
  133. })
  134. }
  135. else
  136. {
  137. return false;
  138. }
  139. });
  140. if(canBatchChangeRoadmap)
  141. {
  142. $("#storyList input[id^=storyIdList]").on("click", function()
  143. {
  144. if($('#roadmapURList .table-actions .dropdown-menu').css('display') != 'none')
  145. {
  146. $('#roadmapURList .table-actions .dropdown-toggle').trigger('click');
  147. }
  148. });
  149. $('.table-actions.btn-toolbar button.dropdown-toggle').click(function()
  150. {
  151. if(!canBatchChangeRoadmap) return;
  152. var selectRows = $('#storyList tr.checked').map(function(){return $(this).data('id')}).get();
  153. var selectBranches = new Set();
  154. for(var row of selectRows)
  155. {
  156. var branch = roadmapStories[row].branch;
  157. selectBranches.add(branch);
  158. }
  159. branches = Array.from(selectBranches).join();
  160. link = createLink('roadmap', 'ajaxGetChangeRoadmaps', 'product=' + product + '&roadmapID=' + roadmapID + '&branch=' + branches);
  161. $('#roadmapRows').load(link, function()
  162. {
  163. if($('#roadmapRows li').length <= 9 )
  164. {
  165. $('#searchMenu').hide();
  166. }
  167. else
  168. {
  169. $('#searchMenu').show();
  170. }
  171. });
  172. });
  173. };
  174. });