show proper data upon returning from save

This commit is contained in:
Olivier Legat 2021-12-18 20:19:57 +01:00
parent c89e292b64
commit 75db2ac0af
2 changed files with 32 additions and 17 deletions

View file

@ -124,8 +124,32 @@ class ScheduleController extends Controller
$fill = $request->all();
$fill['date'] = $date;
$schd = Schedule::updateOrCreate(['id' => $request->id],$fill);
$schd->saveOrFail();
return \response()->json(['status' => true, 'sched'=>$schd]);
$schedule = Schedule::updateOrCreate(['id' => $request->id],$fill);
$schedule->saveOrFail();
$id_lie = array('label'=> null, 'value'=> null);
if(!is_null($schedule->model_lie)) {
if (isset($schedule->relatedModel->name)) {
$id_lie = array('label'=>$schedule->relatedModel->name, 'value'=>$schedule->id_lie);
} else {
$id_lie = array('label'=>'Ticket '.$schedule->id_lie, 'value'=>$schedule->id_lie);
}
$model_lie = $schedule->model_lie;
} else {
$model_lie = array('label'=> null, 'value'=> null);
}
$arSchd = [
'id' => $schedule->id,
'user_id' => $schedule->user_id,
'date' => $schedule->date->format('d/m/Y'),
'activity' => $schedule->activity,
'description' => $schedule->description,
'id_lie' => $id_lie,
'model_lie' => $model_lie,
'slot' => $schedule->slot,
];
return \response()->json(['status' => true, 'sched'=>$arSchd]);
}
}

View file

@ -450,22 +450,13 @@ export default {
.then(response => {
if(response.data.status) {
let sched = response.data.sched;
sched.date = Date.parse(sched.date)
sched.date = this.moment(sched.date).format('DD/MM/YYYY');
// sched.date = Date.parse(sched.date)
// sched.date = this.moment(sched.date).format('DD/MM/YYYY');
let cellData = {
"type": {
"label": "",
"value": sched.activity
},
"type": sched.activity,
"text": sched.description,
"id_lie": {
"label": "",
"value": sched.id_lie
},
"model_lie": {
"label": "",
"value": sched.model_lie
},
"id_lie": sched.id_lie,
"model_lie": sched.model_lie,
"id": sched.id
};
this.$set(this.schedules[sched.user_id][sched.slot], sched.date, cellData);