common.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. * Load product projects.
  3. *
  4. * @param int productID
  5. * @access public
  6. * @return void
  7. */
  8. function loadProductProject(productID)
  9. {
  10. if(productID == 0)
  11. {
  12. replaceProject(defaultProject, true);
  13. loadProductExecutions(productID, $('#project').val());
  14. return;
  15. }
  16. var project = $('#project').length > 0 ? $('#project').val() : 0;
  17. var link = createLink('product', 'ajaxGetProjects', 'productID=' + productID + '&branch=0&project=' + project + '&pageType=old');
  18. $.get(link, function(data)
  19. {
  20. replaceProject(data);
  21. $('#projectIdBox select').trigger('change');
  22. });
  23. }
  24. /**
  25. * Load product、project executions.
  26. *
  27. * @param int $productID
  28. * @access public
  29. * @return void
  30. */
  31. function loadProductExecutions(productID, projectID)
  32. {
  33. if($('#project').length > 0)
  34. {
  35. if(productID == 0 && projectID == 0)
  36. {
  37. replaceExecution(defaultExecution, true);
  38. return;
  39. }
  40. if(productID == 0)
  41. {
  42. var link = createLink('project', 'ajaxGetExecutions', 'projectID=' + projectID + '&mode=multiple,leaf&type=all&pageType=old');
  43. }
  44. else
  45. {
  46. var link = createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&project=' + $('#project').val() + '&branch=0&pageType=old&executionID=' + $('#executionIdBox #execution').val() + '&from=&mode=multiple,leaf');
  47. }
  48. }
  49. else // In classic mode.
  50. {
  51. if(productID == 0)
  52. {
  53. replaceExecution(defaultExecution);
  54. return;
  55. }
  56. var link = createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&project=0&branch=0&pageType=old&executionID=' + $('#executionIdBox #execution').val());
  57. }
  58. $.get(link, function(data)
  59. {
  60. replaceExecution(data);
  61. });
  62. }
  63. /**
  64. * Replace project data.
  65. *
  66. * @param string data
  67. * @access public
  68. * @return void
  69. */
  70. function replaceProject(data, emptySelect)
  71. {
  72. $('#projectIdBox select').replaceWith(data);
  73. $('#projectIdBox .chosen-container').remove();
  74. $('#projectIdBox .picker').remove();
  75. if($('#projectIdBox select option').length > maxCount)
  76. {
  77. $('#projectIdBox select').picker();
  78. }
  79. else
  80. {
  81. $('#projectIdBox select').chosen();
  82. }
  83. if(typeof(emptySelect) != 'undefined') $('#projectIdBox select').val('').trigger('chosen:updated');
  84. }
  85. /**
  86. * Replace execution data.
  87. *
  88. * @param string data
  89. * @access public
  90. * @return void
  91. */
  92. function replaceExecution(data, emptySelect)
  93. {
  94. $('#executionIdBox select').replaceWith(data);
  95. $('#executionIdBox .chosen-container').remove();
  96. $('#executionIdBox .picker').remove();
  97. if($('#executionIdBox select option').length > maxCount)
  98. {
  99. $('#executionIdBox select').picker();
  100. }
  101. else
  102. {
  103. $('#executionIdBox select').chosen();
  104. }
  105. if(typeof(emptySelect) != 'undefined') $('#executionIdBox select').val('').trigger('chosen:updated');
  106. }
  107. /**
  108. * Load dept users.
  109. *
  110. * @param int $deptID
  111. * @param string $key id|account
  112. * @access public
  113. * @return void
  114. */
  115. function loadDeptUsers(deptID, key)
  116. {
  117. if(typeof(key) == 'undefined') key = 'id';
  118. var link = createLink('dept', 'ajaxGetUsers', 'dept=' + deptID + '&user=' + $('#userBox #user').val() + '&key=' + key);
  119. $.get(link, function(data)
  120. {
  121. $('#userBox select').replaceWith(data);
  122. $('#userBox .chosen-container').remove();
  123. $('#userBox select').chosen();
  124. })
  125. }
  126. /**
  127. * Flush width.
  128. *
  129. * @param object $obj
  130. * @access public
  131. * @return void
  132. */
  133. function flushWidth(obj)
  134. {
  135. var maxWidth = 0;
  136. $(obj).find('.input-group').each(function()
  137. {
  138. var $groupAddon = $(this).find('.input-group-addon:first');
  139. if($groupAddon.length > 0)
  140. {
  141. var width = $(this).find('.input-group-addon:first').outerWidth();
  142. if(width > maxWidth) maxWidth = width;
  143. }
  144. });
  145. $(obj).find('.input-group').each(function()
  146. {
  147. var $groupAddon = $(this).find('.input-group-addon:first');
  148. var padding = 1;
  149. if($groupAddon.length > 0)
  150. {
  151. while($groupAddon.outerWidth() < maxWidth)
  152. {
  153. $groupAddon.css('padding-right', padding + 'px').css('padding-left', padding + 'px');
  154. padding++;
  155. }
  156. }
  157. });
  158. }
  159. /**
  160. * Fix scroll.
  161. *
  162. * @access public
  163. * @return void
  164. */
  165. function fixScroll()
  166. {
  167. var $scrollwrapper = $('div.datatable').first().find('.scroll-wrapper:first');
  168. if($scrollwrapper.length == 0)return;
  169. var $tfoot = $('div.table-footer');
  170. var scrollOffset = $scrollwrapper.offset().top + $scrollwrapper.find('.scroll-slide').height();
  171. if($tfoot.length > 0) scrollOffset += $tfoot.height();
  172. if($('div.datatable.head-fixed').length == 0) scrollOffset -= '29';
  173. var windowH = $(window).height();
  174. var bottom = 25 + $tfoot.height();
  175. if(scrollOffset > windowH + $(window).scrollTop())
  176. {
  177. $scrollwrapper.css({'position': 'fixed', 'bottom': bottom + 'px'});
  178. $tfoot.addClass('fixed-footer');
  179. }
  180. $(window).scroll(function()
  181. {
  182. if(scrollOffset <= windowH + $(window).scrollTop())
  183. {
  184. $scrollwrapper.css({'position':'relative', 'bottom': '0px'});
  185. $tfoot.removeClass('fixed-footer');
  186. }
  187. else if($scrollwrapper.css('position') != 'fixed')
  188. {
  189. if(!$tfoot.hasClass('fixed-footer')) $tfoot.addClass('fixed-footer');
  190. $scrollwrapper.css({'position': 'fixed', 'bottom': bottom + 'px'});
  191. }
  192. });
  193. }