From: marina Date: Mon, 23 Dec 2024 11:40:31 +0000 (+0300) Subject: фиксы X-Git-Tag: 1.7~114^2~4 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=3fdb13997a8808c521c9b3262c09bc8f1c43db5d;p=erp24_rep%2Fyii-erp24%2F.git фиксы --- diff --git a/erp24/actions/timetable/StartShiftStepTwoAction.php b/erp24/actions/timetable/StartShiftStepTwoAction.php index c944f35d..80246ad0 100755 --- a/erp24/actions/timetable/StartShiftStepTwoAction.php +++ b/erp24/actions/timetable/StartShiftStepTwoAction.php @@ -149,13 +149,13 @@ class StartShiftStepTwoAction extends Action TimetableFactModel::setValues($model, empty($fact)); - if ($this->controller->request->getHeaders()->get('Accept') == 'application/json') { - $this->controller->response->format = Response::FORMAT_JSON; - return [ - 'success' => !$model->hasErrors(), - 'errors' => $model->getErrors(), + if ($this->controller->request->isAjax) { + $response = [ + 'success' => true, 'model' => $model, ]; + Yii::$app->response->format = Response::FORMAT_JSON; + return $response; } return $this->controller->render('/timetable/start_shift_step_three.php', [ @@ -165,6 +165,18 @@ class StartShiftStepTwoAction extends Action 'device' => $device, 'planSlots' => $planSlots, ]); + } else { + if ($this->controller->request->isAjax) { + $errors = $model->errors; + if (!$twoMinutes) $errors['two_minutes'] = ['После открытия смены не прошло 2 минуты!']; + $response = [ + 'success' => false, + 'errors' => implode(', ', array_merge(...array_values($errors))), + 'model' => $model, + ]; + Yii::$app->response->format = Response::FORMAT_JSON; + return $response; + } } } diff --git a/erp24/forms/timetable/StartForm.php b/erp24/forms/timetable/StartForm.php index e9580dca..5ea15cce 100755 --- a/erp24/forms/timetable/StartForm.php +++ b/erp24/forms/timetable/StartForm.php @@ -252,7 +252,7 @@ class StartForm extends Model */ public function getPlanSlot() { - if (!$this->planSlotModel) { + if (!$this->planSlotModel && !empty($this->plan_id)) { $this->planSlotModel = TimetablePlan::find()->andWhere(['id' => $this->plan_id])->one(); } return $this->planSlotModel; diff --git a/erp24/web/js/timetable/start.js b/erp24/web/js/timetable/start.js index df047c06..904a9a6e 100755 --- a/erp24/web/js/timetable/start.js +++ b/erp24/web/js/timetable/start.js @@ -130,18 +130,9 @@ import TimetableSlot from "./Model/TimetableSlot"; form.append(window.settings.fieldNames.photo, photoBlob, 'selfie.jpg'); fetch('/timetable/start-shift-step-two', { method: 'POST', - headers: {'Accept': 'application/json'}, + headers: {'Accept': 'application/json', 'X-Requested-With': 'XMLHttpRequest'}, body: form }).then(function(response) { - if (!response.ok || response.headers.get('Content-Type').substr(0, 'application/json'.length) !== 'application/json') { - let headersArray = Array.from(response.headers); - let message = 'timetable/start-shift-step-two error ' + response.status + ' ' + response.statusText; - window.reportError(message, '', '','', {}, JSON.stringify({status: response.status, headers: headersArray})); - return { - success: false, - message: 'Ошибка на стороне сервера, обратитесь в техподдержку.', - } - } return response.json(); }, function (error) { window.reportError(error.message); @@ -150,7 +141,6 @@ import TimetableSlot from "./Model/TimetableSlot"; message: 'Ошибка соединения', }; }).then(function (json) { - Array.from(document.querySelectorAll('form .help-block')).map(function (element) { element.innerHTML = ''; }) @@ -195,7 +185,7 @@ import TimetableSlot from "./Model/TimetableSlot"; error = json.message; } bottomMessageBar.className = 'alert alert-danger'; - bottomMessageBar.innerHTML = `Не получилось открыть смену: ${error}`; + bottomMessageBar.innerHTML = `Не получилось открыть смену: ${json.errors}`; bottomMessageBar.hidden = false; } });