common.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. $(function()
  2. {
  3. var page = window.page || '';
  4. var flow = window.flow;
  5. $('#subNavbar a[data-toggle=dropdown]').parent().addClass('dropdown dropdown-hover');
  6. if(page == 'create' || page == 'edit' || page == 'assignedto' || page == 'confirm')
  7. {
  8. oldProductID = $('#product').val();
  9. }
  10. if(window.flow != 'full')
  11. {
  12. $('.querybox-toggle').click(function()
  13. {
  14. $(this).parent().toggleClass('active');
  15. });
  16. }
  17. });
  18. if($('#openedBuild').length || $('#resolvedBuild').length || $('[name^=openedBuilds]').length)
  19. {
  20. $.get(createLink('bug', 'ajaxGetReleasedBuilds', 'productID=' + productID), function(data){releasedBuilds = data;}, 'json');
  21. $('#openedBuild, #resolvedBuild, form [name^=openedBuilds]').picker({optionRender: markReleasedBuilds});
  22. }
  23. /**
  24. * Mark released builds.
  25. *
  26. * @param object $option
  27. * @access public
  28. * @return void
  29. */
  30. function markReleasedBuilds($option)
  31. {
  32. var build = $option.attr('data-value');
  33. if($.inArray(build, releasedBuilds) != -1)
  34. {
  35. if(!$option.find('.label-released').length)
  36. {
  37. var optionText = $option.find('.picker-option-text').html();
  38. $option.find('.picker-option-text').replaceWith("<p class='picker-option-text no-margin'>" + optionText + " <span class='label label-released label-primary label-outline'>" + released + "</span></p>");
  39. }
  40. }
  41. }
  42. /**
  43. * Load all fields.
  44. *
  45. * @param int $productID
  46. * @access public
  47. * @return void
  48. */
  49. function loadAll(productID)
  50. {
  51. if(typeof(changeProductConfirmed) != 'undefined' && !changeProductConfirmed)
  52. {
  53. firstChoice = confirm(confirmChangeProduct);
  54. changeProductConfirmed = true; // Only notice the user one time.
  55. if(!firstChoice)
  56. {
  57. $('#product').val(oldProductID);//Revert old product id if confirm is no.
  58. $('#product').trigger("chosen:updated");
  59. $('#product').chosen();
  60. return true;
  61. }
  62. loadAll(productID);
  63. }
  64. else
  65. {
  66. $('#taskIdBox').innerHTML = '<select id="task"></select>'; // Reset the task.
  67. $('#task').chosen();
  68. loadProductBranches(productID)
  69. }
  70. }
  71. /**
  72. * Load all users as assignedTo list.
  73. *
  74. * @access public
  75. * @return void
  76. */
  77. function loadAllUsers()
  78. {
  79. isClosedBug = typeof isClosedBug == 'undefined' ? false : isClosedBug;
  80. var params = isClosedBug ? '&params=devfirst' : '';
  81. var link = createLink('bug', 'ajaxLoadAllUsers', 'selectedUser=' + $('#assignedTo').val() + params);
  82. $.get(link, function(data)
  83. {
  84. if(data)
  85. {
  86. if(!isClosedBug)
  87. {
  88. var moduleID = $('#module').val();
  89. var productID = $('#product').val();
  90. setAssignedTo(moduleID, productID);
  91. }
  92. $('#assignedTo').replaceWith(data);
  93. $('#assignedTo_chosen').remove();
  94. $('#assignedTo').chosen();
  95. }
  96. });
  97. }
  98. /**
  99. * Set the assignedTo field.
  100. *
  101. * @param int $moduleID
  102. * @param int $productID
  103. * @access public
  104. * @return void
  105. */
  106. function setAssignedTo(moduleID, productID)
  107. {
  108. if(typeof(productID) == 'undefined') productID = $('#product').val();
  109. if(typeof(moduleID) == 'undefined') moduleID = $('#module').val();
  110. var link = createLink('bug', 'ajaxGetModuleOwner', 'moduleID=' + moduleID + '&productID=' + productID);
  111. $.get(link, function(owner)
  112. {
  113. owner = JSON.parse(owner);
  114. var account = owner[0];
  115. var realName = owner[1];
  116. var isExist = false;
  117. var count = $('#assignedTo').find('option').length;
  118. for(var i=0; i < count; i++)
  119. {
  120. if($('#assignedTo').get(0).options[i].value == account)
  121. {
  122. isExist = true;
  123. break;
  124. }
  125. }
  126. if(!isExist && account)
  127. {
  128. option = "<option title='" + realName + "' value='" + account + "'>" + realName + "</option>";
  129. $("#assignedTo").append(option);
  130. }
  131. $('#assignedTo').val(account);
  132. $("#assignedTo").trigger("chosen:updated");
  133. });
  134. }
  135. /**
  136. * Load by branch.
  137. *
  138. * @access public
  139. * @return void
  140. */
  141. function loadBranch()
  142. {
  143. $('#taskIdBox').innerHTML = '<select id="task"></select>'; // Reset the task.
  144. $('#task').chosen();
  145. productID = $('#product').val();
  146. loadProductModules(productID);
  147. loadProductProjects(productID);
  148. loadProductBuilds(productID);
  149. loadProductplans(productID);
  150. loadProductStories(productID);
  151. loadProductMembers(productID);
  152. }
  153. /**
  154. *Load all builds of one execution or product.
  155. *
  156. * @param object $object
  157. * @access public
  158. * @return void
  159. */
  160. function loadAllBuilds()
  161. {
  162. if(page == 'resolve')
  163. {
  164. oldResolvedBuild = $('#resolvedBuild').val() ? $('#resolvedBuild').val() : 0;
  165. link = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=0&type=all');
  166. $('#resolvedBuildBox').load(link);
  167. }
  168. else
  169. {
  170. productID = $('#product').val();
  171. var buildBox = '';
  172. if(page == 'edit') buildBox = $(object).closest('.input-group').attr('id');
  173. loadAllProductBuilds(productID, buildBox);
  174. }
  175. }
  176. /**
  177. * Load all builds of the execution.
  178. *
  179. * @param int $executionID
  180. * @param int $productID
  181. * @param string $buildBox
  182. * @access public
  183. * @return void
  184. */
  185. function loadAllExecutionBuilds(executionID, productID, buildBox)
  186. {
  187. branch = $('#branch').val();
  188. if(typeof(branch) == 'undefined') branch = 0;
  189. $.get(createLink('bug', 'ajaxGetReleasedBuilds', 'productID=' + productID), function(data){releasedBuilds = data;}, 'json');
  190. if(page == 'create')
  191. {
  192. oldOpenedBuild = $('#openedBuild').val() ? $('#openedBuild').val() : 0;
  193. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&needCreate=true&type=all');
  194. $.get(link, function(data)
  195. {
  196. if(!data) data = '<select id="openedBuild" name="openedBuild" class="form-control" multiple=multiple></select>';
  197. $('#openedBuild').replaceWith(data);
  198. $('#pickerDropMenu-pk_openedBuild').remove();
  199. $('#openedBuild').next('.picker').remove();
  200. notice();
  201. $("#openedBuild").picker({optionRender: markReleasedBuilds});
  202. })
  203. }
  204. if(page == 'edit')
  205. {
  206. if(buildBox == 'openedBuildBox')
  207. {
  208. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&needCreate=true&type=all');
  209. $('#openedBuildBox').load(link, function(){$(this).find('select').picker({optionRender: markReleasedBuilds})});
  210. }
  211. if(buildBox == 'resolvedBuildBox')
  212. {
  213. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch + '&type=all');
  214. $('#resolvedBuildBox').load(link, function(){$(this).find('select').picker({optionRender: markReleasedBuilds, dropWidth: 'auto'})});
  215. }
  216. }
  217. }
  218. /**
  219. * Load all builds of the product.
  220. *
  221. * @param int $productID
  222. * @param string $buildBox
  223. * @access public
  224. * @return void
  225. */
  226. function loadAllProductBuilds(productID, buildBox)
  227. {
  228. branch = $('#branch').val();
  229. if(typeof(branch) == 'undefined') branch = 0;
  230. $.get(createLink('bug', 'ajaxGetReleasedBuilds', 'productID=' + productID), function(data){releasedBuilds = data;}, 'json');
  231. if(page == 'create')
  232. {
  233. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&type=all');
  234. $.get(link, function(data)
  235. {
  236. if(!data) data = '<select id="openedBuild" name="openedBuild" class="form-control" multiple=multiple></select>';
  237. $('#openedBuild').replaceWith(data);
  238. $('#pickerDropMenu-pk_openedBuild').remove();
  239. $('#openedBuild').next('.picker').remove();
  240. notice();
  241. $("#openedBuild").picker({optionRender: markReleasedBuilds});
  242. })
  243. }
  244. if(page == 'edit')
  245. {
  246. if(buildBox == 'openedBuildBox')
  247. {
  248. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&type=all');
  249. $('#openedBuildBox').load(link, function(){$(this).find('select').picker({optionRender: markReleasedBuilds})});
  250. }
  251. if(buildBox == 'resolvedBuildBox')
  252. {
  253. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch + '&type=all');
  254. $('#resolvedBuildBox').load(link, function()
  255. {
  256. $(this).find('select').picker({optionRender: markReleasedBuilds, dropWidth: 'auto'})
  257. var $pkResolvedBuild = $('#pk_resolvedBuild-search');
  258. $pkResolvedBuild.closest('.picker').css('width', $pkResolvedBuild.closest('td').width());
  259. });
  260. }
  261. }
  262. }
  263. /**
  264. * Load product's modules.
  265. *
  266. * @param int $productID
  267. * @access public
  268. * @return void
  269. */
  270. function loadProductModules(productID)
  271. {
  272. branch = $('#branch').val();
  273. if(typeof(branch) == 'undefined') branch = 0;
  274. if(typeof(moduleID) == 'undefined') moduleID = 0;
  275. if(config.currentMethod == 'edit') moduleID = $('#module').val();
  276. link = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=bug&branch=' + branch + '&rootModuleID=0&returnType=html&fieldID=&needManage=true&extra=nodeleted&currentModuleID=' + moduleID);
  277. $('#moduleIdBox').load(link, function()
  278. {
  279. $(this).find('select').chosen()
  280. if(typeof(bugModule) == 'string') $('#moduleIdBox').prepend("<span class='input-group-addon' style='border-left-width: 1px;'>" + bugModule + "</span>");
  281. });
  282. }
  283. /**
  284. * Load product stories
  285. *
  286. * @param int $productID
  287. * @access public
  288. * @return void
  289. */
  290. function loadProductStories(productID)
  291. {
  292. branch = $('#branch').val();
  293. if(typeof(branch) == 'undefined') branch = 0;
  294. if(typeof(oldStoryID) == 'undefined') oldStoryID = 0;
  295. link = createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleId=0&storyID=' + oldStoryID);
  296. $('#storyIdBox').load(link, function(){$('#story').chosen();});
  297. }
  298. /**
  299. * Load projects of product.
  300. *
  301. * @param int $productID
  302. * @access public
  303. * @return void
  304. */
  305. function loadProductProjects(productID)
  306. {
  307. required = $('#project_chosen').hasClass('required');
  308. branch = $('#branch').val();
  309. if(typeof(branch) == 'undefined') branch = 0;
  310. link = createLink('product', 'ajaxGetProjects', 'productID=' + productID + '&branch=' + branch + '&projectID=' + oldProjectID);
  311. $('#projectBox').load(link, function()
  312. {
  313. $(this).find('select').chosen();
  314. var projectID = $('#project').find("option:selected").val();
  315. if(required) $(this).find('#project_chosen').addClass('required');
  316. loadProductExecutions(productID, projectID);
  317. });
  318. }
  319. /**
  320. * Load executions of product.
  321. *
  322. * @param int $productID
  323. * @param int $projectID
  324. * @access public
  325. * @return void
  326. */
  327. function loadProductExecutions(productID, projectID = 0)
  328. {
  329. required = $('#execution_chosen').hasClass('required');
  330. branch = $('#branch').val();
  331. if(typeof(branch) == 'undefined') branch = 0;
  332. if(projectID != 0 && projectExecutionPairs[projectID] !== undefined)
  333. {
  334. $('#executionIdBox').parents('.executionBox').hide();
  335. var execution = projectExecutionPairs[projectID];
  336. }
  337. else
  338. {
  339. $('#executionIdBox').parents('.executionBox').show();
  340. var execution = $('#execution').val();
  341. }
  342. link = createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&projectID=' + projectID + '&branch=' + branch + '&number=&executionID=' + execution + '&from=&mode=stagefilter');
  343. $('#executionIdBox').load(link, function()
  344. {
  345. $(this).find('select').chosen();
  346. if(typeof(bugExecution) == 'string') $('#executionIdBox').prepend("<span class='input-group-addon' id='executionBox' style='border-left-width: 0px;'>" + bugExecution + "</span>");
  347. if(required) $(this).find('#execution_chosen').addClass('required');
  348. changeAssignedTo(projectID);
  349. });
  350. projectID != 0 ? loadProjectBuilds(projectID) : loadProductBuilds(productID);
  351. }
  352. /**
  353. * Ajax change execution name.
  354. *
  355. * @param int $projectID
  356. * @access public
  357. * @return void
  358. */
  359. function changeAssignedTo(projectID)
  360. {
  361. if(parseInt(projectID))
  362. {
  363. loadProjectTeamMembers(projectID);
  364. if(page == 'create')
  365. {
  366. var link = createLink('bug', 'ajaxGetExecutionLang', 'projectID=' + projectID);
  367. $.post(link, function(executionLang)
  368. {
  369. $('#executionBox').html(executionLang);
  370. })
  371. }
  372. }
  373. else if($('#execution').val() != 0)
  374. {
  375. loadAssignedTo($('#execution').val());
  376. }
  377. else
  378. {
  379. var productID = $('#product').val();
  380. loadProductMembers(productID);
  381. }
  382. }
  383. /**
  384. * Load executions of product and project.
  385. *
  386. * @param int $productID
  387. * @param int $projectID
  388. * @param int $num
  389. * @access public
  390. * @return void
  391. */
  392. function loadProductExecutionsByProject(productID, projectID = 0, num = 0)
  393. {
  394. var branch = $('#branches' + num).val();
  395. if(typeof(branch) === undefined || branch == null) branch = 0;
  396. if(projectID == 'ditto')
  397. {
  398. for(var i = num - 1; i > 0, projectID == 'ditto'; i--)
  399. {
  400. projectID = $('#projects' + i).val();
  401. }
  402. }
  403. var link = createLink('product', 'ajaxGetExecutionsByProject', 'productID=' + productID + '&projectID=' + projectID + '&branch=' + branch + '&number=' + num);
  404. $.get(link, function(executions)
  405. {
  406. if(!executions) executions = '<select id="executions' + num + '" name="executions[' + num + ']" class="form-control"></select>';
  407. $('#executions' + num).replaceWith(executions);
  408. $("#executions" + num + "_chosen").remove();
  409. $("#executions" + num).next('.picker').remove();
  410. $("#executions" + num).chosen();
  411. });
  412. }
  413. /**
  414. * Load product plans.
  415. *
  416. * @param productID $productID
  417. * @access public
  418. * @return void
  419. */
  420. function loadProductplans(productID)
  421. {
  422. branch = $('#branch').val();
  423. if(typeof(branch) == 'undefined') branch = 0;
  424. link = createLink('productplan', 'ajaxGetProductplans', 'productID=' + productID + '&branch=' + branch);
  425. $('#planIdBox').load(link, function(){$(this).find('select').chosen()});
  426. }
  427. /**
  428. * Load product builds.
  429. *
  430. * @param productID $productID
  431. * @access public
  432. * @return void
  433. */
  434. function loadProductBuilds(productID)
  435. {
  436. branch = $('#branch').val();
  437. if(typeof(branch) == 'undefined') branch = 0;
  438. if(typeof(oldOpenedBuild) == 'undefined') oldOpenedBuild = 0;
  439. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  440. $.get(createLink('bug', 'ajaxGetReleasedBuilds', 'productID=' + productID), function(data){releasedBuilds = data;}, 'json');
  441. if(page == 'create')
  442. {
  443. $.get(link, function(data)
  444. {
  445. if(!data) data = '<select id="openedBuild" name="openedBuild" class="form-control" multiple=multiple></select>';
  446. $('#openedBuild').replaceWith(data);
  447. $('#pickerDropMenu-pk_openedBuild').remove();
  448. $('#openedBuild').next('.picker').remove();
  449. notice();
  450. $("#openedBuild").picker({optionRender: markReleasedBuilds});
  451. })
  452. }
  453. else
  454. {
  455. $('#openedBuildBox').load(link, function(){$(this).find('select').picker({optionRender: markReleasedBuilds})});
  456. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  457. $('#resolvedBuildBox').load(link, function(){$(this).find('select').picker({optionRender: markReleasedBuilds, dropWidth: 'auto'})});
  458. }
  459. }
  460. /**
  461. * Load execution related bugs and tasks.
  462. *
  463. * @param int $executionID
  464. * @access public
  465. * @return void
  466. */
  467. function loadExecutionRelated(executionID)
  468. {
  469. executionID = parseInt(executionID);
  470. currentProjectID = $('#project').val() == 'undefined' ? 0 : $('#project').val();
  471. if(executionID)
  472. {
  473. if(currentProjectID == 0) loadProjectByExecutionID(executionID);
  474. loadExecutionTasks(executionID);
  475. loadExecutionStories(executionID);
  476. loadExecutionBuilds(executionID);
  477. loadAssignedTo(executionID, $('#assignedTo').val());
  478. loadTestTasks($('#product').val(), executionID);
  479. }
  480. else
  481. {
  482. var currentProductID = $('#product').val();
  483. $('#taskIdBox').innerHTML = '<select id="task"></select>'; // Reset the task.
  484. loadProductStories(currentProductID);
  485. loadTestTasks(currentProductID);
  486. if(currentProjectID == 0)
  487. {
  488. loadProductMembers(currentProductID);
  489. }
  490. else
  491. {
  492. loadProjectTeamMembers(currentProjectID);
  493. }
  494. currentProjectID != 0 ? loadProjectBuilds(currentProjectID) : loadProductBuilds(currentProductID);
  495. }
  496. }
  497. /**
  498. * Load a project by execution id.
  499. *
  500. * @param executionID $executionID
  501. * @access public
  502. * @return void
  503. */
  504. function loadProjectByExecutionID(executionID)
  505. {
  506. link = createLink('project', 'ajaxGetPairsByExecution', 'executionID=' + executionID, 'json');
  507. required = $('#project_chosen').hasClass('required');
  508. productID = $('#product').val();
  509. $.post(link, function(data)
  510. {
  511. var originProject = $('#project').html();
  512. if($('#project').find('option[value="' + data.id + '"]').length > 0)
  513. {
  514. $('#project').find('option[value="' + data.id + '"]').attr('selected', 'selected');
  515. originProject = $('#project').html();
  516. $('#project').replaceWith('<select id="project" name="project" class="form-control" onchange="loadProductExecutions(' + productID + ', this.value)">' + originProject + '</select>');
  517. }
  518. else
  519. {
  520. var newProject = '<option value="' + data.id + '" data-keys="' + data.namePinyin + '" selected="selected">' + data.name + '</option>';
  521. $('#project').replaceWith('<select id="project" name="project" class="form-control" onchange="loadProductExecutions(' + productID + ', this.value)">' + originProject + newProject+ '</select>');
  522. }
  523. $('#project_chosen').remove();
  524. $('#project').next('.picker').remove();
  525. $('#project').chosen();
  526. if(required) $('#project_chosen').addClass('required');
  527. }, 'json')
  528. }
  529. /**
  530. * Load execution tasks.
  531. *
  532. * @param executionID $executionID
  533. * @access public
  534. * @return void
  535. */
  536. function loadExecutionTasks(executionID)
  537. {
  538. link = createLink('task', 'ajaxGetExecutionTasks', 'executionID=' + executionID + '&taskID=' + oldTaskID);
  539. $.post(link, function(data)
  540. {
  541. if(!data) data = '<select id="task" name="task" class="form-control"></select>';
  542. $('#task').replaceWith(data);
  543. $('#task_chosen').remove();
  544. $('#task').next('.picker').remove();
  545. $("#task").chosen();
  546. })
  547. }
  548. /**
  549. * Load execution stories.
  550. *
  551. * @param int executionID
  552. * @param int num
  553. * @access public
  554. * @return void
  555. */
  556. function loadExecutionStories(executionID, num)
  557. {
  558. if(typeof(num) == 'undefined') num = '';
  559. var productID = $('#product' + num).val();
  560. var branch = $('#branch' + num).val();
  561. if(typeof(branch) == 'undefined') branch = 0;
  562. if(typeof(oldStoryID) == 'undefined') oldStoryID = 0;
  563. var link = createLink('story', 'ajaxGetExecutionStories', 'executionID=' + executionID + '&productID=' + productID + '&branch=' + branch + '&moduleID=0&storyID=' + oldStoryID + '&number=' + num + '&type=full&status=all&from=bug');
  564. $('#storyIdBox' + num).load(link, function(){$('#story' + num).chosen();});
  565. }
  566. /**
  567. * Load builds of a project.
  568. *
  569. * @param int projectID
  570. * @access public
  571. * @return void
  572. */
  573. function loadProjectBuilds(projectID)
  574. {
  575. var branch = $('#branch').val();
  576. if(typeof(branch) == 'undefined') branch = 0;
  577. var productID = $('#product').val();
  578. var oldOpenedBuild = $('#openedBuild').val() ? $('#openedBuild').val() : 0;
  579. $.get(createLink('bug', 'ajaxGetReleasedBuilds', 'productID=' + productID), function(data){releasedBuilds = data;}, 'json');
  580. if($('#executionIdBox #execution').val() != 0)
  581. {
  582. $('#executionIdBox #execution').change();
  583. return;
  584. }
  585. if(page == 'create')
  586. {
  587. var link = createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + '&varName=openedBuild&build=&branch=' + branch);
  588. $.get(link, function(data)
  589. {
  590. if(!data) data = '<select id="openedBuild" name="openedBuild" class="form-control picker-select" multiple=multiple></select>';
  591. $('#openedBuild').replaceWith(data);
  592. $('#openedBuild').val(oldOpenedBuild);
  593. $('#pickerDropMenu-pk_openedBuild').remove();
  594. $('#openedBuild').next('.picker').remove();
  595. notice();
  596. $("#openedBuild").picker({optionRender: markReleasedBuilds});
  597. })
  598. }
  599. else
  600. {
  601. var link = createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  602. $('#openedBuildBox').load(link, function(){$(this).find('select').val(oldOpenedBuild).picker({optionRender: markReleasedBuilds})});
  603. var oldResolvedBuild = $('#resolvedBuild').val() ? $('#resolvedBuild').val() : 0;
  604. var link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  605. $('#resolvedBuildBox').load(link, function(){$(this).find('select').val(oldResolvedBuild).picker({optionRender: markReleasedBuilds, dropWidth: 'auto'})});
  606. }
  607. }
  608. /**
  609. * Load builds of a execution.
  610. *
  611. * @param int executionID
  612. * @param int num
  613. * @access public
  614. * @return void
  615. */
  616. function loadExecutionBuilds(executionID, num)
  617. {
  618. if(typeof(num) == 'undefined') num = '';
  619. var branch = $('#branch' + num).val();
  620. var oldOpenedBuild = $('#openedBuild' + num).val() ? $('#openedBuild' + num).val() : 0;
  621. var productID = $('#product' + num).val();
  622. if(typeof(branch) == 'undefined') var branch = 0;
  623. if(typeof(productID) == 'undefined') var productID = 0;
  624. $.get(createLink('bug', 'ajaxGetReleasedBuilds', 'productID=' + productID), function(data){releasedBuilds = data;}, 'json');
  625. if(page == 'create')
  626. {
  627. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + "&branch=" + branch + "&index=0&needCreate=true");
  628. $.get(link, function(data)
  629. {
  630. if(!data) data = '<select id="openedBuild" name="openedBuild" class="form-control picker-select" multiple=multiple></select>';
  631. $('#openedBuild').replaceWith(data);
  632. $('#openedBuild').val(oldOpenedBuild);
  633. $('#pickerDropMenu-pk_openedBuild').remove();
  634. $('#openedBuild').next('.picker').remove();
  635. notice();
  636. $("#openedBuild").picker({optionRender: markReleasedBuilds});
  637. })
  638. }
  639. else
  640. {
  641. link = createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&index=0&needCreate=false&type=normal&number=' + num);
  642. $('#openedBuildBox' + num).load(link, function(){$(this).find('select').val(oldOpenedBuild).picker({optionRender: markReleasedBuilds})});
  643. oldResolvedBuild = $('#resolvedBuild').val() ? $('#resolvedBuild').val() : 0;
  644. link = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  645. $('#resolvedBuildBox').load(link, function(){$(this).find('select').val(oldResolvedBuild).picker({optionRender: markReleasedBuilds, dropWidth: 'auto'})});
  646. }
  647. }
  648. /**
  649. * Load product members.
  650. *
  651. * @param productID
  652. * @access public
  653. * @return void
  654. */
  655. function loadProductMembers(productID)
  656. {
  657. var branchID = $('#branch').val() == undefined ? '' : $('#branch').val();
  658. var link = createLink('bug', 'ajaxGetProductMembers', 'productID=' + productID + '&selectedUser=' + $('#assignedTo').val() + '&branchID=' + branchID);
  659. $.get(link, function(data)
  660. {
  661. if(!data) data = '<select id="assignedTo" name="assignedTo" class="form-control"></select>';
  662. $('#assignedTo').replaceWith(data);
  663. $('#assignedTo_chosen').remove();
  664. $("#assignedTo").chosen();
  665. });
  666. }
  667. /**
  668. * Load project members.
  669. *
  670. * @param projectID $projectID
  671. * @access public
  672. * @return void
  673. */
  674. function loadProjectTeamMembers(projectID)
  675. {
  676. link = createLink('bug', 'ajaxGetProjectTeamMembers', 'projectID=' + projectID + '&selectedUser=' + $('#assignedTo').val());
  677. $.get(link, function(data)
  678. {
  679. if(!data) data = '<select id="assignedTo" name="assignedTo" class="form-control"></select>';
  680. $('#assignedTo').replaceWith(data);
  681. $('#assignedTo_chosen').remove();
  682. $("#assignedTo").chosen();
  683. });
  684. }
  685. /**
  686. * Set story field.
  687. *
  688. * @param moduleID $moduleID
  689. * @param productID $productID
  690. * @param storyID $storyID
  691. * @access public
  692. * @return void
  693. */
  694. function setStories(moduleID, productID, storyID)
  695. {
  696. var branch = $('#branch').val();
  697. if(typeof(branch) == 'undefined') branch = 0;
  698. var executionID = $('#execution').val();
  699. if(typeof(executionID) == 'undefined') executionID = 0;
  700. link = createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleID=' + moduleID + '&storyID=' + storyID + '&onlyOption=false&status=&limit=0&type=full&hasParent=0&executionID=' + executionID);
  701. $.get(link, function(stories)
  702. {
  703. if(!stories) stories = '<select id="story" name="story" class="form-control"></select>';
  704. $('#story').replaceWith(stories);
  705. $('#story_chosen').remove();
  706. $('#story').next('.picker').remove();
  707. $("#story").chosen();
  708. });
  709. }
  710. /**
  711. * Load product branches.
  712. *
  713. * @param int $productID
  714. * @access public
  715. * @return void
  716. */
  717. function loadProductBranches(productID, param)
  718. {
  719. $('#branch').remove();
  720. $('#branch_chosen').remove();
  721. $('#branch').next('.picker').remove();
  722. var branchStatus = page == 'create' ? 'active' : 'all';
  723. var oldBranch = page == 'edit' ? bugBranch : 0;
  724. var param = "productID=" + productID + "&oldBranch=" + oldBranch + "&param=" + branchStatus;
  725. if(typeof(tab) != 'undefined' && (tab == 'execution' || tab == 'project')) param += "&projectID=" + objectID;
  726. $.get(createLink('branch', 'ajaxGetBranches', param), function(data)
  727. {
  728. if(data)
  729. {
  730. $('#product').closest('.input-group').append(data);
  731. $('#branch').css('width', page == 'create' ? '120px' : '65px');
  732. $('#branch').chosen();
  733. }
  734. loadProductModules(productID);
  735. loadProductProjects(productID);
  736. loadProductplans(productID);
  737. loadProductStories(productID);
  738. loadProductMembers(productID);
  739. })
  740. }
  741. /**
  742. * Load team members of the execution as assignedTo list.
  743. *
  744. * @param int $executionID
  745. * @access public
  746. * @return void
  747. */
  748. function loadAssignedTo(executionID, selectedUser)
  749. {
  750. selectedUser = (typeof(selectedUser) == 'undefined') ? '' : $('#assignedTo').val();
  751. link = createLink('bug', 'ajaxLoadAssignedTo', 'executionID=' + executionID + '&selectedUser=' + selectedUser);
  752. $.get(link, function(data)
  753. {
  754. $('#assignedTo_chosen').remove();
  755. $('#assignedTo').next('.picker').remove();
  756. $('#assignedTo').replaceWith(data);
  757. $('#assignedTo').chosen();
  758. });
  759. }
  760. var oldTestTaskTitle = $("#testtask").find("option:selected").text();
  761. var oldTestTask = $("#testtask").find("option:selected").val();
  762. /**
  763. * Load test tasks.
  764. *
  765. * @param int $productID
  766. * @param int $executionID
  767. * @access public
  768. * @return void
  769. */
  770. function loadTestTasks(productID, executionID)
  771. {
  772. if(!$('#testtaskBox').length) return;
  773. if(typeof(executionID) == 'undefined') executionID = 0;
  774. link = createLink('testtask', 'ajaxGetTestTasks', 'productID=' + productID + '&executionID=' + executionID);
  775. $.get(link, function(data)
  776. {
  777. var defaultOption = '<option title="' + oldTestTaskTitle + '" value="' + oldTestTask + '" selected="selected">' + oldTestTaskTitle + '</option>';
  778. $('#testtaskBox').html(data);
  779. $('#testtask').append(defaultOption);
  780. $('#testtask').chosen();
  781. });
  782. }
  783. /**
  784. * notice for create build.
  785. *
  786. * @access public
  787. * @return void
  788. */
  789. function notice()
  790. {
  791. if(page == 'edit') return;
  792. $('#buildBoxActions').empty().hide();
  793. var itemCount = $('#openedBuild').find('option').length;
  794. if($('#openedBuild').attr('data-items') != undefined) var itemCount = $('#openedBuild').attr('data-items');
  795. if(itemCount <= 1)
  796. {
  797. var html = '';
  798. if($('#execution').length == 0 || $('#execution').val() == 0)
  799. {
  800. var branch = $('#branch').val();
  801. var projectID = $('#project').val();
  802. if(typeof(branch) == 'undefined') branch = 0;
  803. if(typeof(projectID) == 'undefined') projectID = 0;
  804. var link = createLink('release', 'create', 'productID=' + $('#product').val() + '&branch=' + branch);
  805. if(projectID > 0) link = createLink('projectrelease', 'create', 'projectID=' + projectID);
  806. if(config.onlybody != 'yes') link += link.indexOf('?') >= 0 ? '&onlybody=yes' : '?onlybody=yes';
  807. html += '<a href="' + link + '" data-toggle="modal" data-type="iframe" style="padding-right:5px">' + createRelease + '</a> ';
  808. html += '<a href="javascript:loadProductBuilds(' + $('#product').val() + ')">' + refresh + '</a>';
  809. }
  810. else
  811. {
  812. executionID = $('#execution').val();
  813. productID = $('#product').val();
  814. projectID = $('#project').val();
  815. link = createLink('build', 'create','executionID=' + executionID + '&productID=' + productID + '&projectID=' + projectID);
  816. link += link.indexOf('?') >= 0 ? '&onlybody=yes' : '?onlybody=yes';
  817. html += '<a href="' + link + '" data-toggle="modal" data-type="iframe" style="padding-right:5px">' + createBuild + '</a> ';
  818. html += '<a href="javascript:loadExecutionBuilds(' + executionID + ')">' + refresh + '</a>';
  819. }
  820. var $bba = $('#buildBoxActions');
  821. if($bba.length)
  822. {
  823. $bba.html(html);
  824. $bba.show();
  825. }
  826. else
  827. {
  828. if($('#buildBox').closest('tr').find('td').size() > 1)
  829. {
  830. $('#buildBox').closest('td').next().attr('id', 'buildBoxActions');
  831. $('#buildBox').closest('td').next().html(html);
  832. }
  833. else
  834. {
  835. html = "<td id='buildBoxActions'>" + html + '</td>';
  836. $('#buildBox').closest('td').after(html);
  837. }
  838. }
  839. }
  840. }
  841. /**
  842. * Set branch related.
  843. *
  844. * @param int $branchID
  845. * @param int $productID
  846. * @param int $num
  847. * @access public
  848. * @return void
  849. */
  850. function setBranchRelated(branchID, productID, num)
  851. {
  852. var currentModuleID = config.currentMethod == 'batchedit' ? $('#modules' + num).val() : 0;
  853. var moduleLink = createLink('tree', 'ajaxGetModules', 'productID=' + productID + '&viewType=bug&branch=' + branchID + '&num=' + num + '&currentModuleID=' + currentModuleID);
  854. $.get(moduleLink, function(modules)
  855. {
  856. if(!modules) modules = '<select id="modules' + num + '" name="modules[' + num + ']" class="form-control"></select>';
  857. $('#modules' + num).replaceWith(modules);
  858. $("#modules" + num + "_chosen").remove();
  859. $("#modules" + num).next('.picker').remove();
  860. $("#modules" + num).chosen();
  861. });
  862. var projectLink = createLink('product', 'ajaxGetProjectsByBranch', 'productID=' + productID + '&branch=' + branchID + '&num=' + num);
  863. $.get(projectLink, function(projects)
  864. {
  865. if(!projects) projects = '<select id="projects' + num + '" name="projects[' + num + ']" class="form-control"></select>';
  866. $('#projects' + num).replaceWith(projects);
  867. $("#projects" + num + "_chosen").remove();
  868. $("#projects" + num).next('.picker').remove();
  869. $("#projects" + num).chosen();
  870. });
  871. var executionLink = createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&projectID=0&branch=' + branchID + '&num=' + num);
  872. $.get(executionLink, function(executions)
  873. {
  874. if(!executions) executions = '<select id="executions' + num + '" name="executions[' + num + ']" class="form-control"></select>';
  875. $('#executions' + num).replaceWith(executions);
  876. $("#executions" + num + "_chosen").remove();
  877. $("#executions" + num).next('.picker').remove();
  878. $("#executions" + num).chosen();
  879. });
  880. var buildLink = createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + "&varName=openedBuilds&build=&branch=" + branchID);
  881. /* If the branch of the current row is inconsistent with the one below, clear the module and execution of the nex row. */
  882. if(config.currentMethod == 'batchcreate')
  883. {
  884. var nextBranchID = $('#branch' + (num + 1)).val();
  885. if(nextBranchID != branchID)
  886. {
  887. $('#modules' + (num + 1)).find("option[value='ditto']").remove();
  888. $('#modules' + (num + 1)).trigger("chosen:updated");
  889. $('#executions' + (num + 1)).find("option[value='ditto']").remove();
  890. $('#executions' + (num + 1)).trigger("chosen:updated");
  891. }
  892. setOpenedBuilds(buildLink, num);
  893. }
  894. if(config.currentMethod == 'batchedit')
  895. {
  896. planID = $('#plans' + num).val();
  897. planLink = createLink('product', 'ajaxGetPlans', 'productID=' + productID + '&branch=' + branchID + '&planID=' + planID + '&fieldID=' + num + '&needCreate=false&expired=&param=skipParent');
  898. $.ajaxSettings.async = false;
  899. $('#plans' + num).parent('td').load(planLink, function()
  900. {
  901. $('#plans' + num).chosen();
  902. var firstBugID = $('.table-form tbody').first('tr').find('input[id^=bugIDList]').val();
  903. if(num == firstBugID)
  904. {
  905. $('#plans' + firstBugID).find('option').each(function()
  906. {
  907. if($(this).val() == 'ditto') $(this).remove();
  908. $('#plans' + firstBugID).trigger('chosen:updated');
  909. });
  910. }
  911. });
  912. $.ajaxSettings.async = true;
  913. }
  914. }
  915. /**
  916. * Set title field width.
  917. *
  918. * @access public
  919. * @return void
  920. */
  921. function setTitleWidth()
  922. {
  923. if(window.config.currentMethod != 'browse') return false;
  924. if($('#bugList thead th.c-title').width() < 150) $('#bugList thead th.c-title').width(150);
  925. setTimeout(function()
  926. {
  927. if($('#bugList thead th.c-title').width() < 150) $('#bugList thead th.c-title').width(150);
  928. }, 400)
  929. }