- Add delete document
This commit is contained in:
parent
dcee8db29f
commit
4802ecdf91
4 changed files with 67 additions and 2 deletions
|
|
@ -129,4 +129,19 @@ class DocumentsController extends Controller
|
|||
$pathToFile = public_path() . Storage::url('docs/' . $doc->uuid . '.' . $doc->type);
|
||||
return response()->download($pathToFile, $doc->path);
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$doc = Documents::findOrFail($request->id);
|
||||
|
||||
if ($doc->lang === 'fr') {
|
||||
foreach ($doc->others_lang as $item) {
|
||||
$item->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$doc->delete();
|
||||
|
||||
return ['status' => 'OK'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
public/js/app.js
vendored
2
public/js/app.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -2,6 +2,7 @@
|
|||
<form>
|
||||
<div v-show="error.length > 0" class="alert alert-danger" role="alert">{{this.error}}</div>
|
||||
<div v-show="success.length > 0" class="alert alert-success" role="alert">{{this.success}}</div>
|
||||
<div v-show="alertErrorVisible" class="alert alert-danger" role="alert">{{alertMsg}}</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="title" placeholder="Titre du document" class="form-control"
|
||||
v-model="documentDatas.title" required>
|
||||
|
|
@ -35,10 +36,31 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12 d-flex justify-content-between">
|
||||
<a href="/documents" class="btn btn-secondary">Retour</a>
|
||||
<a href="#" class="btn btn-danger" :disabled="isUploading" @click="confirm">Supprimer</a>
|
||||
<a href="#" class="btn btn-success" :disabled="isUploading" @click="updateDocument">Enregistrer</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal Delete -->
|
||||
<div class="modal fade" id="DeleteModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="DeleteModalLabel">Attention !</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Cette action supprimera ce document ainsi que les traductions si il s'agit d'un document FR <br>Voulez vous continuer ?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Non</button>
|
||||
<button type="button" class="btn btn-success" @click="deleteDocument">Oui</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
|
|
@ -86,7 +108,9 @@
|
|||
directories: [],
|
||||
documentDatas: {lang: ''},
|
||||
filePercent: -1,
|
||||
isUploading: false
|
||||
isUploading: false,
|
||||
alertMsg: '',
|
||||
alertErrorVisible: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -144,6 +168,31 @@
|
|||
}
|
||||
return root
|
||||
},
|
||||
confirm() {
|
||||
$('#DeleteModal').modal('show');
|
||||
},
|
||||
deleteDocument() {
|
||||
axios.post('/documents/' + this.documentDatas.id + '/delete')
|
||||
.then(response => {
|
||||
if (response.data.status === 'OK'){
|
||||
window.location.href = '/documents';
|
||||
}else{
|
||||
$('#DeleteModal').modal('hide');
|
||||
this.showAlertError("Une erreur est survenue. Veuillez réessayer plus tard.");
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
$('#DeleteModal').modal('hide');
|
||||
this.showAlertError("Une erreur est survenue. Veuillez réessayer plus tard.");
|
||||
});
|
||||
},
|
||||
showAlertError(msg) {
|
||||
this.alertMsg = msg;
|
||||
this.alertErrorVisible = true;
|
||||
setTimeout(() => {
|
||||
this.alertErrorVisible = false;
|
||||
}, 1800);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ Route::post('/documents/store', 'DocumentsController@store');
|
|||
Route::get('/documents/{id}/edit', 'DocumentsController@edit');
|
||||
Route::post('/documents/{id}/update', 'DocumentsController@update');
|
||||
Route::post('/documents/upload', 'DocumentsController@upload');
|
||||
Route::post('/documents/{id}/delete', 'DocumentsController@delete');
|
||||
/* USERS */
|
||||
Route::get('/users', 'UsersController@index');
|
||||
Route::get('/users/add', 'UsersController@add');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue