setmodule.ui.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. function changeModule($target, type = 'single')
  2. {
  3. const name = $target.attr('name');
  4. if($target.prop('checked'))
  5. {
  6. $("input[type=hidden][name='" + name + "']").val('1').attr('disabled');
  7. if(type == 'single') checkRelated(name, 'open');
  8. }
  9. else
  10. {
  11. $("input[type=hidden][name='" + name + "']").val('1').attr('disabled');
  12. $("input[type=hidden][name='" + name + "']").val('0').removeAttr('disabled');
  13. if(type == 'single') checkRelated(name, 'close');
  14. }
  15. };
  16. function checkModule(event)
  17. {
  18. changeModule($(event.target));
  19. }
  20. function checkGroup()
  21. {
  22. const checked = $(this).prop('checked');
  23. $(this).closest('tr').find("div:not(.hidden) > input[type=checkbox][name^='module']").each(function()
  24. {
  25. const name = $(this).attr('name');
  26. $(this).prop('checked', checked);
  27. $(`input[type=hidden][name='${name}']`).val(checked ? '1' : '0');
  28. });
  29. };
  30. function checkAll()
  31. {
  32. const checked = $(this).prop('checked');
  33. $('input[type=checkbox][name^=allChecker]').prop('checked', checked);
  34. $(this).closest('table').find("div:not(.hidden) > input[type=checkbox][name^='module']").each(function()
  35. {
  36. $(this).prop('checked', checked);
  37. changeModule($(this), 'all');
  38. });
  39. };
  40. window.submitForm = function()
  41. {
  42. const isCheckedUR = $('[name="module[productUR]"]').prop('checked');
  43. const isCheckedER = $('[name="module[productER]"]').prop('checked');
  44. let message = confirmDisableStoryType;
  45. let storyType = '';
  46. if(edition != 'ipd' && URAndSR && !isCheckedUR)
  47. {
  48. storyType += URCommon;
  49. }
  50. if(enableER && !isCheckedER)
  51. {
  52. if(storyType) storyType += ',';
  53. storyType += ERCommon;
  54. }
  55. if(storyType)
  56. {
  57. zui.Modal.confirm(
  58. {
  59. message: message.replace(/{type}/g, storyType),
  60. icon: 'icon-exclamation-sign',
  61. iconClass: 'warning-pale rounded-full icon-2x'
  62. }).then((res) =>
  63. {
  64. if(res)
  65. {
  66. realSubmitForm();
  67. return false;
  68. }
  69. setModuleState('productUR', true);
  70. setModuleState('productER', true);
  71. });
  72. return false;
  73. }
  74. realSubmitForm();
  75. return false;
  76. }
  77. window.realSubmitForm = function()
  78. {
  79. const formData = new FormData($('#setModuleForm form')[0]);
  80. const url = $.createLink('admin', 'setmodule');
  81. $.ajaxSubmit({url: url, data: formData});
  82. }
  83. /**
  84. * 设置模块的checkbox和hidden input状态
  85. * @param {string} moduleName - 模块名称(如 'productUR', 'productER')
  86. * @param {boolean} checked - 是否选中
  87. */
  88. function setModuleState(moduleName, checked)
  89. {
  90. const checkboxSelector = `[name="module[${moduleName}]"]`;
  91. const hiddenSelector = `#module${moduleName}[type=hidden]`;
  92. $(checkboxSelector).prop('checked', checked);
  93. $(hiddenSelector).val(checked ? '1' : '0');
  94. }
  95. /**
  96. * 检查模块是否已启用
  97. * @param {string} moduleName - 模块名称
  98. * @returns {boolean} 是否已启用
  99. */
  100. function isModuleEnabled(moduleName)
  101. {
  102. return $('[name="module[' + moduleName + ']"]').prop('checked');
  103. }
  104. /**
  105. * 显示依赖关系确认对话框
  106. * @param {string} message - 确认消息
  107. * @param {Function} onConfirm - 确认回调
  108. * @param {Function} onCancel - 取消回调
  109. */
  110. function showDependencyConfirm(message, onConfirm, onCancel)
  111. {
  112. zui.Modal.confirm(
  113. {
  114. message: message,
  115. icon: 'icon-exclamation-sign',
  116. iconClass: 'warning-pale rounded-full icon-2x'
  117. }).then((res) =>
  118. {
  119. if(res)
  120. {
  121. if(onConfirm) onConfirm();
  122. return false;
  123. }
  124. if(onCancel) onCancel();
  125. });
  126. }
  127. window.checkRelated = function(name, type)
  128. {
  129. if(type === 'open')
  130. {
  131. // 开启 业务需求 时,需要确保 用户需求 已开启
  132. if(name.includes('productER') && edition !== 'ipd')
  133. {
  134. if(!isModuleEnabled('productUR'))
  135. {
  136. const message = openDependFeature.replace('{source}', ERCommon).replace('{target}', URCommon);
  137. showDependencyConfirm(
  138. message,
  139. () => setModuleState('productUR', true),
  140. () => setModuleState('productER', false)
  141. );
  142. return false;
  143. }
  144. }
  145. // 开启 项目变更 时,需要确保 交付物 已开启
  146. else if(name.includes('projectCm'))
  147. {
  148. if(!isModuleEnabled('projectDeliverable'))
  149. {
  150. const message = openDependFeature.replace('{source}', cmLang).replace('{target}', deliverableLang);
  151. showDependencyConfirm(
  152. message,
  153. () => setModuleState('projectDeliverable', true),
  154. () => setModuleState('projectCm', false)
  155. );
  156. return false;
  157. }
  158. }
  159. // 开启 项目变更 时,需要确保 交付物 和 基线 都已开启
  160. else if(name.includes('projectChange'))
  161. {
  162. const deliverableEnabled = isModuleEnabled('projectDeliverable');
  163. const cmEnabled = isModuleEnabled('projectCm');
  164. if(!deliverableEnabled || !cmEnabled)
  165. {
  166. let message = openDependFeature.replace('{source}', changeLang);
  167. const missingLangs = [];
  168. if(!deliverableEnabled) missingLangs.push(deliverableLang);
  169. if(!cmEnabled) missingLangs.push(cmLang);
  170. message = message.replace('{target}', missingLangs.join(','));
  171. showDependencyConfirm(
  172. message,
  173. () =>
  174. {
  175. if(!deliverableEnabled) setModuleState('projectDeliverable', true);
  176. if(!cmEnabled) setModuleState('projectCm', true);
  177. },
  178. () => setModuleState('projectChange', false)
  179. );
  180. return false;
  181. }
  182. }
  183. }
  184. else
  185. {
  186. // 关闭 用户需求 时,如果 业务需求 已开启,需要提示关闭 业务需求
  187. if(name.includes('productUR') && edition !== 'ipd')
  188. {
  189. if(isModuleEnabled('productER'))
  190. {
  191. const message = closeDependFeature.replace('{source}', URCommon).replace('{target}', ERCommon);
  192. showDependencyConfirm(
  193. message,
  194. () => setModuleState('productER', false),
  195. () =>
  196. {
  197. setModuleState('productUR', true);
  198. setModuleState('productER', true);
  199. }
  200. );
  201. return false;
  202. }
  203. }
  204. // 关闭 交付物 时,如果 项目变更 或 基线 已开启,需要提示关闭它们
  205. else if(name.includes('projectDeliverable'))
  206. {
  207. const changeEnabled = isModuleEnabled('projectChange');
  208. const cmEnabled = isModuleEnabled('projectCm');
  209. if(changeEnabled || cmEnabled)
  210. {
  211. let message = closeDependFeature.replace('{source}', deliverableLang);
  212. const activeLangs = [];
  213. if(changeEnabled) activeLangs.push(changeLang);
  214. if(cmEnabled) activeLangs.push(cmLang);
  215. message = message.replace('{target}', activeLangs.join(','));
  216. showDependencyConfirm(
  217. message,
  218. () =>
  219. {
  220. if(changeEnabled) setModuleState('projectChange', false);
  221. if(cmEnabled) setModuleState('projectCm', false);
  222. },
  223. () => setModuleState('projectDeliverable', true)
  224. );
  225. }
  226. }
  227. // 关闭 基线 时,如果 项目变更 已开启,需要提示关闭 项目变更
  228. else if(name.includes('projectCm'))
  229. {
  230. if(isModuleEnabled('projectChange'))
  231. {
  232. const message = closeDependFeature.replace('{source}', cmLang).replace('{target}', changeLang);
  233. showDependencyConfirm(
  234. message,
  235. () => setModuleState('projectChange', false),
  236. () => setModuleState('projectCm', true)
  237. );
  238. }
  239. }
  240. }
  241. }