From 3729cbf2c57ce9953be9b9d0be49d3ed40e9611a Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 15 Oct 2024 13:25:10 +0800 Subject: [PATCH] * [task#130461,doing,1h] move before submit js in batchEdit. --- module/task/js/batchedit.ui.js | 48 +++++++++++++++++++++++ module/task/ui/batchedit.html.php | 65 ++++--------------------------- 2 files changed, 55 insertions(+), 58 deletions(-) diff --git a/module/task/js/batchedit.ui.js b/module/task/js/batchedit.ui.js index 713c883db5..d5a7c69c60 100644 --- a/module/task/js/batchedit.ui.js +++ b/module/task/js/batchedit.ui.js @@ -58,3 +58,51 @@ window.renderRowData = function($row, index, row) }); } } + +window.clickSubmit = async function(e) +{ + if(!nonStoryChildTasks) return true; + const $taskBatchForm = $('#taskBatchEditForm' + executionID); + const $taskBatchFormTrs = $taskBatchForm.find('tbody tr'); + + var confirmID = ''; + var tipAll = true; + for(let i = 0; i < $taskBatchFormTrs.length; i++) + { + const $currentTr = $($taskBatchFormTrs[i]); + const taskID = $currentTr.find('.form-batch-control[data-name=id]').find('input[name^=id]').val(); + const storyID = $currentTr.find('.form-batch-control[data-name=story]').find('input[name^=story]').val(); + + if(tasks[taskID].story == storyID) continue; + if(!storyID && tasks[taskID].parent <= 0) continue; + if(tasks[taskID].parent > 0) + { + if(storyID) confirmID = confirmID.replace('ID' + taskID + ', ', ''); + continue; + } + if(typeof childTasks[taskID] != 'object' || typeof nonStoryChildTasks[taskID] != 'object') continue; + + const nonStoryChildTaskIdList = Object.keys(nonStoryChildTasks[taskID]); + if(nonStoryChildTaskIdList.length == 0) continue; + + if(tipAll) tipAll = Object.keys(childTasks[taskID]).length == nonStoryChildTaskIdList.length; + + for(let j = 0; j < nonStoryChildTaskIdList.length; j++) confirmID += 'ID' + nonStoryChildTaskIdList[j].toString() + ', '; + } + if(confirmID.length == 0) return true; + + if(confirmID.endsWith(', ')) confirmID = confirmID.slice(0, -2); + + let confirmTip = tipAll ? syncStoryToAllChildrenTip : syncStoryToChildrenTip; + confirmTip = confirmTip.replace('%s', confirmID); + zui.Modal.confirm(confirmTip).then((res) => + { + $taskBatchForm.find('[name=syncChildren]').remove(); + $taskBatchForm.append(''); + + const formData = new FormData($taskBatchForm[0]); + const confirmURL = $taskBatchForm.attr('action'); + $.ajaxSubmit({url: confirmURL, data: formData}); + }); + return false; +}; diff --git a/module/task/ui/batchedit.html.php b/module/task/ui/batchedit.html.php index c69b3fac1d..1ec7664866 100644 --- a/module/task/ui/batchedit.html.php +++ b/module/task/ui/batchedit.html.php @@ -17,63 +17,12 @@ jsVar('users', $users); jsVar('teams', $teams); jsVar('currentUser', $app->user->account); jsVar('moduleGroup', $moduleGroup); - -$beforeSubmit = null; -$childTasks = json_encode($childTasks); -$nonStoryChildTasks = json_encode($nonStoryChildTasks); -$tasksJsVar = json_encode($tasks); -if(!empty($nonStoryChildTasks)) -{ - $beforeSubmit = jsRaw("() => - { - const \$taskBatchForm = $('#taskBatchEditForm{$executionID}'); - const childTasks = $childTasks; - const nonStoryChildTasks = $nonStoryChildTasks; - const \$taskBatchFormTrs = \$taskBatchForm.find('tbody tr'); - const tasks = $tasksJsVar; - - var confirmID = ''; - var tipAll = true; - for(let i = 0; i < \$taskBatchFormTrs.length; i++) - { - const \$currentTr = $(\$taskBatchFormTrs[i]); - const taskID = \$currentTr.find('.form-batch-control[data-name=id]').find('input[name^=id]').val(); - const storyID = \$currentTr.find('.form-batch-control[data-name=story]').find('input[name^=story]').val(); - - if(tasks[taskID].story == storyID) continue; - if(!storyID && tasks[taskID].parent <= 0) continue; - if(tasks[taskID].parent > 0) - { - if(storyID) confirmID = confirmID.replace('ID' + taskID + ', ', ''); - continue; - } - if(typeof childTasks[taskID] != 'object' || typeof nonStoryChildTasks[taskID] != 'object') continue; - - const nonStoryChildTaskIdList = Object.keys(nonStoryChildTasks[taskID]); - if(nonStoryChildTaskIdList.length == 0) continue; - - if(tipAll) tipAll = Object.keys(childTasks[taskID]).length == nonStoryChildTaskIdList.length; - - for(let j = 0; j < nonStoryChildTaskIdList.length; j++) confirmID += 'ID' + nonStoryChildTaskIdList[j].toString() + ', '; - } - if(confirmID.length == 0) return true; - - if(confirmID.endsWith(', ')) confirmID = confirmID.slice(0, -2); - - let confirmTip = tipAll ? '{$lang->task->syncStoryToAllChildrenTip}' : '{$lang->task->syncStoryToChildrenTip}'; - confirmTip = confirmTip.replace('%s', confirmID); - zui.Modal.confirm(confirmTip).then((res) => - { - \$taskBatchForm.find('[name=syncChildren]').remove(); - \$taskBatchForm.append(''); - - const formData = new FormData(\$taskBatchForm[0]); - const confirmURL = \$taskBatchForm.attr('action'); - $.ajaxSubmit({url: confirmURL, data: formData}); - }); - return false; - }"); -} +jsVar('executionID', $executionID); +jsVar('childTasks', $childTasks); +jsVar('nonStoryChildTasks', $nonStoryChildTasks); +jsVar('tasks', $tasks); +jsVar('syncStoryToAllChildrenTip', $lang->task->syncStoryToAllChildrenTip); +jsVar('syncStoryToChildrenTip', $lang->task->syncStoryToChildrenTip); /* ====== Define the page structure with zin widgets ====== */ formBatchPanel @@ -83,7 +32,7 @@ formBatchPanel set::data(array_values($tasks)), set::onRenderRow(jsRaw('renderRowData')), set::customFields(array('list' => $customFields, 'show' => explode(',', $showFields), 'key' => 'batchEditFields')), - !empty($nonStoryChildTasks) ? set::ajax(array('beforeSubmit' => $beforeSubmit)) : null, + set::ajax(array('beforeSubmit' => jsRaw('clickSubmit'))), set::formID('taskBatchEditForm' . $executionID), formBatchItem (