mergeprogram.ui.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. $(function()
  2. {
  3. initFormData();
  4. });
  5. window.changeAllLines = function()
  6. {
  7. $('input[name^=productLines]').prop('checked', $('#checkAllLines').prop('checked'));
  8. $('#checkAllProducts').prop('checked', $('#checkAllLines').prop('checked'));
  9. changeAllProducts();
  10. }
  11. window.changeAllProducts = function()
  12. {
  13. $('input[name^=products]').prop('checked', $('#checkAllProducts').prop('checked'));
  14. $('input[name^=products]').each(function()
  15. {
  16. const lineID = $(this).data('line');
  17. if(lineID) checkGroupLines(lineID);
  18. });
  19. $('#checkAllSprints').prop('checked', $('#checkAllProducts').prop('checked'));
  20. changeAllSprints();
  21. }
  22. window.changeAllSprints = function()
  23. {
  24. $('input[name^=sprints]').prop('checked', $('#checkAllSprints').prop('checked'));
  25. $('input[name^=sprints]').each(function()
  26. {
  27. const productID = $(this).data('product');
  28. const lineID = $(this).data('line');
  29. checkGroupProducts(lineID, productID);
  30. if(lineID) checkGroupLines(lineID);
  31. });
  32. buildForm();
  33. }
  34. window.changeLines = function(event)
  35. {
  36. checkAllLines();
  37. const lineID = $(event.target).val();
  38. $('input[id^=products-' + lineID + '-]').prop('checked', $(event.target).prop('checked'));
  39. checkAllProducts();
  40. $('input[id^=sprints-' + lineID + '-]').prop('checked', $(event.target).prop('checked'));
  41. checkAllSprints();
  42. buildForm();
  43. }
  44. window.changeProducts = function(event)
  45. {
  46. checkAllProducts();
  47. const productID = $(event.target).val();
  48. const lineID = $(event.target).data('line');
  49. if(lineID)
  50. {
  51. $('input[id^=sprints-' + lineID + '-' + productID + '-]').prop('checked', $(event.target).prop('checked'));
  52. checkGroupLines(lineID);
  53. }
  54. else
  55. {
  56. $('input[id^=sprints-' + productID + '-]').prop('checked', $(event.target).prop('checked'));
  57. }
  58. checkAllSprints();
  59. buildForm();
  60. }
  61. window.changeSprints = function(event)
  62. {
  63. checkAllSprints();
  64. const productID = $(event.target).data('product');
  65. const lineID = $(event.target).data('line');
  66. checkGroupProducts(lineID, productID);
  67. if(lineID) checkGroupLines(lineID);
  68. buildForm();
  69. }
  70. window.changeProjectType = function()
  71. {
  72. const projectType = $('input[name=projectType]:checked').val();
  73. $('.programForm, .formTitle').toggleClass('hidden', projectType == 'project' && mode == 'light');
  74. $('.createProjectTip').toggleClass('hidden', projectType != 'project');
  75. $('.createExecutionTip').toggleClass('hidden', projectType != 'execution');
  76. $('[name=projectAcl]').closest('.check-list').toggleClass('hidden', projectType == 'project');
  77. $('[name=programAcl]').closest('.check-list').toggleClass('hidden', projectType == 'execution');
  78. $('.projectName').toggleClass('hidden', projectType == 'project');
  79. $('.projectStatus').toggleClass('hidden', projectType == 'project');
  80. if(projectType == 'project')
  81. {
  82. $('[name=projectAcl]').attr('disabled', 'disabled');
  83. $('[name=programAcl]').removeAttr('disabled');
  84. }
  85. if(projectType == 'execution')
  86. {
  87. $('[name=programAcl]').attr('disabled', 'disabled');
  88. $('[name=projectAcl]').removeAttr('disabled');
  89. }
  90. }
  91. window.changeNewProgram = function()
  92. {
  93. const checkedNewProgram = $('input[name=newProgram]').prop('checked');
  94. $('#programs').toggleClass('hidden', checkedNewProgram);
  95. $('#programName').toggleClass('hidden', !checkedNewProgram);
  96. if(checkedNewProgram)
  97. {
  98. $('#programs').attr('disabled', 'disabled');
  99. }
  100. else
  101. {
  102. $('#programs').removeAttr('disabled');
  103. }
  104. }
  105. window.changeNewProject = function()
  106. {
  107. const checkedNewProject = $('input[name=newProject]').prop('checked');
  108. $('#projects').toggleClass('hidden', checkedNewProject);
  109. $('#projectName').toggleClass('hidden', !checkedNewProject);
  110. if(checkedNewProject)
  111. {
  112. $('#projects').attr('disabled', 'disabled');
  113. }
  114. else
  115. {
  116. $('#projects').removeAttr('disabled');
  117. }
  118. }
  119. window.changeNewLine = function()
  120. {
  121. const checkedNewLine = $('input[name=newLine]').prop('checked');
  122. $('#lines').toggleClass('hidden', checkedNewLine);
  123. $('#lineName').toggleClass('hidden', !checkedNewLine);
  124. if(checkedNewLine)
  125. {
  126. $('#lines').attr('disabled', 'disabled');
  127. }
  128. else
  129. {
  130. $('#lines').removeAttr('disabled');
  131. }
  132. }
  133. window.changePrograms = function()
  134. {
  135. const programID = $('#programs').zui('picker').$.state.value;
  136. setStatus('program', programID);
  137. getProjectByProgram(programID);
  138. getLineByProgram(programID);
  139. }
  140. window.changeLongTime = function()
  141. {
  142. const checkedLongTime = $('input[name=longTime]').prop('checked');
  143. if(checkedLongTime)
  144. {
  145. $('#end').datePicker({disabled: true});
  146. }
  147. else
  148. {
  149. $('#end').datePicker({disabled: false});
  150. }
  151. }
  152. window.clickSubmit = function()
  153. {
  154. if(type == 'productline')
  155. {
  156. var checkedProductCount = $("input[name^='products']:checked").length;
  157. if(checkedProductCount <= 0)
  158. {
  159. zui.Modal.alert(errorNoProduct);
  160. return false;
  161. }
  162. }
  163. else if(type == 'product')
  164. {
  165. var checkedProductCount = $("input[name^='products']:checked").length;
  166. if(checkedProductCount <= 0)
  167. {
  168. zui.Modal.alert(errorNoProduct);
  169. return false;
  170. }
  171. var executionCount = 0;
  172. var checkedExecutionCount = 0;
  173. $("input[name^='products']:checked").each(function()
  174. {
  175. var productID = $(this).val()
  176. executionCount += $("[data-product='" + productID + "']").length;
  177. checkedExecutionCount += $("[data-product='" + productID + "']:checked").length;
  178. });
  179. if(executionCount !== 0 && checkedExecutionCount === 0)
  180. {
  181. zui.Modal.alert(errorNoExecution);
  182. return false;
  183. }
  184. }
  185. else
  186. {
  187. var checkedExecutionCount = $("input[name^='sprints']:checked").length;
  188. if(checkedExecutionCount === 0)
  189. {
  190. zui.Modal.alert(errorNoExecution);
  191. return false;
  192. }
  193. }
  194. }
  195. window.checkAllLines = function()
  196. {
  197. let allChecked = true;
  198. $('input[name^=productLines]').each(function()
  199. {
  200. if(!$(this).prop('checked')) allChecked = false;
  201. });
  202. $('#checkAllLines').prop('checked', allChecked);
  203. }
  204. window.checkAllProducts = function()
  205. {
  206. let allChecked = true;
  207. $('input[name^=products]').each(function()
  208. {
  209. if(!$(this).prop('checked')) allChecked = false;
  210. });
  211. $('#checkAllProducts').prop('checked', allChecked);
  212. }
  213. window.checkAllSprints = function()
  214. {
  215. let allChecked = true;
  216. $('input[name^=sprints]').each(function()
  217. {
  218. if(!$(this).prop('checked')) allChecked = false;
  219. });
  220. $('#checkAllSprints').prop('checked', allChecked);
  221. }
  222. window.checkGroupLines = function(lineID)
  223. {
  224. let allChecked = true;
  225. $('input[id^=products-' + lineID + '-]').each(function()
  226. {
  227. if(!$(this).prop('checked')) allChecked = false;
  228. });
  229. $('#productLines' + lineID).prop('checked', allChecked);
  230. checkAllLines();
  231. }
  232. window.checkGroupProducts = function(lineID, productID)
  233. {
  234. let allChecked = true;
  235. if(lineID)
  236. {
  237. $('input[id^=sprints-'+ lineID +'-' + productID + '-]').each(function()
  238. {
  239. if(!$(this).prop('checked')) allChecked = false;
  240. });
  241. $('#products-'+ lineID +'-' + productID).prop('checked', allChecked);
  242. }
  243. else
  244. {
  245. $('input[id^=sprints-' + productID + '-]').each(function()
  246. {
  247. if(!$(this).prop('checked')) allChecked = false;
  248. });
  249. $('#products' + productID).prop('checked', allChecked);
  250. }
  251. checkAllProducts();
  252. }
  253. window.buildForm = function()
  254. {
  255. initFormData();
  256. setProgramName();
  257. setProgramBegin();
  258. setProgramEnd();
  259. setProjectStatus();
  260. setProjectPM();
  261. }
  262. window.setProgramName = function()
  263. {
  264. const programID = $('input[name^=products]:checked').data('programid');
  265. if(programID)
  266. {
  267. $('.programName').not('.hidden').find('input[name=newProgram]').prop('checked', false);
  268. changeNewProgram();
  269. $('input[name=newProgram]').attr('disabled', 'disabled');
  270. $('#programs').zui('picker').$.changeState({value: programID.toString()});
  271. $("#programs").zui('picker').render({disabled: true});
  272. $('#programID').val(programID);
  273. getProjectByProgram(programID);
  274. }
  275. else
  276. {
  277. $('input[name=newProgram]').removeAttr('disabled');
  278. $("#programs").zui('picker').render({disabled: false});
  279. $('#programID').val('');
  280. }
  281. }
  282. window.setProgramBegin = function()
  283. {
  284. let minBegin = today;
  285. $('input[type=checkbox][data-begin]:checked').each(function()
  286. {
  287. begin = $(this).attr('data-begin').substr(0, 10);
  288. if(begin == '0000-00-00') return;
  289. if(begin < minBegin) minBegin = begin;
  290. });
  291. $('#begin').zui('datePicker').$.changeState({value: minBegin});
  292. }
  293. window.setProgramEnd = function()
  294. {
  295. let minEnd = '';
  296. $('input[type=checkbox][data-end]:checked').each(function()
  297. {
  298. end = $(this).attr('data-end').substr(0, 10);
  299. if(end == '0000-00-00') return true;
  300. if(end > minEnd) minEnd = end;
  301. });
  302. $('#end').zui('datePicker').$.changeState({value: minEnd});
  303. }
  304. window.setProjectStatus = function()
  305. {
  306. var projectStatus = 'wait';
  307. $('input[type=checkbox][data-status]:checked').each(function()
  308. {
  309. var status = $(this).attr('data-status');
  310. if(status == 'doing' || status == 'suspended')
  311. {
  312. projectStatus = 'doing';
  313. return false;
  314. }
  315. });
  316. $('#projectStatus').zui('picker').$.changeState({value: projectStatus})
  317. setProgramStatus(projectStatus);
  318. }
  319. window.setProjectPM = function()
  320. {
  321. let PM = [];
  322. $('input[type=checkbox][data-pm]:checked').each(function()
  323. {
  324. let PMName = $(this).attr('data-pm');
  325. PM[PMName] = PM[PMName] == undefined ? 0 : PM[PMName];
  326. PM[PMName] = PM[PMName] + 1;
  327. });
  328. PM.sort(function(el1, el2){return el2 - el1;});
  329. PMNameList = Object.keys(PM);
  330. PMNameList = PMNameList.filter(Boolean);
  331. $('#PM').zui('picker').$.changeState({value: PMNameList[0]});
  332. }
  333. window.setProgramStatus = function(projectStatus)
  334. {
  335. var programStatus = 'wait';
  336. if(projectStatus != 'wait') programStatus = 'doing';
  337. if(projectStatus == 'closed') programStatus = 'closed';
  338. $('#programStatus').zui('picker').$.changeState({value: programStatus});
  339. }
  340. window.initFormData = function()
  341. {
  342. $('#programBox').toggleClass('hidden', $('[name^=sprints]:checked').length == 0 && mode == 'light');
  343. $('.programParams').toggleClass('hidden', $('[name^=sprints]:checked').length == 0);
  344. $('.programForm').toggleClass('hidden', $('[name^=sprints]:checked').length != 0 && projectType == 'project' && mode == 'light');
  345. if($('[name^=sprints]:checked').length == 0)
  346. {
  347. $(".programParams input").attr('disabled' ,'disabled');
  348. $(".programParams .picker-field").zui('picker').render({disabled: true});
  349. $(".projectName input").attr('disabled' ,'disabled');
  350. $(".projectName .picker-field").zui('picker').render({disabled: true});
  351. }
  352. else
  353. {
  354. $(".programParams input").removeAttr('disabled');
  355. $(".programParams .picker-field").zui('picker').render({disabled: false});
  356. $(".projectName input").removeAttr('disabled');
  357. $(".projectName .picker-field").zui('picker').render({disabled: false});
  358. changeProjectType();
  359. if(mode == 'light')
  360. {
  361. $('.programName').find('input[name=newProgram]').prop('checked', false);
  362. changeNewProgram();
  363. }
  364. }
  365. }
  366. window.setStatus = function(objectType, objectID)
  367. {
  368. const link = $.createLink('upgrade', 'ajaxGetProgramStatus', 'objectID=' + objectID);
  369. $.get(link, function(data)
  370. {
  371. if(objectType == 'program') $('#programStatus').zui('picker').$.changeState({value: data});
  372. if(objectType == 'project') $('#projectStatus').zui('picker').$.changeState({value: data});
  373. })
  374. }
  375. window.getProjectByProgram = function(programID)
  376. {
  377. const link = $.createLink('upgrade', 'ajaxGetProjectPairsByProgram', 'programID=' + programID);
  378. $.get(link, function(data)
  379. {
  380. data = JSON.parse(data);
  381. $('#projects').zui('picker').render({items: data.projects});
  382. })
  383. }
  384. window.getLineByProgram = function(programID)
  385. {
  386. const link = $.createLink('upgrade', 'ajaxGetLinesPairsByProgram', 'programID=' + programID);
  387. $.get(link, function(data)
  388. {
  389. data = JSON.parse(data);
  390. $('#lines').zui('picker').render({items: data.lines});
  391. })
  392. }