common.ui.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. window.clickSubmit = function(e)
  2. {
  3. const status = $(e.submitter).data('status');
  4. if(status === undefined) return;
  5. const method = typeof(page) !== 'undefined' ? page : config.currentMethod;
  6. let storyStatus = status;
  7. if(status == 'active' && method != 'batchcreate')
  8. {
  9. storyStatus = !$('[name^=reviewer]').val() || $('#needNotReview').prop('checked') ? 'active' : 'reviewing';
  10. }
  11. if(status == 'draft' && (method == 'change' || (method == 'edit' && $('#status').val() == 'changing')))
  12. {
  13. storyStatus = 'changing';
  14. }
  15. $(e.submitter).closest('form').find('[name=status]').val(storyStatus);
  16. };
  17. window.unlinkTwins = function(e)
  18. {
  19. const $this = $(e.target).closest('li').find('.relievedTwins');
  20. const $ul = $this.closest('ul');
  21. const postData = new FormData();
  22. postData.append('twinID', $this.data('id'));
  23. zui.Modal.confirm({message: window.relievedTip || $ul.data('relievedTip'), icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) =>
  24. {
  25. if(res)
  26. {
  27. $.post($.createLink('story', 'ajaxRelieveTwins'), postData, function()
  28. {
  29. $this.closest('li').remove();
  30. if($ul.find('li').length == 0) $ul.closest('.section').remove();
  31. });
  32. }
  33. });
  34. };
  35. window.toggleFeedback = function(obj)
  36. {
  37. if(storyType == 'requirement') return false;
  38. const $this = $(obj);
  39. const source = $this.val();
  40. if(!source) return;
  41. $('.feedbackBox').toggleClass('hidden', !feedbackSource.includes(source));
  42. }
  43. window.loadBranchModule = function(productID)
  44. {
  45. const branch = $('[name=branch]').val();
  46. const moduleID = $('[name=module]').val();
  47. if(!branch) branch = 0;
  48. var moduleLink = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=story&branch=' + branch + '&rootModuleID=0&returnType=html&fieldID=&extra=nodeleted&currentModuleID=' + moduleID);
  49. const $modulePicker = $('[name^=module]').zui('picker');
  50. $.getJSON(moduleLink, function(data)
  51. {
  52. $modulePicker.render({items: data.items})
  53. $modulePicker.$.setValue(moduleID);
  54. });
  55. };
  56. window.loadProductPlans = function(productID, branch)
  57. {
  58. if(typeof(branch) == 'undefined') branch = 0;
  59. if(!branch) branch = 0;
  60. let params = config.currentMethod == 'create' ? 'unexpired,noclosed' : '';
  61. let planLink = $.createLink('product', 'ajaxGetPlans', 'productID=' + productID + '&branch=' + branch + '&params=' + params + '&skipParent=true');
  62. let $planIdBox = $('div[data-name="plan"] #planIdBox');
  63. $.get(planLink, function(data)
  64. {
  65. let items = JSON.parse(data);
  66. let $inputGroup = $planIdBox.closest('.input-group');
  67. $inputGroup.html("<span id='planIdBox'><div class='picker-box' id='plan'></div></span>")
  68. new zui.Picker('#planIdBox #plan', {items: items, name: 'plan', defaultValue: ''});
  69. if(items.length == 0)
  70. {
  71. $inputGroup.append('<a class="btn btn-default" type="button" data-size="lg" data-toggle="modal" href="' + $.createLink('productplan', 'create', 'productID=' + productID + '&branch=' + branch) + '"><i class="icon icon-plus"></i></a>');
  72. $inputGroup.append(`<button class="refresh btn" type="button" onclick="window.loadProductPlans(${productID},${branch})"><i class="icon icon-refresh"></i></button>`);
  73. }
  74. })
  75. };
  76. window.loadBranch = function()
  77. {
  78. var branch = $('[name=branch]').val();
  79. var productID = $('[name=product]').val();
  80. if(typeof(branch) == 'undefined') branch = 0;
  81. if($('[name=roadmap]').length)
  82. {
  83. window.loadProductRoadmaps(productID, branch);
  84. }
  85. else
  86. {
  87. window.loadProductPlans(productID, branch);
  88. }
  89. window.loadBranchModule(productID);
  90. };
  91. window.setModuleAndPlanByBranch = function(e)
  92. {
  93. const $branch = $(e.target);
  94. const branchID = $branch.val();
  95. let $row = $branch.closest('tr');
  96. var moduleLink = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=story&branch=' + branchID + '&rootModuleID=0&returnType=html&fieldID=&extra=nodeleted');
  97. while($row.length)
  98. {
  99. const $modulePicker = $row.find('[name^=module]').zui('picker');
  100. const moduleID = $row.find('[name^=module]').val();
  101. $.getJSON(moduleLink, function(data)
  102. {
  103. $modulePicker.render({items: data.items})
  104. $modulePicker.$.setValue(moduleID);
  105. });
  106. $row = $row.next('tr');
  107. if(!$row.find('td[data-name="module"][data-ditto="on"]').length) break;
  108. }
  109. var planLink = $.createLink('productPlan', 'ajaxGetProductPlans', 'productID=' + productID + '&branch=' + branchID);
  110. let $rows = $branch.closest('tr');
  111. while($rows.length)
  112. {
  113. const $planPicker = $rows.find('[name^=plan]').zui('picker');
  114. const planID = $rows.find('[name^=plan]').val();
  115. $.getJSON(planLink, function(data)
  116. {
  117. $planPicker.render({items: data})
  118. $planPicker.$.setValue(planID);
  119. });
  120. $rows = $rows.next('tr');
  121. if(!$rows.find('td[data-name="plan"][data-ditto="on"]').length) break;
  122. }
  123. }
  124. window.setSourceNote = function(e)
  125. {
  126. const $row = $(e.target).closest('tr');
  127. const $sourceNote = $row.find('[data-name="sourceNote"]').closest('td');
  128. renderSourceNote($sourceNote, e.target.value);
  129. }
  130. function renderSourceNote($sourceNote, source, sourceNote)
  131. {
  132. const $row = $sourceNote.closest('tr');
  133. const index = $row.attr('data-index');
  134. const sourceName = $sourceNote.find('input').attr('name');
  135. if(source === undefined) source = $row.find('[name^="source"]').val();
  136. if(sourceNote === undefined) sourceNote = '';
  137. if(source == 'researchreport')
  138. {
  139. const sourceNoteID = `sourceNote_${index}`;
  140. $sourceNote.html(`<div class='form-group-wrapper picker-box' id=${sourceNoteID}></div>`);
  141. $.getJSON($.createLink('story', 'ajaxGetSourceNote'), function(sourceNoteItems)
  142. {
  143. $sourceNotePicker = new zui.Picker(`#${sourceNoteID}`, {items: sourceNoteItems, name: sourceName, defaultValue: sourceNote});
  144. });
  145. }
  146. else
  147. {
  148. $sourceNote.html(`<input class="form-control form-batch-input" type="text" autocomplete="off" name=${sourceName} id="sourceNote" data-name="sourceNote">`);
  149. }
  150. }