gantt.ui.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. window.clickSubmit = function(e)
  2. {
  3. const $taskBatchForm = $('#taskBatchEditForm' + executionID);
  4. if(nonStoryChildTasks.length == 0)
  5. {
  6. return checkRelation();
  7. }
  8. else
  9. {
  10. const $taskBatchFormTrs = $taskBatchForm.find('tbody tr');
  11. var confirmID = '';
  12. for(let i = 0; i < $taskBatchFormTrs.length; i++)
  13. {
  14. const $currentTr = $($taskBatchFormTrs[i]);
  15. const taskID = $currentTr.find('.form-batch-control[data-name=id]').find('input[name^=id]').val();
  16. const storyID = $currentTr.find('.form-batch-control[data-name=story]').find('input[name^=story]').val();
  17. if(tasks[taskID].story == storyID) continue;
  18. if(!storyID && tasks[taskID].parent <= 0) continue;
  19. if(tasks[taskID].parent > 0)
  20. {
  21. if(storyID) confirmID = confirmID.replace('ID' + taskID + ', ', '');
  22. continue;
  23. }
  24. if(typeof childTasks[taskID] != 'object' || typeof nonStoryChildTasks[taskID] != 'object') continue;
  25. const nonStoryChildTaskIdList = Object.keys(nonStoryChildTasks[taskID]);
  26. if(nonStoryChildTaskIdList.length == 0) continue;
  27. for(let j = 0; j < nonStoryChildTaskIdList.length; j++) confirmID += 'ID' + nonStoryChildTaskIdList[j].toString() + ', ';
  28. }
  29. if(confirmID.length > 0)
  30. {
  31. if(confirmID.endsWith(', ')) confirmID = confirmID.slice(0, -2);
  32. let confirmTip = syncStoryToChildrenTip.replace('%s', confirmID);
  33. zui.Modal.confirm(confirmTip).then((res) =>
  34. {
  35. $taskBatchForm.find('[name=syncChildren]').remove();
  36. $taskBatchForm.append('<input type="hidden" name="syncChildren" value="' + (res ? '1' : '0') + '" />');
  37. if(checkRelation())
  38. {
  39. const formData = new FormData($taskBatchForm[0]);
  40. const confirmURL = $taskBatchForm.attr('action');
  41. $.ajaxSubmit({url: confirmURL, data: formData});
  42. }
  43. });
  44. }
  45. else
  46. {
  47. return true;
  48. }
  49. return false;
  50. }
  51. }
  52. function checkRelation()
  53. {
  54. const $taskBatchForm = $('#taskBatchEditForm' + executionID);
  55. let checkRelation = false;
  56. let taskID = 0;
  57. let checkTasks = '';
  58. $('[name^=status]').each(function()
  59. {
  60. taskID = $(this).closest('tr').find('[name^=id]').val();
  61. if($(this).val() == 'cancel' && tasks[taskID].status != 'cancel')
  62. {
  63. checkRelation = true;
  64. checkTasks += taskID + ',';
  65. }
  66. })
  67. checkTasks = checkTasks.replace(/^,+|,+$/g, '');
  68. if(checkRelation && checkTasks)
  69. {
  70. let blockSubmit = true;
  71. $.get($.createLink('task', 'ajaxGetRelation', 'taskIdList=' + checkTasks), function(data)
  72. {
  73. if(data)
  74. {
  75. zui.Modal.confirm({message: unlinkRelationTip, actions: [{key: 'confirm', text: unlinkLang, btnType: 'primary', class: 'btn-wide'}, {key: 'cancel'}]}).then((res) =>
  76. {
  77. if(res)
  78. {
  79. const link = $taskBatchForm.attr('action');
  80. let formData = $taskBatchForm.serialize();
  81. let postData = {};
  82. let params = new URLSearchParams(formData);
  83. for(const[key, value] of params.entries())
  84. {
  85. const decodedKey = decodeURIComponent(key);
  86. const decodedValue = decodeURIComponent(value);
  87. if(!(decodedKey in postData)) postData[decodedKey] = [];
  88. postData[decodedKey].push(decodedValue);
  89. }
  90. $.ajaxSubmit({url: link, data: postData});
  91. }
  92. else
  93. {
  94. return false;
  95. }
  96. })
  97. }
  98. else
  99. {
  100. blockSubmit = false;
  101. }
  102. })
  103. return !blockSubmit;
  104. }
  105. return true;
  106. }