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', [
'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;
+ }
}
}
*/
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;
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);
message: 'Ошибка соединения',
};
}).then(function (json) {
-
Array.from(document.querySelectorAll('form .help-block')).map(function (element) {
element.innerHTML = '';
})
error = json.message;
}
bottomMessageBar.className = 'alert alert-danger';
- bottomMessageBar.innerHTML = `Не получилось открыть смену: ${error}`;
+ bottomMessageBar.innerHTML = `Не получилось открыть смену: ${json.errors}`;
bottomMessageBar.hidden = false;
}
});