common.ui.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. window.loadProductStories = function(productID)
  2. {
  3. let branch = $('[name=branch]').val();
  4. let moduleID = $('[name=module]').val();
  5. let storyID = $('[name=story]').val();
  6. if(typeof(branch) == 'undefined') branch = 0;
  7. if(typeof(moduleID) == 'undefined') moduleID = 0;
  8. if(typeof(storyID) == 'undefined') storyID = 0;
  9. const link = $.createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleID=' + moduleID + '&storyID=' + storyID + '&onlyOption=false&status=active&limit=0&type=&hasParent=0&objectID=' + objectID);
  10. $.getJSON(link, function(data)
  11. {
  12. let $storyPicker = $('[name=story]').zui('picker');
  13. $storyPicker.render({items: data});
  14. $storyPicker.$.setValue(storyID);
  15. })
  16. }
  17. window.loadProductBranches = function(productID)
  18. {
  19. const oldBranch = config.currentMethod == 'edit' ? caseBranch : 0;
  20. let param = 'productID=' + productID + '&oldBranch=' + oldBranch + '&param=' + (config.currentMethod == 'create' ? 'active' : 'all');
  21. if(typeof(tab) != 'undefined' && (tab == 'execution' || tab == 'project')) param += '&projectID=' + objectID;
  22. $.getJSON($.createLink('branch', 'ajaxGetBranches', param), function(data)
  23. {
  24. $('#branch').toggleClass('hidden', data.length <= 0);
  25. let branch = $('[name=branch]').val();
  26. let $branchPicker = $('[name=branch]').zui('picker');
  27. $branchPicker.render({items: data});
  28. $branchPicker.$.setValue(branch);
  29. })
  30. }
  31. window.loadProductModules = function(productID)
  32. {
  33. let branch = $('[name=branch]').val();
  34. if(typeof(branch) == 'undefined') branch = 0;
  35. const getModuleLink = $.createLink('testcase', 'ajaxGetOptionMenu', 'rootID=' + productID + '&branch=' + branch + '&rootModuleID=0&returnType=html&fieldID=');
  36. $.getJSON(getModuleLink, function(data)
  37. {
  38. let oldModule = $('[name=module]').val();
  39. let $modulePicker = $('[name=module]').zui('picker');
  40. $modulePicker.render({items: data});
  41. $modulePicker.$.setValue(oldModule);
  42. $('#module').next('.input-group-addon').toggleClass('hidden', data.length > 1);
  43. })
  44. }
  45. window.loadScenes = function(productID, sceneName = 'scene')
  46. {
  47. let branchID = $('[name=branch]').val();
  48. let moduleID = $('[name=module]').val();
  49. if(typeof(branchID) == 'undefined') branchID = 0;
  50. if(typeof(moduleID) == 'undefined') moduleID = 0;
  51. if(typeof(sceneID) == 'undefined') sceneID = 0;
  52. const link = $.createLink('testcase', 'ajaxGetScenes', 'productID=' + productID + '&branch=' + branchID + '&moduleID=' + moduleID + '&sceneID=' + sceneID);
  53. $.getJSON(link, function(scenes)
  54. {
  55. const $picker = $('[name=' + sceneName + ']').zui('picker');
  56. $picker.render({items: scenes});
  57. $picker.$.setValue(sceneID);
  58. });
  59. }
  60. /**
  61. * Set modules.
  62. *
  63. * @param int $branchID
  64. * @param int $productID
  65. * @param int $num
  66. * @access public
  67. * @return void
  68. */
  69. window.onBranchChangedForBatch = function(event)
  70. {
  71. const $target = $(event.target);
  72. const $currentRow = $target.closest('tr');
  73. const branchID = $target.val();
  74. const moduleID = $currentRow.find('.form-batch-control[data-name="module"] .pick-value').val();
  75. const product = productID == 0 ? $currentRow.find('.form-batch-control[data-name="product"] input').val() : productID;
  76. $.getJSON($.createLink('tree', 'ajaxGetModules', 'productID=' + product + '&viewType=case&branch=' + branchID + '&number=0&currentModuleID=' + moduleID), function(data)
  77. {
  78. if(!data || !data.modules) return;
  79. let $row = $currentRow;
  80. while($row.length)
  81. {
  82. const $module = $row.find('.form-batch-control[data-name="module"] .picker').zui('picker');
  83. $module.render({items: data.modules});
  84. $module.$.setValue(data.currentModuleID);
  85. $row = $row.next('tr');
  86. if(!$row.find('td[data-name="module"][data-ditto="on"]').length || !$row.find('td[data-name="branch"][data-ditto="on"]').length) break;
  87. }
  88. });
  89. loadScenesForBatch(product, moduleID, $currentRow);
  90. loadStoriesForBatch(product, moduleID, 0, $currentRow);
  91. }
  92. window.onModuleChangedForBatch = function(event)
  93. {
  94. const $target = $(event.target);
  95. const $currentRow = $target.closest('tr');
  96. const moduleID = $target.val();
  97. loadScenesForBatch(productID, moduleID, $currentRow);
  98. loadStoriesForBatch(productID, moduleID, 0, $currentRow);
  99. }
  100. window.loadScenesForBatch = function(productID, moduleID, $currentRow)
  101. {
  102. let branchID = $currentRow.find('.form-batch-control[data-name="branch"] .pick-value').val();
  103. if(!branchID) branchID = 0;
  104. const sceneLink = $.createLink('testcase', 'ajaxGetScenes', 'productID=' + productID + '&branch=' + branchID + '&moduleID=' + moduleID);
  105. $.getJSON(sceneLink, function(scenes)
  106. {
  107. let $row = $currentRow;
  108. while($row.length)
  109. {
  110. const $scene = $row.find('.form-batch-control[data-name="scene"] .picker').zui('picker');
  111. $scene.render({items: scenes});
  112. $scene.$.setValue($scene.$.value);
  113. $row = $row.next('tr');
  114. if(!$row.find('td[data-name="module"][data-ditto="on"]').length) break;
  115. }
  116. });
  117. }
  118. /**
  119. * Set stories.
  120. *
  121. * @param int productID
  122. * @param int moduleID
  123. * @param int num
  124. * @access public
  125. * @return void
  126. */
  127. window.loadStoriesForBatch = function(productID, moduleID, num, $currentRow = null)
  128. {
  129. let branchID = $currentRow.find('.form-batch-control[data-name="branch"]').length ? $currentRow.find('.form-batch-control[data-name="branch"] .pick-value').val() : 0;
  130. if(!branchID) branchID = 0;
  131. const storyLink = $.createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branchID + '&moduleID=' + moduleID + '&storyID=0&onlyOption=false&status=active&limit=0&type=&hasParent=0&objectID=0&number=' + num);
  132. $.getJSON(storyLink, function(stories)
  133. {
  134. let $row = $currentRow;
  135. while($row.length)
  136. {
  137. const $story = $row.find('.form-batch-control[data-name="story"] .picker').zui('picker');
  138. $story.render({items: stories});
  139. $story.$.setValue($story.$.value);
  140. $row = $row.next('tr');
  141. if(($row.find('td[data-name="branch"]').length && !$row.find('td[data-name="branch"][data-ditto="on"]').length) || !$row.find('td[data-name="module"][data-ditto="on"]').length) break;
  142. }
  143. });
  144. }