view.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function showLink(releaseID, type, param)
  2. {
  3. var method = type == 'story' ? 'linkStory' : 'linkBug';
  4. if(typeof(param) == 'undefined') param = '&browseType=' + type + '&param=0';
  5. if(type == 'leftBug') param += '&type=leftBug';
  6. loadURL(createLink('projectrelease', method, 'releaseID=' + releaseID + param), type);
  7. $('.actions').find("a[href*='" + type + "']").addClass('hidden');
  8. }
  9. /**
  10. * Load URL.
  11. *
  12. * @param string $url
  13. * @param string$type
  14. * @access public
  15. * @return void
  16. */
  17. function loadURL(url, type)
  18. {
  19. $.get(url, function(data)
  20. {
  21. var $pane = $(type == 'story' ? '#stories' : (type == 'leftBug' ? '#leftBugs' : '#bugs'));
  22. $pane.find('.main-table').hide();
  23. var $linkBox = $pane.find('.linkBox');
  24. $linkBox.html(data).removeClass('hidden');
  25. $linkBox.find('[data-ride="table"]').table();
  26. $linkBox.find('[data-ride="pager"]').pager();
  27. $linkBox.find('[data-ride="pager"] li a.pager-item').click(function()
  28. {
  29. loadURL($(this).attr('href'), type);
  30. return false;
  31. });
  32. $linkBox.find('[data-ride="pager"] .pager-size-menu a[data-size]').off('click');
  33. $linkBox.find('[data-ride="pager"] .pager-size-menu a[data-size]').click(function()
  34. {
  35. line = $linkBox.find('[data-ride="pager"]').attr('data-link-creator');
  36. line = line.replace('{recPerPage}', $(this).attr('data-size')).replace('{page}', $linkBox.find('[data-ride="pager"]').attr('data-page'));
  37. $.cookie($linkBox.find('[data-ride="pager"]').attr('data-page-cookie'), $(this).attr('data-size'), {expires:config.cookieLife, path:config.webRoot});
  38. loadURL(line, type);
  39. return false;
  40. });
  41. $.toggleQueryBox(true, $linkBox.find('#queryBox'));
  42. });
  43. }
  44. $(function()
  45. {
  46. if(link == 'true') showLink(releaseID, type, param);
  47. var infoShowed = false;
  48. $('.nav.nav-tabs a[data-toggle="tab"]').on('shown.zui.tab', function(e)
  49. {
  50. var href = $(e.target).attr('href');
  51. var tabPane = $(href + '.tab-pane');
  52. if(tabPane.size() == 0) return;
  53. var formID = tabPane.find('.linkBox').find('form:last');
  54. if(formID.size() == 0) formID = tabPane.find('form:last');
  55. if(href == '#releaseInfo' && !infoShowed)
  56. {
  57. var $tr = $('#releaseInfo .detail-content .table-data tbody tr:first');
  58. width = $tr.width() - $tr.find('th').width();
  59. $('#releaseInfo img').each(function()
  60. {
  61. if($(this).parent().prop('tagName').toLowerCase() == 'a') $(this).unwrap();
  62. setImageSize($(this), width, 0);
  63. });
  64. infoShowed = true;
  65. }
  66. });
  67. $('.table-story').table(
  68. {
  69. statisticCreator: function(table)
  70. {
  71. var $checkedRows = table.getTable().find(table.isDataTable ? '.datatable-row-left.checked' : 'tbody>tr.checked');
  72. var $originTable = table.isDataTable ? table.$.find('.datatable-origin') : null;
  73. var checkedTotal = $checkedRows.length;
  74. if(!checkedTotal) return;
  75. var checkedEstimate = 0;
  76. var checkedCase = 0;
  77. var rateCount = checkedTotal;
  78. $checkedRows.each(function()
  79. {
  80. var $row = $(this);
  81. if($originTable)
  82. {
  83. $row = $originTable.find('tbody>tr[data-id="' + $row.data('id') + '"]');
  84. }
  85. var data = $row.data();
  86. checkedEstimate += data.estimate;
  87. if(data.cases > 0)
  88. {
  89. checkedCase += 1;
  90. }
  91. else if(data.children != undefined && data.children > 0)
  92. {
  93. rateCount -= 1;
  94. }
  95. });
  96. var rate = '0%';
  97. if(rateCount) rate = Math.round(checkedCase / rateCount * 100) + '%';
  98. if(checkedTotal == 0) return storySummary;
  99. return checkedSummary.replace('%total%', checkedTotal)
  100. .replace('%estimate%', checkedEstimate.toFixed(1))
  101. .replace('%rate%', rate);
  102. }
  103. });
  104. })