batchedit.ui.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. window.renderRowData = function($row, index, row)
  2. {
  3. /* If there are multiple branch products, show the branches. */
  4. if(isBranchProduct == 1)
  5. {
  6. $row.find('[data-name="branch"]').find('.picker-box').on('inited', function(e, info)
  7. {
  8. let $branch = info[0];
  9. /* The product of current bug is multiple branch product, show branches in the select box. */
  10. if(products[row.product] != undefined && products[row.product].type != 'normal' && branchTagOption[row.product] != undefined)
  11. {
  12. let branches = branchTagOption[row.product];
  13. $branch.render({items: branches, disabled: false});
  14. }
  15. /* The product of current bug isn't multiple branch product, disable the input box. */
  16. else
  17. {
  18. $branch.render({disabled: true});
  19. }
  20. $branch.$.changeState({value: ''});
  21. });
  22. }
  23. /* Show the modules of current bug's product. */
  24. if(modules[row.product] != undefined && modules[row.product][row.branch] != undefined)
  25. {
  26. $row.find('[data-name="module"]').find('.picker-box').on('inited', function(e, info)
  27. {
  28. let bugModules = modules[row.product][row.branch];
  29. let $module = info[0];
  30. $module.render({items: bugModules});
  31. });
  32. }
  33. /* Show the plans of current bug's product. */
  34. if(row.plans != undefined)
  35. {
  36. $row.find('[data-name="plan"]').find('.picker-box').on('inited', function(e, info)
  37. {
  38. let $plan = info[0];
  39. $plan.render({items: row.plans});
  40. });
  41. }
  42. /* Show the bugs of current bug's product. */
  43. $row.find('[data-name="resolutionBox"]').find('.input-group').find('.duplicate-select').on('inited', function(e, info)
  44. {
  45. let $duplicateBug = info[0];
  46. $.getJSON($.createLink('bug', 'ajaxGetDuplicateBugs', `bugID=${row.id}&duplicateBug=${row.duplicateBug}`), function(duplicateBugs)
  47. {
  48. $duplicateBug.render({items: duplicateBugs});
  49. $duplicateBug.$.setValue(row.duplicateBug);
  50. });
  51. });
  52. $row.find('[data-name="resolutionBox"]').find('.input-group').find('.duplicate-select').toggleClass('hidden', row.resolution != 'duplicate');
  53. /* Change assigner. */
  54. let $assignedTo = $row.find('.form-batch-input[data-name="assignedTo"]');
  55. if(row.status == 'closed')
  56. {
  57. $row.find('[data-name="assignedTo"]').find('.picker-box').on('inited', function(e, info)
  58. {
  59. let $plan = info[0];
  60. $plan.render({disabled: true});
  61. });
  62. }
  63. else if(tab == 'project' || tab == 'execution')
  64. {
  65. let assignedToList;
  66. if(row.execution != 0)
  67. {
  68. /* If bug has execution, assigner of the bug is all members of the execution. */
  69. assignedToList = executionMembers[row.execution];
  70. }
  71. else if(row.project != 0)
  72. {
  73. /* If bug has project, assigner of the bug is all members of the project. */
  74. assignedToList = projectMembers[row.project];
  75. }
  76. else if(productMembers.length > 0)
  77. {
  78. /* If bug has product and the product has members, assigner of the bug is all members of the product. */
  79. assignedToList = productMembers[row.product];
  80. }
  81. /* If the assignedToList is defined, replace assigner with assignedToList. */
  82. if(assignedToList != undefined)
  83. {
  84. $assignedTo.empty();
  85. $assignedTo.append('<option value=""></option>');
  86. $.each(assignedToList, function(assignedToID, assignedToName)
  87. {
  88. if(assignedToID != row.id) $assignedTo.append('<option value="' + assignedToID + '">' + assignedToName + '</option>');
  89. });
  90. }
  91. }
  92. $assignedTo.find('option[value="closed"]').remove();
  93. $row.find('[data-name="product"]').val(row.product); // Set product value.
  94. /* Set project items. */
  95. $row.find('[data-name="project"]').find('.picker-box').on('inited', function(e, info)
  96. {
  97. let projectItems = JSON.parse(JSON.stringify(productProjects[row.product]));
  98. const $project = info[0];
  99. const isRequired = typeof(noProductProjects[row.project]) != 'undefined';
  100. if(typeof(deletedProjects[row.project]) != 'undefined') projectItems.push(deletedProjects[row.project]);
  101. $project.render({items: projectItems, required: isRequired});
  102. });
  103. /* Set execution items. */
  104. $row.find('[data-name="execution"]').find('.picker-box').on('inited', function(e, info)
  105. {
  106. const isDisabled = typeof(noSprintProjects[row.project]) != 'undefined';
  107. let executionItems = isDisabled || typeof(productExecutions[row.product]) == 'undefined' || typeof(productExecutions[row.product][row.project]) == 'undefined' ? [] : JSON.parse(JSON.stringify(productExecutions[row.product][row.project]));
  108. const $execution = info[0];
  109. if(typeof(deletedExecutions[row.execution]) != 'undefined') executionItems.push(deletedExecutions[row.execution]);
  110. $execution.render({items: executionItems, disabled: isDisabled});
  111. });
  112. /* Set openedBuild items. */
  113. $row.find('[data-name="openedBuild"]').find('.picker-box').on('inited', function(e, info)
  114. {
  115. let openedBuildItems = [];
  116. if(row.execution > 0)
  117. {
  118. openedBuildItems = executionOpenedBuilds[row.execution];
  119. }
  120. else if(row.project > 0)
  121. {
  122. openedBuildItems = projectOpenedBuilds[row.project];
  123. }
  124. else
  125. {
  126. openedBuildItems = productOpenedBuilds[row.product];
  127. }
  128. const $openedBuild = info[0];
  129. $openedBuild.render({items: openedBuildItems, menu: {checkbox: true}});
  130. });
  131. }
  132. function setDuplicate(event)
  133. {
  134. const $target = $(event.target);
  135. const $currentRow = $target.closest('tr');
  136. const resolution = $target.val();
  137. $currentRow.find('[data-name="duplicateBug"]').toggleClass('hidden', resolution != 'duplicate');
  138. }
  139. function projectChange(event)
  140. {
  141. const $row = $(event.target).closest('tr');
  142. const projectID = $(event.target).val();
  143. $row.find('input[name^="execution"]').zui('picker').render({disabled: typeof(noSprintProjects[projectID]) != 'undefined'});
  144. if(typeof(noProductProjects[projectID]) != 'undefined')
  145. {
  146. const productIDLink = $.createLink('bug', 'ajaxGetProductIDByProject', 'projectID=' + projectID);
  147. $.get(productIDLink, function(id)
  148. {
  149. $row.find('[name^=product]').val(id);
  150. loadExecutions($row, id, projectID);
  151. loadProductModules($row, id)
  152. loadProductPlans($row, id);
  153. loadProductBugs($row, id);
  154. });
  155. }
  156. else
  157. {
  158. const productID = $row.find('[name^=product]').val();
  159. loadExecutions($row, productID, projectID);
  160. }
  161. }
  162. function loadExecutions($row, productID, projectID)
  163. {
  164. let branch = $row.find('[name^="branch"]').val();
  165. if(typeof(branch) == 'undefined') branch = 0;
  166. const link = $.createLink('product', 'ajaxGetExecutions', 'productID=' + productID + '&projectID=' + projectID + '&branch=' + branch + '&pageType=&executionID=&from=&mode=stagefilter');
  167. const isMultipleProject = typeof(projectExecutions[projectID]) != 'undefined';
  168. const executionID = isMultipleProject ? projectExecutions[projectID] : $row.find('[name^=execution]').val();
  169. $.getJSON(link, function(data)
  170. {
  171. let $executionPicker = $row.find('[name^=execution]').zui('picker');
  172. $executionPicker.render({items: data});
  173. $executionPicker.$.setValue(isMultipleProject ? '' : executionID);
  174. });
  175. const isLoadBuild = (!isMultipleProject && !executionID) || (isMultipleProject);
  176. if(isLoadBuild) projectID != 0 ? loadProjectBuilds($row, projectID) : loadProductBuilds($row, productID);
  177. }
  178. function loadProjectBuilds($row, projectID)
  179. {
  180. let branch = $row.find('[name^=branch]').val();
  181. if(typeof(branch) == 'undefined') branch = 0;
  182. const productID = $row.find('[name^=product]').val();
  183. const oldOpenedBuild = $row.find('[name^=openedBuild]').val() ? $row.find('[name^=openedBuild]').val().toString() : 0;
  184. const openedLink = $.createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  185. $.getJSON(openedLink, function(data)
  186. {
  187. let $buildPicker = $row.find('[name^=openedBuild]').zui('picker');
  188. $buildPicker.render({items: data});
  189. $buildPicker.$.setValue(oldOpenedBuild);
  190. })
  191. }
  192. function loadProductBuilds($row, productID)
  193. {
  194. let branch = $row.find('[name^=branch]').val();
  195. if(typeof(branch) == 'undefined') branch = 0;
  196. const oldOpenedBuild = $row.find('[name^=openedBuild]').val() ? $row.find('[name^=openedBuild]').val().toString() : 0;
  197. const openedLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch);
  198. $.getJSON(openedLink, function(data)
  199. {
  200. let $buildPicker = $row.find('[name^=openedBuild]').zui('picker');
  201. $buildPicker.render({items: data});
  202. $buildPicker.$.setValue(oldOpenedBuild);
  203. });
  204. }
  205. function loadProductModules($row, productID)
  206. {
  207. let branch = $('[name^=branch]').val();
  208. if(typeof(branch) == 'undefined') branch = 0;
  209. const moduleID = $row.find('[name^=module]').val();
  210. const link = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=bug&branch=' + branch + '&rootModuleID=0&returnType=items&fieldID=&extra=nodeleted&currentModuleID=' + moduleID);
  211. $.getJSON(link, function(data)
  212. {
  213. const $modulePicker = $row.find('[name^=module]').zui('picker');
  214. $modulePicker.render({items: data});
  215. $modulePicker.$.setValue(moduleID);
  216. });
  217. }
  218. function loadProductPlans($row, productID)
  219. {
  220. let branch = $row.find('[name^=branch]').val();
  221. if(typeof(branch) == 'undefined') branch = 0;
  222. const link = $.createLink('productplan', 'ajaxGetProductplans', 'productID=' + productID + '&branch=' + branch);
  223. $.getJSON(link, function(data)
  224. {
  225. const planID = $row.find('[name^=plan]').val();
  226. const $planPicker = $row.find('[name^=plan]').zui('picker');
  227. $planPicker.render({items: data});
  228. $planPicker.$.setValue(planID);
  229. });
  230. }
  231. function loadProductBugs($row, productID)
  232. {
  233. const bugID = $row.find('[name^=id]').val();
  234. const link = $.createLink('bug', 'ajaxGetProductBugs', 'productID=' + productID + '&bugID=' + bugID);
  235. $.getJSON(link, function(data)
  236. {
  237. const duplicateBugID = $row.find('[name^=duplicateBug]').val();
  238. const $bugPicker = $row.find('[name^=duplicateBug]').zui('picker');
  239. $bugPicker.render({items: data});
  240. $bugPicker.$.setValue(duplicateBugID);
  241. });
  242. }
  243. function branchChange(event)
  244. {
  245. const $row = $(event.target).closest('tr');
  246. const productID = $row.find('[name^=product]').val();
  247. const projectID = $row.find('[name^=project]').val();
  248. loadProductModules($row, productID);
  249. loadProductBuilds($row, productID);
  250. loadProductPlans($row, productID);
  251. projectID != 0 ? loadProjectBuilds($row, projectID) : loadProductBuilds($row, productID);
  252. }
  253. function executionChange(event)
  254. {
  255. const $row = $(event.target).closest('tr');
  256. const projectID = $row.find('[name^=project]').val();
  257. const executionID = $row.find('[name^=execution]').val();
  258. if(executionID != 0)
  259. {
  260. loadProjectByExecutionID($row, executionID);
  261. loadExecutionBuilds($row, executionID);
  262. }
  263. else if(projectID != 0)
  264. {
  265. loadProjectBuilds($row, projectID);
  266. }
  267. else
  268. {
  269. const productID = $row.find('[name^=product]').val();
  270. loadProductBuilds($row, productID);
  271. }
  272. }
  273. function loadProjectByExecutionID($row, executionID)
  274. {
  275. const link = $.createLink('project', 'ajaxGetPairsByExecution', 'executionID=' + executionID, 'json');
  276. $.post(link, function(data)
  277. {
  278. $projectPicker = $row.find('[name^=project]').zui('picker');
  279. $projectPicker.$.setValue(data.id.toString());
  280. }, 'json')
  281. }
  282. function loadExecutionBuilds($row, executionID)
  283. {
  284. const branch = $row.find('[name^=branch]').val();
  285. const productID = $row.find('[name^=product]').val();
  286. const oldOpenedBuild = $row.find('[name^=openedBuild]').val() ? $row.find('[name^=openedBuild]').val().toString() : 0;
  287. if(typeof(branch) == 'undefined') branch = 'all';
  288. const openedLink = $.createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + '&varName=openedBuild&build=' + oldOpenedBuild + '&branch=' + branch + '&needCreate=false&type=normal');
  289. $.getJSON(openedLink, function(data)
  290. {
  291. let $buildPicker = $row.find('[name^=openedBuild]').zui('picker');
  292. $buildPicker.render({items: data});
  293. $buildPicker.$.setValue(oldOpenedBuild);
  294. });
  295. }