common.ui.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. $(function()
  2. {
  3. $('#subNavbar a[data-toggle=dropdown]').parent().addClass('dropdown dropdown-hover');
  4. });
  5. function changeProduct(event)
  6. {
  7. const productID = $(event.target).val();
  8. if(productID == undefined) return false;
  9. if(typeof(changeProductConfirmed) != 'undefined' && !changeProductConfirmed && productID != bug.productID && (typeof(isShadowProduct) == 'undefined' || !isShadowProduct))
  10. {
  11. zui.Modal.confirm({message: confirmChangeProduct, onResult: function(result)
  12. {
  13. if(result)
  14. {
  15. changeProductConfirmed = true; // Only notice the user one time.
  16. changeProduct(event);
  17. }
  18. else
  19. {
  20. $('[name=product]').zui('picker').$.setValue(bug.product); // Revert old product id if confirm is no.
  21. }
  22. }});
  23. }
  24. else
  25. {
  26. loadProductBranches(productID)
  27. loadProductModules(productID);
  28. loadProductProjects(productID);
  29. loadExecutions(productID);
  30. loadAssignedTo(productID);
  31. loadProductBuilds(productID);
  32. loadProductPlans(productID);
  33. loadProductCases(productID);
  34. loadProductStories(productID, bug.storyID);
  35. loadProductBugs(productID, bug.id);
  36. }
  37. }
  38. function changeBranch(event)
  39. {
  40. const productID = $('[name="product"]').val();
  41. loadProductModules(productID);
  42. loadProductProjects(productID);
  43. loadExecutions(productID);
  44. loadAssignedTo(productID);
  45. loadProductBuilds(productID);
  46. loadProductPlans(productID);
  47. loadProductCases(productID);
  48. loadProductStories(productID, bug.storyID);
  49. }
  50. function changeProject(event)
  51. {
  52. const projectID = $(event.target).val();
  53. const projectInfoLink = $.createLink('bug', 'ajaxGetProjectInfo', 'projectID=' + projectID);
  54. $.getJSON(projectInfoLink, function(project)
  55. {
  56. $('#executionBox').closest('tr').toggleClass('hidden', project.multiple == 0);
  57. });
  58. if(config.currentMethod == 'edit' && isShadowProduct)
  59. {
  60. const productIDLink = $.createLink('bug', 'ajaxGetProductIDByProject', 'projectID=' + projectID);
  61. $.get(productIDLink, function(id)
  62. {
  63. const productID = id;
  64. const $productPicker = $('.detail-side [name=product]').zui('picker');
  65. $productPicker.$.setValue(productID);
  66. loadExecutionLabel(projectID);
  67. loadExecutions(productID, projectID);
  68. loadAssignedTo(productID, projectID);
  69. });
  70. }
  71. else
  72. {
  73. const productID = $('[name="product"]').val();
  74. loadExecutionLabel(projectID);
  75. loadExecutions(productID, projectID);
  76. loadAssignedTo(productID, projectID);
  77. }
  78. }
  79. function changeExecution(event)
  80. {
  81. const productID = $('[name="product"]').val();
  82. const projectID = $('[name="project"]').val() == 'undefined' ? 0 : $('[name="project"]').val();
  83. const executionID = $(event.target).val();
  84. if(executionID != 0)
  85. {
  86. loadProjectByExecutionID(executionID);
  87. loadExecutionStories(executionID);
  88. loadExecutionBuilds(executionID);
  89. loadAssignedToByExecution(executionID);
  90. loadTestTasks(productID, executionID);
  91. }
  92. else
  93. {
  94. loadProductStories(productID, bug.storyID);
  95. loadTestTasks(productID);
  96. if(projectID == 0)
  97. {
  98. loadAssignedToByProduct(productID);
  99. loadProductBuilds(productID);
  100. }
  101. else
  102. {
  103. loadAssignedToByProject(projectID);
  104. loadProjectBuilds(projectID);
  105. }
  106. }
  107. loadExecutionTasks(executionID);
  108. }
  109. function changeModule(event)
  110. {
  111. const moduleID = $(event.target).val();
  112. const productID = $('[name="product"]').val();
  113. const storyID = $('[name="story"]').val();
  114. let executionID = $('[name="execution"]').val();
  115. if(typeof(executionID) == 'undefined') executionID = 0;
  116. loadAssignedToByModule(moduleID, productID);
  117. loadProductStories(productID, storyID, moduleID, executionID);
  118. }
  119. function changeRegion(event)
  120. {
  121. const regionID = $(event.target).val();
  122. const url = $.createLink('kanban', 'ajaxGetLanes', 'regionID=' + regionID + '&type=bug&field=lane');
  123. $.get(url, function(lane)
  124. {
  125. if(!lane) lane = "<select id='lane' name='lane' class='form-control'></select>";
  126. $('#lane').replaceWith(lane);
  127. });
  128. }
  129. function refreshModule(event)
  130. {
  131. const productID = $('[name="product"]').val();
  132. loadProductModules(productID);
  133. }
  134. window.refreshProductBuild = function(event)
  135. {
  136. const productID = $('[name="product"]').val();
  137. loadProductBuilds(productID);
  138. }
  139. window.refreshExecutionBuild = function(event)
  140. {
  141. const executionID = $('[name="execution"]').val();
  142. loadExecutionBuilds(executionID);
  143. }
  144. function loadProductBranches(productID)
  145. {
  146. const branchStatus = methodName == 'create' ? 'active' : 'all';
  147. const oldBranch = methodName == 'edit' ? bug.branch : 0;
  148. let param = "productID=" + productID + "&oldBranch=" + oldBranch + "&param=" + branchStatus;
  149. if(typeof(tab) != 'undefined' && (tab == 'execution' || tab == 'project')) param += "&projectID=" + bug[tab];
  150. $.getJSON($.createLink('branch', 'ajaxGetBranches', param), function(data)
  151. {
  152. if(data.length > 0)
  153. {
  154. if($('#branchPicker').length > 0)
  155. {
  156. const $branchPicker = $('#branchPicker').zui('picker');
  157. $branchPicker.render({items: data, defaultValue: data[0].value});
  158. $branchPicker.$.setValue('0');
  159. }
  160. else
  161. {
  162. $('[name="product"]').closest('.input-group').append($('<div id="branchPicker" class="form-group-wrapper picker-box"></div>').picker({name: 'branch', items: data, defaultValue: data[0].value, required: true}));
  163. }
  164. $('#branchPicker').css('width', methodName == 'create' ? '120px' : '70px');
  165. }
  166. else
  167. {
  168. $('#branchPicker').zui('picker').destroy();
  169. $('#branchPicker').remove();
  170. }
  171. });
  172. }
  173. function loadProductModules(productID)
  174. {
  175. if(methodName == 'edit')
  176. {
  177. const moduleID = $('[name="module"]').val();
  178. }
  179. let branch = $('[name="branch"]').val();
  180. if(typeof(branch) == 'undefined') branch = 0;
  181. if(typeof(moduleID) == 'undefined') moduleID = 0;
  182. const link = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=bug&branch=' + branch + '&rootModuleID=0&returnType=items&fieldID=&extra=nodeleted&currentModuleID=' + moduleID);
  183. $.getJSON(link, function(data)
  184. {
  185. let moduleID = $('[name="module"]').val();
  186. let $modulePicker = $('[name="module"]').zui('picker');
  187. $modulePicker.render({items: data});
  188. if(moduleID != 0) $modulePicker.$.setValue('0');
  189. $('#manageModule').toggleClass('hidden', data.length > 1);
  190. if(data.length <= 1) $('#manageModule').attr('href', $.createLink('tree', 'browse', 'rootID=' + productID + '&currentModuleID=' + moduleID + '&branch=' + branch));
  191. });
  192. }
  193. function loadProductProjects(productID)
  194. {
  195. let branch = $('[name="branch"]').val();
  196. if(typeof(branch) == 'undefined') branch = 0;
  197. const link = $.createLink('bug', 'ajaxGetProjects', 'productID=' + productID + '&branch=' + branch + '&projectID=' + $('[name="project"]').val());
  198. $.getJSON(link, function(data)
  199. {
  200. let project = $('[name="project"]').val();
  201. let $projectPicker = $('[name="project"]').zui('picker');
  202. $projectPicker.render({items: data});
  203. $projectPicker.$.setValue(project != '0' ? project : '');
  204. });
  205. }
  206. function loadExecutions(productID, projectID = 0)
  207. {
  208. let branch = $('[name="branch"]').val();
  209. if(typeof(branch) == 'undefined') branch = 0;
  210. const isMultipleProject = projectID != 0 && projectExecutionPairs[projectID] !== undefined;
  211. $('#executionBox').toggle(!isMultipleProject);
  212. if(projectID == 0) projectID = $('[name="project"]').val();
  213. const link = $.createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&projectID=' + projectID + '&branch=' + branch + '&pageType=&executionID=&from=&mode=stagefilter');
  214. $.getJSON(link, function(data)
  215. {
  216. let executionID = isMultipleProject ? projectExecutionPairs[projectID] : $('[name=execution]').val();
  217. let $executionPicker = $('[name="execution"]').zui('picker');
  218. $executionPicker.render({items: data});
  219. $executionPicker.$.setValue(executionID != '0' ? executionID : '');
  220. });
  221. if($('[name="execution"]').val() == 0) projectID != 0 ? loadProjectBuilds(projectID) : loadProductBuilds(productID);
  222. }
  223. function loadExecutionLabel(projectID)
  224. {
  225. if(methodName == 'create' && projectID > 0)
  226. {
  227. const link = $.createLink('bug', 'ajaxGetExecutionLang', 'projectID=' + projectID);
  228. $.post(link, function(executionLang)
  229. {
  230. $('#executionBox .form-label').html(executionLang);
  231. })
  232. }
  233. }
  234. function loadAssignedTo(productID, projectID = 0, executionID = 0)
  235. {
  236. if(projectID != 0)
  237. {
  238. loadAssignedToByProject(projectID);
  239. }
  240. else if(executionID != 0)
  241. {
  242. loadAssignedToByExecution(executionID);
  243. }
  244. else
  245. {
  246. loadAssignedToByProduct(productID);
  247. }
  248. }
  249. function loadAssignedToByProduct(productID)
  250. {
  251. let branch = $('[name="branch"]').val();
  252. if(typeof(branch) == 'undefined') branch = 0;
  253. const link = $.createLink('bug', 'ajaxGetProductMembers', 'productID=' + productID + '&selectedUser=' + $('[name="assignedTo"]').val() + '&branchID=' + branch);
  254. $.getJSON(link, function(data)
  255. {
  256. let assignedTo = $('[name="assignedTo"]').val();
  257. let $assignedToPicker = $('[name="assignedTo"]').zui('picker');
  258. $assignedToPicker.render({items: data});
  259. $assignedToPicker.$.setValue(assignedTo);
  260. });
  261. }
  262. function loadAssignedToByProject(projectID)
  263. {
  264. const link = $.createLink('bug', 'ajaxGetProjectTeamMembers', 'projectID=' + projectID);
  265. $.getJSON(link, function(data)
  266. {
  267. let assignedTo = $('[name="assignedTo"]').val();
  268. let $assignedToPicker = $('[name="assignedTo"]').zui('picker');
  269. $assignedToPicker.render({items: data});
  270. $assignedToPicker.$.setValue(assignedTo);
  271. });
  272. }
  273. function loadAssignedToByExecution(executionID)
  274. {
  275. const link = $.createLink('bug', 'ajaxLoadAssignedTo', 'executionID=' + executionID);
  276. $.getJSON(link, function(data)
  277. {
  278. let assignedTo = $('[name="assignedTo"]').val();
  279. let $assignedToPicker = $('[name="assignedTo"]').zui('picker');
  280. $assignedToPicker.render({items: data});
  281. $assignedToPicker.$.setValue(assignedTo);
  282. });
  283. }
  284. function loadAssignedToByModule(moduleID, productID)
  285. {
  286. if(typeof(productID) == 'undefined') productID = $('[name="product"]').val();
  287. if(typeof(moduleID) == 'undefined') moduleID = $('[name="module"]').val();
  288. const link = $.createLink('bug', 'ajaxGetModuleOwner', 'moduleID=' + moduleID + '&productID=' + productID);
  289. $.getJSON(link, function(owner)
  290. {
  291. let account = owner.account;
  292. let realName = owner.realname;
  293. let isExist = false;
  294. let $assignedToPicker = $('[name="assignedTo"]').zui('picker');
  295. let assignedToItems = $assignedToPicker.options.items;
  296. let count = assignedToItems.length;
  297. for(var i = 0; i < count; i++)
  298. {
  299. if(assignedToItems[i].value == account)
  300. {
  301. isExist = true;
  302. break;
  303. }
  304. }
  305. if(!isExist && account)
  306. {
  307. assignedToItems.push({text: realName, value: account, keys: realName, key: account});
  308. $assignedToPicker.render({items: Array.from(assignedToItems)});
  309. }
  310. if(!bug.assignedTo) $assignedToPicker.$.setValue(account);
  311. });
  312. }
  313. function loadProjectBuilds(projectID)
  314. {
  315. let branch = $('[name="branch"]').val();
  316. if(typeof(branch) == 'undefined') branch = 0;
  317. const productID = $('[name="product"]').val();
  318. const oldOpenedBuild = $('[name^="openedBuild"]').val() ? $('[name^="openedBuild"]').val().toString() : 0;
  319. if(methodName == 'create')
  320. {
  321. const link = $.createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + '&varName=openedBuild&build=&branch=' + branch);
  322. $.getJSON(link, function(data)
  323. {
  324. let buildID = $('[name^="openedBuild"]').val();
  325. let $buildPicker = $('[name^="openedBuild"]').zui('picker');
  326. $buildPicker.render({items: data});
  327. $buildPicker.$.setValue(buildID);
  328. loadBuildActions();
  329. })
  330. }
  331. else
  332. {
  333. const openedLink = $.createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  334. $.getJSON(openedLink, function(data)
  335. {
  336. let $buildPicker = $('[name^="openedBuild"]').zui('picker');
  337. $buildPicker.render({items: data});
  338. $buildPicker.$.setValue(oldOpenedBuild);
  339. loadBuildActions();
  340. })
  341. const oldResolvedBuild = $('[name="resolvedBuild"]').val() ? $('[name="resolvedBuild"]').val().toString() : 0;
  342. const resolvedLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  343. $.getJSON(resolvedLink, function(data)
  344. {
  345. let $buildPicker = $('[name="resolvedBuild"]').zui('picker');
  346. $buildPicker.render({items: data});
  347. $buildPicker.$.setValue(oldResolvedBuild);
  348. });
  349. }
  350. }
  351. function loadProductBuilds(productID, type = 'normal', buildBox = 'all')
  352. {
  353. let branch = $('[name="branch"]').val();
  354. if(typeof(branch) == 'undefined') branch = 0;
  355. if(methodName == 'create')
  356. {
  357. if(buildBox == 'all' || buildBox == 'openedBuild')
  358. {
  359. const link = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=&branch=' + (branch == 0 ? 'all' : branch) + '&type=' + type);
  360. $.getJSON(link, function(data)
  361. {
  362. let buildID = $('[name^="openedBuild"]').val();
  363. let $buildPicker = $('[name^="openedBuild"]').zui('picker');
  364. $buildPicker.render({items: data});
  365. $buildPicker.$.setValue(buildID);
  366. loadBuildActions();
  367. });
  368. }
  369. }
  370. else
  371. {
  372. if(buildBox == 'all' || buildBox == 'openedBuild')
  373. {
  374. const openedLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + bug.openedBuild + '&branch=' + (branch == 0 ? 'all' : branch) + '&type=' + type);
  375. $.getJSON(openedLink, function(data)
  376. {
  377. let buildID = $('[name^="openedBuild"]').val().toString();
  378. let $buildPicker = $('[name^="openedBuild"]').zui('picker');
  379. $buildPicker.render({items: data});
  380. $buildPicker.$.setValue(buildID);
  381. });
  382. }
  383. if(buildBox == 'all' || buildBox == 'resolvedBuild')
  384. {
  385. const oldResolvedBuild = $('[name="resolvedBuild"]').val() ? $('[name="resolvedBuild"]').val().toString() : 0;
  386. const resolvedLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch + '&type=' + type);
  387. $.getJSON(resolvedLink, function(data)
  388. {
  389. let $buildPicker = $('[name="resolvedBuild"]').zui('picker');
  390. $buildPicker.render({items: data});
  391. $buildPicker.$.setValue(oldResolvedBuild);
  392. });
  393. }
  394. }
  395. }
  396. function loadExecutionBuilds(executionID, num)
  397. {
  398. if(typeof(num) == 'undefined') num = '';
  399. let branch = num != '' ? $('#branch' + num).val() : $('[name="branch"]').val();
  400. let productID = num != '' ? $('#product' + num).val() : $('[name="product"]').val();
  401. const oldOpenedBuild = $('[name^="openedBuild"]' + num).val() ? $('[name^="openedBuild"]' + num).val().toString() : 0;
  402. if(typeof(branch) == 'undefined') branch = 'all';
  403. if(typeof(productID) == 'undefined') productID = 0;
  404. if(methodName == 'create')
  405. {
  406. const link = $.createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + "&branch=" + branch + "&needCreate=true");
  407. $.getJSON(link, function(data)
  408. {
  409. let $buildPicker = $('[name^="openedBuild"]').zui('picker');
  410. $buildPicker.render({items: data});
  411. $buildPicker.$.setValue(oldOpenedBuild);
  412. loadBuildActions();
  413. });
  414. }
  415. else
  416. {
  417. const openedLink = $.createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&needCreate=false&type=normal&number=' + num);
  418. $.getJSON(openedLink, function(data)
  419. {
  420. let $buildPicker = $('[name^="openedBuild"]').zui('picker');
  421. $buildPicker.render({items: data});
  422. $buildPicker.$.setValue(oldOpenedBuild);
  423. });
  424. const oldResolvedBuild = $('[name="resolvedBuild"]').val() ? $('[name="resolvedBuild"]').val().toString() : 0;
  425. const resolvedLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=resolvedBuild&build=' + oldResolvedBuild + '&branch=' + branch);
  426. $.getJSON(resolvedLink, function(data)
  427. {
  428. let $buildPicker = $('[name^="resolvedBuild"]').zui('picker');
  429. $buildPicker.render({items: data});
  430. $buildPicker.$.setValue(oldResolvedBuild);
  431. });
  432. }
  433. }
  434. function loadProductPlans(productID)
  435. {
  436. if($('[name="plan"]').length == 0) return;
  437. let branch = $('[name="branch"]').val();
  438. if(typeof(branch) == 'undefined') branch = 0;
  439. const link = $.createLink('productplan', 'ajaxGetProductplans', 'productID=' + productID + '&branch=' + branch);
  440. $.getJSON(link, function(data)
  441. {
  442. if(data)
  443. {
  444. let planID = $('[name="plan"]').val();
  445. let $planPicker = $('[name="plan"]').zui('picker');
  446. $planPicker.render({items: data});
  447. $planPicker.$.setValue(planID);
  448. }
  449. });
  450. }
  451. function loadProductStories(productID, storyID, moduleID = 0, executionID = 0)
  452. {
  453. let branch = $('[name="branch"]').val();
  454. if(typeof(branch) == 'undefined') branch = 0;
  455. const link = $.createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleID=' + moduleID + '&storyID=' + storyID + '&onlyOption=false&status=active&limit=0&type=full&hasParent=0&executionID=' + executionID);
  456. $.getJSON(link, function(data)
  457. {
  458. let $storyPicker = $('[name="story"]').zui('picker');
  459. $storyPicker.render({items: data});
  460. $storyPicker.$.setValue(storyID);
  461. });
  462. }
  463. function loadExecutionStories(executionID)
  464. {
  465. const productID = $('[name="product"]').val();
  466. let branch = $('[name="branch"]').val();
  467. if(typeof(branch) == 'undefined') branch = 0;
  468. const link = $.createLink('story', 'ajaxGetExecutionStories', 'executionID=' + executionID + '&productID=' + productID + '&branch=' + branch + '&moduleID=0&storyID=' + bug.storyID + '&number=&type=full&status=all&from=bug');
  469. $.getJSON(link, function(data)
  470. {
  471. let story = $('[name="story"]').val();
  472. let $storyPicker = $('[name="story"]').zui('picker');
  473. $storyPicker.render({items: data});
  474. $storyPicker.$.setValue(story);
  475. });
  476. }
  477. function loadExecutionTasks(executionID)
  478. {
  479. const link = $.createLink('task', 'ajaxGetExecutionTasks', 'executionID=' + executionID);
  480. $.post(link, function(data)
  481. {
  482. let $taskPicker = $('[name="task"]').zui('picker');
  483. if(data)
  484. {
  485. data = JSON.parse(data);
  486. $taskPicker.render({items: data});
  487. }
  488. })
  489. }
  490. function loadProjectByExecutionID(executionID)
  491. {
  492. const link = $.createLink('project', 'ajaxGetPairsByExecution', 'executionID=' + executionID, 'json');
  493. $.post(link, function(data)
  494. {
  495. if($('[name="project"]').val() == data.id.toString()) return;
  496. $projectPicker = $('[name="project"]').zui('picker');
  497. $projectPicker.$.setValue(data.id.toString());
  498. }, 'json')
  499. }
  500. function loadTestTasks(productID, executionID)
  501. {
  502. if(!$('#testtaskBox').length) return;
  503. if(typeof(executionID) == 'undefined') executionID = 0;
  504. const link = $.createLink('testtask', 'ajaxGetTestTasks', 'productID=' + productID + '&executionID=' + executionID + '&testtaskID=' + bug.testtask);
  505. $.getJSON(link, function(result)
  506. {
  507. let testtask = $('[name="testtask"]').val();
  508. let $testtaskPicker = $('[name="testtask"]').zui('picker');
  509. if(result.tasks)
  510. {
  511. $testtaskPicker.render({items: result.tasks});
  512. $testtaskPicker.$.setValue(testtask);
  513. }
  514. });
  515. }
  516. function loadAllBuilds(event)
  517. {
  518. const productID = $('[name="product"]').val();
  519. const $buildElement = $(event.target).closest('.input-group').find('select').length > 0 ? $(event.target).closest('.input-group').find('select') : $(event.target).closest('.input-group').find('input');
  520. const buildBox = $buildElement.attr('name').replace('[]', '');
  521. loadProductBuilds(productID, 'all', buildBox);
  522. }
  523. function loadAllUsers(event)
  524. {
  525. const isClosedBug = bug.status == 'closed';
  526. const params = isClosedBug ? 'params=devfirst' : 'params=devfirst,noclosed';
  527. const link = $.createLink('bug', 'ajaxLoadAllUsers', params);
  528. $.getJSON(link, function(data)
  529. {
  530. $('[name="assignedTo"]').zui('picker').render({items: data});
  531. if(!isClosedBug)
  532. {
  533. const moduleID = $('[name="module"]').val();
  534. const productID = $('[name="product"]').val();
  535. loadAssignedToByModule(moduleID, productID);
  536. }
  537. });
  538. }
  539. function setBranchRelated(event)
  540. {
  541. const $target = $(event.target);
  542. const $currentRow = $target.closest('tr');
  543. const branchID = $target.val();
  544. const productID = $('[name= "product"]').val();
  545. const moduleID = $currentRow.find('.form-batch-input[data-name="module"]').val() || '0';
  546. const moduleLink = $.createLink('tree', 'ajaxGetModules', 'productID=' + productID + '&viewType=bug&branch=' + branchID + '&num=0&currentModuleID=' + moduleID);
  547. $.getJSON(moduleLink, function(data)
  548. {
  549. if(!data || !data.modules) return;
  550. let $row = $currentRow;
  551. while($row.length)
  552. {
  553. const currentModuleID = $row.find('.form-batch-control[data-name="module"] input').val();
  554. const $modulePicker = $row.find('.form-batch-control[data-name="module"] input').zui('picker');
  555. $modulePicker.render({items: data.modules});
  556. $modulePicker.$.setValue(currentModuleID);
  557. $row = $row.next('tr');
  558. if(!$row.find('td[data-name="module"][data-ditto="on"]').length) break;
  559. }
  560. });
  561. var projectLink = $.createLink('product', 'ajaxGetProjectsByBranch', 'productID=' + productID + '&branch=' + branchID);
  562. $.getJSON(projectLink, function(projects)
  563. {
  564. if(!projects) return;
  565. let $row = $currentRow;
  566. while($row.length)
  567. {
  568. const currentProjectID = $row.find('.form-batch-control[data-name="project"] input').val();
  569. const $projectPikcer = $row.find('.form-batch-control[data-name="project"] input').zui('picker');
  570. $projectPikcer.render({items: projects});
  571. $projectPikcer.$.setValue(currentProjectID);
  572. $row = $row.next('tr');
  573. if(!$row.find('td[data-name="project"][data-ditto="on"]').length) break;
  574. }
  575. });
  576. const currentProjectID = $currentRow.find('.form-batch-input[data-name="project"]').val() || '0';
  577. var executionLink = $.createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&projectID=' + currentProjectID + '&branch=' + branchID + '&pageType=batch');
  578. $.getJSON(executionLink, function(executions)
  579. {
  580. if(!executions) return;
  581. let $row = $currentRow;
  582. while($row.length)
  583. {
  584. const currentExecutionID = $row.find('.form-batch-control[data-name="execution"] input').val();
  585. const $executionPicker = $row.find('.form-batch-control[data-name="execution"] input').zui('picker');
  586. $executionPicker.render({items: executions});
  587. $executionPicker.$.setValue(currentExecutionID);
  588. $row = $row.next('tr');
  589. if(!$row.find('td[data-name="execution"][data-ditto="on"]').length) break;
  590. }
  591. });
  592. /* If the branch of the current row is inconsistent with the one below, clear the module and execution of the nex row. */
  593. if(config.currentMethod == 'batchcreate')
  594. {
  595. let $nextRow = $currentRow.next('tr');
  596. let nextBranchID = $nextRow.find('td[data-name="branch"]').val();
  597. if(nextBranchID != branchID)
  598. {
  599. $nextRow.find('.form-batch-input[data-name="branch"]').attr('data-ditto', 'off');
  600. $nextRow.find('.form-batch-input[data-name="execution"]').attr('data-ditto', 'off');
  601. }
  602. var buildLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + "&varName=openedBuilds&build=&branch=" + branchID);
  603. setOpenedBuilds(buildLink, $currentRow);
  604. }
  605. if(config.currentMethod == 'batchedit')
  606. {
  607. var planID = $('#plans_' + num).val();
  608. var planLink = $.createLink('product', 'ajaxGetPlans', 'productID=' + productID + '&branch=' + branchID + '&planID=' + planID + '&fieldID=' + num + '&needCreate=false&expired=&param=skipParent');
  609. $('#plans_' + num).parent('td').load(planLink, function()
  610. {
  611. var firstBugID = $('.table-form tbody').first('tr').find('input[id^=bugIDList]').val();
  612. if(num == firstBugID)
  613. {
  614. $('#plans_' + firstBugID).find('option').each(function()
  615. {
  616. if($(this).val() == 'ditto') $(this).remove();
  617. $('#plans_' + firstBugID).trigger('chosen:updated');
  618. });
  619. }
  620. });
  621. }
  622. }
  623. function loadBuildActions()
  624. {
  625. if(methodName == 'edit') return;
  626. $('#createRelease, #createBuild').hide();
  627. let itemCount = $('[name^=openedBuild]').zui('picker').options.items.length;
  628. if(itemCount <= 1)
  629. {
  630. let html = '';
  631. if($('#execution').length == 0 || $('[name="execution"]').val() == 0)
  632. {
  633. $('#createRelease').show();
  634. }
  635. else
  636. {
  637. $('#createBuild').show();
  638. }
  639. }
  640. }
  641. let checkHasCheckedData = function(item, checkedValue)
  642. {
  643. return item.value == checkedValue;
  644. };
  645. function loadBuilds()
  646. {
  647. const productID = $('[name="product"]').val();
  648. const projectID = $('[name="project"]').val() == 'undefined' ? 0 : $('[name="project"]').val();
  649. const executionID = $('[name="execution"]').val() == 'undefined' ? 0 : $('[name="execution"]').val();
  650. if(executionID)
  651. {
  652. loadExecutionBuilds(executionID);
  653. }
  654. else if(projectID)
  655. {
  656. loadProjectBuilds(projectID);
  657. }
  658. else
  659. {
  660. loadProductBuilds(productID);
  661. }
  662. }
  663. function loadProductCases(productID)
  664. {
  665. const branchID = $('[name=branch]').length > 0 ? $('[name=branch]').val() : 0;
  666. const caseID = $('[name=case]').val();
  667. $.getJSON($.createLink('bug', 'ajaxGetProductCases', `productID=${productID}&branch=${branchID}`),function(cases)
  668. {
  669. const $casePicker = $('[name="case"]').zui('picker');
  670. $casePicker.render({items: cases});
  671. $casePicker.$.setValue(caseID);
  672. });
  673. }
  674. function loadProductBugs(productID, bugID)
  675. {
  676. if($('[name="duplicateBug"]').length == 0) return;
  677. const link = $.createLink('bug', 'ajaxGetDuplicateBugs', `bugID=${bugID}&duplicateBugID=${duplicateBugID}`);
  678. $.getJSON(link, function(data)
  679. {
  680. const $duplicateBugPicker = $('[name="duplicateBug"]').zui('picker');
  681. $duplicateBugPicker.render({items: data});
  682. $duplicateBugPicker.$.setValue(duplicateBugID);
  683. });
  684. }