save cell from modal
This commit is contained in:
parent
d9b058a1a7
commit
c89e292b64
4 changed files with 99 additions and 3 deletions
|
|
@ -117,4 +117,15 @@ class ScheduleController extends Controller
|
|||
|
||||
return view('schedule.index', compact('users', 'date', 'weekCells', 'arSchedules'));
|
||||
}
|
||||
|
||||
public function setCellContent(Request $request)
|
||||
{
|
||||
$date = CarbonImmutable::createFromFormat('d/m/Y', $request->date);
|
||||
$fill = $request->all();
|
||||
$fill['date'] = $date;
|
||||
|
||||
$schd = Schedule::updateOrCreate(['id' => $request->id],$fill);
|
||||
$schd->saveOrFail();
|
||||
return \response()->json(['status' => true, 'sched'=>$schd]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,6 +184,7 @@ export default {
|
|||
models: [],
|
||||
error: '',
|
||||
modale:{
|
||||
id: null,
|
||||
userid: 0,
|
||||
slot: 0,
|
||||
day: '01/01/1900',
|
||||
|
|
@ -350,6 +351,7 @@ export default {
|
|||
value: '',
|
||||
};
|
||||
let currentModale = {
|
||||
id: this.schedules[userid][slotkey][day]['id'],
|
||||
userid: userid,
|
||||
slot: slotkey,
|
||||
day: day,
|
||||
|
|
@ -428,6 +430,71 @@ export default {
|
|||
})
|
||||
});
|
||||
},
|
||||
saveCell() {
|
||||
this.error = false
|
||||
const data = {
|
||||
'id': this.modale.id,
|
||||
'user_id': this.modale.userid,
|
||||
'date': this.modale.day,
|
||||
'activity': this.$refs.type.value,
|
||||
'slot': this.modale.slot,
|
||||
'model_lie': this.$refs.morph.value,
|
||||
'id_lie': this.value.value,
|
||||
'description': this.$refs.text.value,
|
||||
}
|
||||
this.saveCellOnServer(data)
|
||||
},
|
||||
saveCellOnServer(data) {
|
||||
this.error = false
|
||||
axios.post(this.route('schedule.setCellContent'), data)
|
||||
.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');
|
||||
let cellData = {
|
||||
"type": {
|
||||
"label": "",
|
||||
"value": sched.activity
|
||||
},
|
||||
"text": sched.description,
|
||||
"id_lie": {
|
||||
"label": "",
|
||||
"value": sched.id_lie
|
||||
},
|
||||
"model_lie": {
|
||||
"label": "",
|
||||
"value": sched.model_lie
|
||||
},
|
||||
"id": sched.id
|
||||
};
|
||||
this.$set(this.schedules[sched.user_id][sched.slot], sched.date, cellData);
|
||||
this.$refs.close.click()
|
||||
} else {
|
||||
this.error = 'Réponse inconnue';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
if(error.response.status === 429) {
|
||||
location.reload()
|
||||
}
|
||||
if(error.response.status === 422) {
|
||||
if(error.response.data.errors) {
|
||||
this.error = ''
|
||||
for(let id in error.response.data.errors) {
|
||||
let field = error.response.data.errors[id]
|
||||
this.error += field.join('\n') + '\n'
|
||||
}
|
||||
return
|
||||
} else if(error.response.data.message) {
|
||||
this.error = error.response.data.message
|
||||
return
|
||||
}
|
||||
}
|
||||
this.error = error
|
||||
})
|
||||
},
|
||||
selectChange() {
|
||||
this.value = {
|
||||
label: null,
|
||||
|
|
@ -445,6 +512,24 @@ export default {
|
|||
},
|
||||
eraseCell(id) {
|
||||
|
||||
},
|
||||
limitLines(e) {
|
||||
let keynum, lines = this.$refs.text.value.split('\n').length;
|
||||
// IE
|
||||
if(window.event) {
|
||||
keynum = e.keyCode;
|
||||
// Netscape/Firefox/Opera
|
||||
} else if(e.which) {
|
||||
keynum = e.which;
|
||||
}
|
||||
if(keynum != 8 && this.$refs.text.value.length >= this.textLimit) {
|
||||
e.preventDefault()
|
||||
return false;
|
||||
}
|
||||
if(keynum == 13 && lines == this.$refs.text.rows) {
|
||||
e.preventDefault()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,14 +32,13 @@
|
|||
<script>
|
||||
window._routes = {
|
||||
"schedule.index": "{{ route('schedule.index') }}",
|
||||
|
||||
"ticket.show": "{{ route('ticket.show', 'TICKET') }}",
|
||||
"projects.show": "{{ route('projects.show', 'PROJECT') }}",
|
||||
"sites.show": "{{ route('sites.show', 'SITE') }}",
|
||||
"ticket.index": "{{ route('ticket.index') }}",
|
||||
"projects.index": "{{ route('projects.index') }}",
|
||||
"sites.index": "{{ route('sites.index') }}",
|
||||
"planning.setCellContent": "{{ route('planning.setCellContent') }}",
|
||||
"schedule.setCellContent": "{{ route('schedule.setCellContent') }}",
|
||||
"planning.eraseCellContent": "{{ route('planning.eraseCellContent') }}"
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ Route::middleware(['auth'])->group(function () {
|
|||
|
||||
Route::prefix('/schedule')->name('schedule.')->group(function () {
|
||||
Route::get('/', [ScheduleController::class, 'index'])->name('index');
|
||||
Route::get('/import', [ScheduleController::class, 'import'])->name('import');
|
||||
Route::post('/setCellContent', [ScheduleController::class, 'setCellContent'])
|
||||
->name('setCellContent');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue