From 86c02ca46e2f14c0529c23826b75a85e0be6ea75 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Mon, 6 Nov 2023 14:28:35 +0800 Subject: [PATCH] * Fix error message can not pop up the problem. --- module/execution/control.php | 2 ++ module/execution/js/importbug.ui.js | 20 +++++++++++++++++++- module/execution/zen.php | 6 ++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/module/execution/control.php b/module/execution/control.php index 2f29c1acd0..6f37a5bd1f 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -340,6 +340,8 @@ class execution extends control { $postData = form::batchData($this->config->execution->form->importBug)->get(); $tasks = $this->executionZen->buildTasksForImportBug($execution, $postData); + if(dao::isError()) return $this->sendError(dao::getError()); + $this->execution->importBug($tasks); if(dao::isError()) return $this->sendError(dao::getError()); diff --git a/module/execution/js/importbug.ui.js b/module/execution/js/importbug.ui.js index 0a434efb1c..69dd111122 100644 --- a/module/execution/js/importbug.ui.js +++ b/module/execution/js/importbug.ui.js @@ -7,6 +7,24 @@ $(document).off('click', '.import-bug-btn').on('click', '.import-bug-btn', funct const formData = new FormData($("#importForm")[0]); checkedList.forEach((id) => formData.append(`id[${id}]`, id)); - $.ajaxSubmit({url: $('#importForm').attr('action'), data: formData}); + $.ajaxSubmit({url: $('#importForm').attr('action'), data: formData, onFail: printError}); + return false; }); + +/** + * Print error message. + * + * @param error $error + * @access public + * @return void + */ +function printError(result) +{ + Object.entries(result.message).forEach(([name, msg]) => { + if (Array.isArray(msg)) { + msg = msg.join(''); + } + zui.Modal.alert(msg); + }) +} diff --git a/module/execution/zen.php b/module/execution/zen.php index f50c09cae6..2dae0d8083 100644 --- a/module/execution/zen.php +++ b/module/execution/zen.php @@ -708,8 +708,6 @@ class executionZen extends execution $task->openedBy = $this->app->user->account; if($task->estimate !== '') $task->left = $task->estimate; - if(strpos($requiredFields, 'estStarted') !== false && helper::isZeroDate($task->estStarted)) $task->estStarted = ''; - if(strpos($requiredFields, 'deadline') !== false && helper::isZeroDate($task->deadline)) $task->deadline = ''; if(!empty($task->assignedTo)) $task->assignedDate = $now; /* Check task required fields. */ @@ -721,13 +719,13 @@ class executionZen extends execution if($field == 'estimate' and strlen(trim($task->estimate)) != 0) continue; - dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->task->$field); + dao::$errors["{$field}[{$bugID}]"] = 'ID: ' . $bugID . sprintf($this->lang->error->notempty, $this->lang->task->$field); return false; } if(!preg_match("/^[0-9]+(.[0-9]{1,3})?$/", (string)$task->estimate) and !empty($task->estimate)) { - dao::$errors['message'][] = $this->lang->task->error->estimateNumber; + dao::$errors["{$field}[{$bugID}]"] = 'ID: ' . $bugID . $this->lang->task->error->estimateNumber; return false; }