m.common.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /**
  2. * Load all users as assignedTo list.
  3. *
  4. * @access public
  5. * @return void
  6. */
  7. function loadAllUsers()
  8. {
  9. link = createLink('bug', 'ajaxLoadAllUsers', 'selectedUser=' + $('#assignedTo').val());
  10. $('#assignedToBox').load(link, function()
  11. {
  12. moduleID = $('#module').val();
  13. productID = $('#product').val();
  14. setAssignedTo(moduleID, productID);
  15. });
  16. }
  17. /**
  18. * Load by branch.
  19. *
  20. * @access public
  21. * @return void
  22. */
  23. function loadBranch()
  24. {
  25. $('#taskIdBox').innerHTML = '<select id="task"></select>'; // Reset the task.
  26. productID = $('#product').val();
  27. loadProductModules(productID);
  28. loadProductExecutions(productID);
  29. loadProductBuilds(productID);
  30. loadProductplans(productID);
  31. loadProductStories(productID);
  32. }
  33. /**
  34. * Load product modules.
  35. *
  36. * @param productID $productID
  37. * @access public
  38. * @return void
  39. */
  40. function loadProductModules(productID)
  41. {
  42. branch = $('#branch').val();
  43. if(typeof(branch) == 'undefined') branch = 0;
  44. link = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=bug&branch=' + branch + '&rootModuleID=0&returnType=mhtml&needManage=true');
  45. $('#moduleIdBox').load(link);
  46. }
  47. /**
  48. * Load product plans.
  49. *
  50. * @param productID $productID
  51. * @access public
  52. * @return void
  53. */
  54. function loadProductplans(productID)
  55. {
  56. branch = $('#branch').val();
  57. if(typeof(branch) == 'undefined') branch = 0;
  58. link = createLink('productplan', 'ajaxGetProductplans', 'productID=' + productID + '&branch=' + branch);
  59. $('#planIdBox').load(link);
  60. }
  61. /**
  62. * Load executions of product.
  63. *
  64. * @param int $productID
  65. * @access public
  66. * @return void
  67. */
  68. function loadProductExecutions(productID)
  69. {
  70. branch = $('#branch').val();
  71. if(typeof(branch) == 'undefined') branch = 0;
  72. if(typeof(oldExecutionID) == 'undefined') oldExecutionID = 0;
  73. link = createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&executionID=' + oldExecutionID + '&branch=' + branch);
  74. $('#executionIdBox').load(link);
  75. }
  76. /**
  77. * load assignedTo and stories of module.
  78. *
  79. * @access public
  80. * @return void
  81. */
  82. function loadModuleRelated()
  83. {
  84. moduleID = $('#module').val();
  85. productID = $('#product').val();
  86. setAssignedTo(moduleID, productID);
  87. setStories(moduleID, productID);
  88. }
  89. /**
  90. * Set the assignedTo field.
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function setAssignedTo(moduleID, productID)
  96. {
  97. if(typeof(productID) == 'undefined') productID = $('#product').val();
  98. if(typeof(moduleID) == 'undefined') moduleID = $('#module').val();
  99. link = createLink('bug', 'ajaxGetModuleOwner', 'moduleID=' + moduleID + '&productID=' + productID);
  100. $.get(link, function(owner)
  101. {
  102. owner = JSON.parse(owner);
  103. var account = owner[0];
  104. var realName = owner[1];
  105. var isExist = false;
  106. var count = $('#assignedTo').find('option').length;
  107. for(var i = 0; i < count; i++)
  108. {
  109. if($('#assignedTo').get(0).options[i].value == account)
  110. {
  111. isExist = true;
  112. break;
  113. }
  114. }
  115. if(!isExist && account)
  116. {
  117. option = "<option title='" + realName + "' value='" + account + "'>" + realName + "</option>";
  118. $("#assignedTo").append(option);
  119. }
  120. $('#assignedTo').val(account);
  121. });
  122. }
  123. /**
  124. * Load execution related bugs and tasks.
  125. *
  126. * @param int $executionID
  127. * @access public
  128. * @return void
  129. */
  130. function loadExecutionRelated(executionID)
  131. {
  132. if(executionID)
  133. {
  134. loadExecutionTasks(executionID);
  135. loadExecutionStories(executionID);
  136. loadExecutionBuilds(executionID);
  137. loadAssignedTo(executionID);
  138. }
  139. else
  140. {
  141. $('#taskIdBox').innerHTML = '<select id="task"></select>'; // Reset the task.
  142. loadProductStories($('#product').val());
  143. loadProductBuilds($('#product').val());
  144. }
  145. }
  146. /**
  147. *Load all builds of one execution or product.
  148. *
  149. * @access public
  150. * @return void
  151. */
  152. function loadAllBuilds(that)
  153. {
  154. productID = $('#product').val();
  155. executionID = $('#execution').val();
  156. if(page == 'edit') buildBox = $(that).parent().prev().filter('span').attr('id');
  157. if(executionID)
  158. {
  159. loadAllExecutionBuilds(executionID, productID);
  160. }
  161. else
  162. {
  163. loadAllProductBuilds(productID);
  164. }
  165. }
  166. /**
  167. * Load all builds of the execution.
  168. *
  169. * @param int $executionID
  170. * @param int $productID
  171. * @access public
  172. * @return void
  173. */
  174. function loadAllExecutionBuilds(executionID, productID)
  175. {
  176. branch = $('#branch').val();
  177. if(typeof(branch) == 'undefined') branch = 0;
  178. if(page == 'create')
  179. {
  180. oldOpenedBuild = $('#openedBuild').val() ? $('#openedBuild').val() : 0;
  181. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&needCreate=true&type=all');
  182. $('#buildBox').load(link, function(){ notice();});
  183. }
  184. if(page == 'edit')
  185. {
  186. if(buildBox == 'openedBuildBox')
  187. {
  188. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&needCreate=true&type=all');
  189. $('#openedBuildBox').load(link);
  190. }
  191. if(buildBox == 'resolvedBuildBox')
  192. {
  193. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=0&index=0&needCreate=true&type=all');
  194. $('#resolvedBuildBox').load(link);
  195. }
  196. }
  197. }
  198. /**
  199. * Load all builds of the product.
  200. *
  201. * @param int $productID
  202. * @access public
  203. * @return void
  204. */
  205. function loadAllProductBuilds(productID)
  206. {
  207. branch = $('#branch').val();
  208. if(typeof(branch) == 'undefined') branch = 0;
  209. if(page == 'create')
  210. {
  211. oldOpenedBuild = $('#openedBuild').val() ? $('#openedBuild').val() : 0;
  212. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&type=all');
  213. $('#buildBox').load(link, function(){ notice();});
  214. }
  215. if(page == 'edit')
  216. {
  217. if(buildBox == 'openedBuildBox')
  218. {
  219. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&type=all');
  220. $('#openedBuildBox').load(link);
  221. }
  222. if(buildBox == 'resolvedBuildBox')
  223. {
  224. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=0&index=0&type=all');
  225. $('#resolvedBuildBox').load(link);
  226. }
  227. }
  228. }
  229. /**
  230. * Load product stories
  231. *
  232. * @param int $productID
  233. * @access public
  234. * @return void
  235. */
  236. function loadProductStories(productID)
  237. {
  238. branch = $('#branch').val();
  239. if(typeof(branch) == 'undefined') branch = 0;
  240. if(typeof(oldStoryID) == 'undefined') oldStoryID = 0;
  241. link = createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleId=0&storyID=' + oldStoryID);
  242. $('#storyIdBox').load(link);
  243. }
  244. /**
  245. * Load product builds.
  246. *
  247. * @param productID $productID
  248. * @access public
  249. * @return void
  250. */
  251. function loadProductBuilds(productID)
  252. {
  253. branch = $('#branch').val();
  254. if(typeof(branch) == 'undefined') branch = 0;
  255. if(typeof(oldOpenedBuild) == 'undefined') oldOpenedBuild = 0;
  256. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  257. if(page == 'create')
  258. {
  259. $('#buildBox').load(link, function(){ notice();});
  260. }
  261. else
  262. {
  263. $('#openedBuildBox').load(link);
  264. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  265. $('#resolvedBuildBox').load(link);
  266. }
  267. }
  268. /**
  269. * Load execution tasks.
  270. *
  271. * @param executionID $executionID
  272. * @access public
  273. * @return void
  274. */
  275. function loadExecutionTasks(executionID)
  276. {
  277. link = createLink('task', 'ajaxGetExecutionTasks', 'executionID=' + executionID + '&taskID=' + oldTaskID);
  278. $('#taskIdBox').load(link);
  279. }
  280. /**
  281. * Load execution stories.
  282. *
  283. * @param executionID $executionID
  284. * @access public
  285. * @return void
  286. */
  287. function loadExecutionStories(executionID)
  288. {
  289. branch = $('#branch').val();
  290. if(typeof(branch) == 'undefined') branch = 0;
  291. if(typeof(oldStoryID) == 'undefined') oldStoryID = 0;
  292. link = createLink('story', 'ajaxGetExecutionStories', 'executionID=' + executionID + '&productID=' + $('#product').val() + '&branch=' + branch + '&moduleID=0&storyID=' + oldStoryID);
  293. $('#storyIdBox').load(link);
  294. }
  295. /**
  296. * Load builds of a execution.
  297. *
  298. * @param int $executionID
  299. * @access public
  300. * @return void
  301. */
  302. function loadExecutionBuilds(executionID)
  303. {
  304. branch = $('#branch').val();
  305. if(typeof(branch) == 'undefined') branch = 0;
  306. productID = $('#product').val();
  307. if(page == 'create') oldOpenedBuild = $('#openedBuild').val() ? $('#openedBuild').val() : 0;
  308. if(page == 'create')
  309. {
  310. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + "&branch=" + branch + "&index=0&needCreate=true");
  311. $('#buildBox').load(link, function(){ notice();});
  312. }
  313. else
  314. {
  315. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  316. $('#openedBuildBox').load(link);
  317. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  318. $('#resolvedBuildBox').load(link);
  319. }
  320. }
  321. /**
  322. * Set story field.
  323. *
  324. * @param moduleID $moduleID
  325. * @param productID $productID
  326. * @access public
  327. * @return void
  328. */
  329. function setStories(moduleID, productID)
  330. {
  331. var branch = $('#branch').val();
  332. if(typeof(branch) == 'undefined') branch = 0;
  333. link = createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleID=' + moduleID);
  334. $.get(link, function(stories)
  335. {
  336. if(!stories) stories = '<select id="story" name="story" class="form-control"></select>';
  337. $('#story').replaceWith(stories);
  338. });
  339. }
  340. /**
  341. * Load team members of the execution as assignedTo list.
  342. *
  343. * @param int $executionID
  344. * @access public
  345. * @return void
  346. */
  347. function loadAssignedTo(executionID)
  348. {
  349. link = createLink('bug', 'ajaxLoadAssignedTo', 'executionID=' + executionID + '&selectedUser=' + $('#assignedTo').val());
  350. $('#assignedToBox').load(link);
  351. }
  352. /**
  353. * notice for create build.
  354. *
  355. * @access public
  356. * @return void
  357. */
  358. function notice()
  359. {
  360. $('#buildBoxActions').empty().hide();
  361. if($('#openedBuild').find('option').length < 1)
  362. {
  363. var html = '';
  364. if($('#execution').val() == '')
  365. {
  366. branch = $('#branch').val();
  367. if(typeof(branch) == 'undefined') branch = 0;
  368. html += '<a href="' + createLink('release', 'create', 'productID=' + $('#product').val() + '&branch=' + branch) + '" target="_blank" style="padding-right:5px">' + createRelease + '</a> ';
  369. html += '<a href="javascript:loadProductBuilds(' + $('#product').val() + ')">' + refresh + '</a>';
  370. }
  371. else
  372. {
  373. html += '<a href="' + createLink('build', 'create','executionID=' + $('#execution').val()) + '" target="_blank" style="padding-right:5px">' + createBuild + '</a> ';
  374. html += '<a href="javascript:loadExecutionBuilds(' + $('#execution').val() + ')">' + refresh + '</a>';
  375. }
  376. var $bba = $('#buildBoxActions');
  377. if($bba.length)
  378. {
  379. $bba.html(html);
  380. $bba.show();
  381. }
  382. else
  383. {
  384. if($('#buildBox').closest('tr').find('td').length > 1)
  385. {
  386. $('#buildBox').closest('td').next().attr('id', 'buildBoxActions');
  387. $('#buildBox').closest('td').next().html(html);
  388. }
  389. else
  390. {
  391. html = "<td id='buildBoxActions'>" + html + '</td>';
  392. $('#buildBox').closest('td').after(html);
  393. }
  394. }
  395. }
  396. }
  397. /**
  398. * Set duplicate.
  399. *
  400. * @param string $resolution
  401. * @access public
  402. * @return void
  403. */
  404. function setDuplicate(resolution)
  405. {
  406. if(resolution == 'duplicate')
  407. {
  408. $('#duplicateBugBox').removeClass('hidden');
  409. }
  410. else
  411. {
  412. $('#duplicateBugBox').addClass('hidden');
  413. }
  414. }
  415. $(function()
  416. {
  417. if($('#execution').val()) loadExecutionRelated($('#execution').val());
  418. });