common.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. $(function()
  2. {
  3. if(typeof(resetActive) != 'undefined') return false;
  4. if(typeof(storyType) == 'undefined') storyType = '';
  5. if(typeof(rawModule) == 'undefined') rawModule = 'product';
  6. if(typeof(app) == 'undefined') app = '';
  7. if(typeof(execution) != 'undefined') rawModule = 'projectstory';
  8. if(['project', 'projectstory'].indexOf(rawModule) === -1 && app != 'qa')
  9. {
  10. if(app != 'my') $('#navbar .nav li').removeClass('active');
  11. $("#navbar .nav li[data-id=" + storyType + ']').addClass('active');
  12. $('#subNavbar li[data-id="' + storyType + '"]').addClass('active');
  13. }
  14. if($('#navbar .nav>li[data-id=story] .dropdown-menu').length)
  15. {
  16. $('#navbar .nav li[data-id=story]').addClass('active');
  17. $("#navbar>ul>li[data-id='story']>ul>li[data-id!='" + storyType + "']").removeClass('active');
  18. $("#navbar>ul>li[data-id='story']>ul>li[data-id='" + storyType + "']").addClass('active');
  19. $('#navbar .nav>li[data-id=story]>a').html($('#navbar .nav li.active [data-id=' + storyType + ']').text() + '<span class="caret"></span>');
  20. }
  21. var $saveButton = $('#saveButton');
  22. var $saveDraftButton = $('#saveDraftButton');
  23. $saveButton.on('click', function(e)
  24. {
  25. $saveButton.attr('type', 'submit').attr('disabled', true);
  26. $saveDraftButton.attr('disabled', true);
  27. var storyStatus = !$('#reviewer').val() || $('#needNotReview').is(':checked') ? 'active' : 'reviewing';
  28. $('<input />').attr('type', 'hidden').attr('name', 'status').attr('value', storyStatus).appendTo('#dataform');
  29. $('#dataform').submit();
  30. e.preventDefault();
  31. setTimeout(function()
  32. {
  33. if($saveButton.attr('disabled') == 'disabled')
  34. {
  35. setTimeout(function()
  36. {
  37. $saveButton.attr('type', 'button').removeAttr('disabled');
  38. $saveDraftButton.removeAttr('disabled');
  39. }, 10000);
  40. }
  41. else
  42. {
  43. $saveDraftButton.removeAttr('disabled');
  44. }
  45. }, 100);
  46. });
  47. $saveDraftButton.on('click', function(e)
  48. {
  49. $saveButton.attr('disabled', true);
  50. $saveDraftButton.attr('type', 'submit').attr('disabled', true);
  51. storyStatus = 'draft';
  52. if(typeof(page) != 'undefined' && page == 'change') storyStatus = 'changing';
  53. if(typeof(page) !== 'undefined' && page == 'edit' && $('#status').val() == 'changing') storyStatus = 'changing';
  54. $('<input />').attr('type', 'hidden').attr('name', 'status').attr('value', storyStatus).appendTo('#dataform');
  55. $('#dataform').submit();
  56. e.preventDefault();
  57. setTimeout(function()
  58. {
  59. if($saveDraftButton.attr('disabled') == 'disabled')
  60. {
  61. setTimeout(function()
  62. {
  63. $saveButton.removeAttr('disabled');
  64. $saveDraftButton.attr('type', 'button').removeAttr('disabled');
  65. }, 10000);
  66. }
  67. else
  68. {
  69. $saveButton.removeAttr('disabled');
  70. }
  71. }, 100);
  72. });
  73. })
  74. /**
  75. * Get status.
  76. *
  77. * @param method $method
  78. * @param params $params
  79. * @access public
  80. * @return void
  81. */
  82. function getStatus(method, params)
  83. {
  84. $.get(createLink('story', 'ajaxGetStatus', "method=" + method + '&params=' + params), function(status)
  85. {
  86. $('form #status').val(status).change();
  87. });
  88. }
  89. /**
  90. * Load URS.
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function loadURS(allURS)
  96. {
  97. var productID = $('#product').val();
  98. var branchID = $('#branch').val();
  99. var moduleID = typeof(allURS) == 'undefined' ? $('#module').val() : 0;
  100. var requirementList = $('#URS').val();
  101. requirementList = requirementList ? requirementList.join(',') : '';
  102. var link = createLink('story', 'ajaxGetURS', 'productID=' + productID + '&branchID=' + branchID + '&moduleID=' + moduleID + '&requirementList=' + requirementList);
  103. $.post(link, function(data)
  104. {
  105. $('#URS').replaceWith(data);
  106. $('#URS_chosen').remove();
  107. $('#URS').chosen();
  108. });
  109. }
  110. $('.twins').mouseover(function() {
  111. if(page == 'edit') return;
  112. $(this).parent('ul').find('a.unlink').addClass('hide');
  113. $(this).find('.unlink').removeClass('hide');
  114. });
  115. $('.twins').mouseenter(function() {
  116. $('[data-toggle="popover"]').popover('hide');
  117. });
  118. $('.twins').mouseout(function() {
  119. if(page == 'edit') return;
  120. $(this).find('.unlink').addClass('hide');
  121. });
  122. if(typeof(relievedTip) != 'undefined')
  123. {
  124. $('[data-toggle="popover"]').each(function(item) {
  125. $index = $(this).attr('data-id');
  126. $(this).popover({
  127. placement: 'bottom',
  128. html: true,
  129. content: '<div class="popover-icon"><i class="icon-info"></i></div><div class="content">' + relievedTip + '</div><div class="popover-custom text-right"><a href="javascript:relieve(' + $index + ')" class="text-active btn-info">' + relieved + '</a> <a href="javascript:popoverCancel(' + $index + ');" class="text-cancel">' + cancel + '</a></div>'
  130. });
  131. })
  132. }
  133. function relieve(index)
  134. {
  135. $.post(relieveURL, {twinID:index}, function(data){
  136. $('[data-id="' + index + '"]').popover('hide');
  137. if(data.result == 'success')
  138. {
  139. if(data.twinsCount != 0) $('[data-id="' + index + '"]').parent('li').remove();
  140. if(data.twinsCount == 0 || index == storyID)
  141. {
  142. $('[href="#legendTwins"]').parent('li').next('li').addClass('active');;
  143. $('[href="#legendTwins"]').parent('li').remove();
  144. $('#legendTwins').next('div').addClass('active');
  145. $('#legendTwins').remove();
  146. $('#twinsTitle').remove();
  147. $('#twinsList').remove();
  148. }
  149. }
  150. }, 'json');
  151. }
  152. function popoverCancel(index)
  153. {
  154. $('[data-id="' + index + '"]').popover('hide');
  155. if(page == 'edit') return;
  156. $('[data-id="' + index + '"]').addClass('hide');
  157. }
  158. /**
  159. * Reload parent window When operating in a pop-up window.
  160. *
  161. * @access public
  162. * @return void
  163. */
  164. function reloadByAjaxForm()
  165. {
  166. parent.location.reload();
  167. }