batchcreate.ui.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. function loadExecutionBuilds(event)
  2. {
  3. const $target = $(event.target);
  4. if($target.closest('.form-batch-ditto').data('ditto') == 'on') return false;
  5. const $currentRow = $target.closest('tr');
  6. const executionID = $target.val();
  7. const projectID = $currentRow.find('.form-batch-control[data-name="project"] .picker').zui('picker').$.value || '0';
  8. const branch = $currentRow.find('.form-batch-control[data-name="branch"] input').val() || '0'; // Branch ID (from same row).
  9. const productID = $('[name="product"]').val();
  10. if(executionID != 0)
  11. {
  12. var link = $.createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + "&varName=openedBuilds&build=&branch=" + branch);
  13. }
  14. else if(projectID != 0)
  15. {
  16. var link = $.createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + "&varName=openedBuilds&build=&branch=" + branch);
  17. }
  18. else
  19. {
  20. var link = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + "&varName=openedBuilds&build=&branch=" + branch);
  21. }
  22. setOpenedBuilds(link, $currentRow);
  23. }
  24. function setOpenedBuilds(link, $currentRow)
  25. {
  26. $.getJSON(link, function(builds)
  27. {
  28. if(!builds) return;
  29. let $row = $currentRow;
  30. while($row.length)
  31. {
  32. const $build = $row.find('[data-name="openedBuild"] .picker').zui('picker');
  33. $build.render({items: builds});
  34. $build.$.setValue($build.$.value.split(','));
  35. $row = $row.next('tr');
  36. if(!$row.find('td[data-name="openedBuild"][data-ditto="on"]').length || !$row.find('td[data-name="branch"][data-ditto="on"]').length) break;
  37. }
  38. });
  39. }
  40. function setLane(event)
  41. {
  42. const $target = $(event.target);
  43. if($target.closest('.form-batch-ditto').data('ditto') == 'on') return false;
  44. const $currentRow = $target.closest('tr');
  45. const regionID = $target.val();
  46. laneLink = $.createLink('kanban', 'ajaxGetLanes', 'regionID=' + regionID + '&type=bug&field&pageType=batch');
  47. $.getJSON(laneLink, function(lanes)
  48. {
  49. if(!lanes) return;
  50. let $row = $currentRow;
  51. while($row.length)
  52. {
  53. const $lane = $row.find('[data-name="laneID"] .picker').zui('picker');
  54. $lane.render({items: lanes});
  55. $lane.$.setValue($lane.options.defaultValue);
  56. $row = $row.next('tr');
  57. if(!$row.find('td[data-name="laneID"][data-ditto="on"]').length || !$row.find('td[data-name="branch"][data-ditto="on"]').length) break;
  58. }
  59. });
  60. }
  61. /**
  62. * Load product executions on project change.
  63. *
  64. * @param {Event} event Project form control change event.
  65. */
  66. function loadProductExecutionsByProject(event)
  67. {
  68. const $target = $(event.target); // Project form control element.
  69. if($target.closest('.form-batch-ditto').data('ditto') == 'on') return false;
  70. const $currentRow = $target.closest('tr'); // Currenr batch form row element.
  71. const projectID = $target.val(); // Project ID.
  72. const productID = $('[name="product"]').val(); // Product ID (from hidden form control).
  73. const branch = $currentRow.find('.form-batch-control[data-name="branch"] input').val() || '0'; // Branch ID (from same row).
  74. /* Get executions with ajax request. */
  75. $.getJSON($.createLink('product', 'ajaxGetExecutionsByProject', 'productID=' + productID + '&projectID=' + projectID + '&branch=' + branch), function(data)
  76. {
  77. /* Return if server do not return any data. */
  78. if(!data || !data.executions) return;
  79. /* Update executions form control in current row and all follow ditto rows. */
  80. let $row = $currentRow; // Start loop from current row.
  81. while($row.length)
  82. {
  83. /* Find execution form control and clear old options. */
  84. const $execution = $row.find('[data-name="execution"] .picker').zui('picker');
  85. $execution.render({items: data.executions});
  86. $execution.$.setValue($execution.$.value);
  87. /* Set next row to current row and continue the loop. */
  88. $row = $row.next('tr');
  89. /* Break loop if next row is not ditto row. */
  90. if(!$row.find('td[data-name="execution"][data-ditto="on"]').length) break;
  91. }
  92. });
  93. const executionID = $currentRow.find('.form-batch-control[data-name="execution"] .picker').zui('picker').$.value || '0';
  94. if(executionID != 0)
  95. {
  96. var link = $.createLink('build', 'ajaxGetExecutionBuilds', 'executionID=' + executionID + '&productID=' + productID + "&varName=openedBuilds&build=&branch=" + branch);
  97. }
  98. else if(projectID != 0)
  99. {
  100. var link = $.createLink('build', 'ajaxGetProjectBuilds', 'projectID=' + projectID + '&productID=' + productID + "&varName=openedBuilds&build=&branch=" + branch);
  101. }
  102. else
  103. {
  104. var link = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + "&varName=openedBuilds&build=&branch=" + branch);
  105. }
  106. setOpenedBuilds(link, $currentRow);
  107. }