common.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. $(document).ready(function()
  2. {
  3. $('#startForm, #closeForm, #activateForm, #blockForm').ajaxForm(
  4. {
  5. finish:function(response)
  6. {
  7. if(response.locate)
  8. {
  9. if(response.locate == 'parent')
  10. {
  11. parent.$.cookie('selfClose', 1);
  12. setTimeout(function(){parent.$.closeModal(null, 'this')}, 1200);
  13. }
  14. else if(response.locate == 'parent.parent')
  15. {
  16. setTimeout(function(){parent.location.reload();}, 1200);
  17. }
  18. else
  19. {
  20. setTimeout(function(){window.location.href = response.locate;}, 1200);
  21. }
  22. }
  23. return false;
  24. }
  25. });
  26. })
  27. /**
  28. * Adjust priBox width.
  29. *
  30. * @access public
  31. * @return void
  32. */
  33. function adjustPriBoxWidth()
  34. {
  35. var boxWidth = $('#ownerAndPriBox').width();
  36. var beginWidth = $("input[name='begin']").outerWidth();
  37. var addonWidth = $('#ownerAndPriBox .input-group-addon').outerWidth();
  38. var width = boxWidth - beginWidth - addonWidth;
  39. $('#pri,#pri_chosen .chosen-single').css('width', width > 0 ? width : '160px');
  40. }
  41. /**
  42. * Create bug from fail case.
  43. *
  44. * @param object $obj
  45. * @access public
  46. * @return void
  47. */
  48. function createBug(obj)
  49. {
  50. var $form = $(obj).closest('form');
  51. var params = $form.data('params');
  52. var stepIdList = '';
  53. $form.find('.step .step-id :checkbox').each(function()
  54. {
  55. if($(this).prop('checked')) stepIdList += $(this).val() + '_';
  56. });
  57. var onlybody = config.onlybody;
  58. config.onlybody = 'no';
  59. var link = createLink('bug', 'create', params + ',stepIdList=' + stepIdList);
  60. if(onlybody = 'yes') link += '#app=qa';
  61. if(tab == 'my')
  62. {
  63. window.parent.$.apps.open(link, 'qa');
  64. }
  65. else
  66. {
  67. window.open(link, '_blank');
  68. }
  69. config.onlybody = onlybody;
  70. }
  71. /**
  72. * Load execution related
  73. *
  74. * @param int $executionID
  75. * @access public
  76. * @return void
  77. */
  78. function loadExecutionRelated(executionID)
  79. {
  80. loadExecutionBuilds(executionID);
  81. }
  82. /**
  83. * Load execution builds.
  84. *
  85. * @param int $executionID
  86. * @access public
  87. * @return void
  88. */
  89. function loadExecutionBuilds(executionID)
  90. {
  91. var selectedBuild = $('#build').val();
  92. if(!selectedBuild) selectedBuild = 0;
  93. var link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + $('#product').val() + '&varName=testTaskBuild&build=' + selectedBuild);
  94. if(executionID == 0) link = createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + $('#product').val() + '&varName=build&build=' + selectedBuild + '&branch=&index=&needCreate=&type=noempty,notrunk,withexecution');
  95. $('#buildBox').load(link, function()
  96. {
  97. $('#build').chosen();
  98. });
  99. }
  100. /**
  101. * Load test report.
  102. *
  103. * @param int productID
  104. * @access public
  105. * @return void
  106. */
  107. function loadTestReports(productID)
  108. {
  109. link = createLink('testtask', 'ajaxGetTestReports', 'productID=' + productID);
  110. $.get(link, function(data)
  111. {
  112. if(!data) data = '<select id="testreport" name="testreport" class="form-control"></select>';
  113. $('#testreport').replaceWith(data);
  114. $('#testreport_chosen').remove();
  115. $("#testreport").chosen();
  116. });
  117. }
  118. /**
  119. * when begin date input change and end date input is null
  120. * change end date input to begin's after day
  121. *
  122. * @access public
  123. * @return void
  124. */
  125. function suitEndDate()
  126. {
  127. beginDate = $('#begin').val();
  128. if(!beginDate) return;
  129. endDate = $('#end').val();
  130. if(endDate) return;
  131. endDate = $.zui.formatDate(convertStringToDate(beginDate).addDays(1), 'yyyy-MM-dd');
  132. $('#end').val(endDate);
  133. }
  134. /**
  135. * Convert a date string like 2011-11-11 to date object in js.
  136. *
  137. * @param string $date
  138. * @access public
  139. * @return date
  140. */
  141. function convertStringToDate(dateString)
  142. {
  143. dateString = dateString.split('-');
  144. dateString = dateString[1] + '/' + dateString[2] + '/' + dateString[0];
  145. return Date.parse(dateString);
  146. }