- Add error msg to user on folder delete
https://supportweb.ldc.fr/ticket/267
This commit is contained in:
parent
be59d3c408
commit
dcee8db29f
5 changed files with 30 additions and 11 deletions
|
|
@ -56,9 +56,14 @@ class FoldersController extends Controller
|
|||
public function delete(Request $request) {
|
||||
$folder = Directories::find($request->id);
|
||||
if($folder) {
|
||||
$count = $folder->documents->count();
|
||||
if ($count > 0)
|
||||
{
|
||||
return ['status' => 'KO', 'error' => sprintf("Il y a %d document(s) lié(s).", $count)];
|
||||
}
|
||||
$folder->delete();
|
||||
}
|
||||
return Directories::all();
|
||||
return ['status' => 'OK', 'directories' => Directories::all()];
|
||||
}
|
||||
|
||||
private function orderFolders($folders){
|
||||
|
|
|
|||
|
|
@ -18,4 +18,9 @@ class Directories extends Model
|
|||
}
|
||||
return array_reverse($parents);
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->hasMany(Documents::class, 'directory', 'id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,9 @@ class Documents extends Model
|
|||
}
|
||||
return array_reverse($parents);
|
||||
}
|
||||
|
||||
public function directory()
|
||||
{
|
||||
return $this->belongsTo(Directories::class, 'id', 'directory');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
public/js/app.js
vendored
2
public/js/app.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -227,17 +227,21 @@
|
|||
},
|
||||
deleteFolder() {
|
||||
this.done = false;
|
||||
let _this2 = this;
|
||||
axios.post('/delete-folder', {id: this.folderId})
|
||||
.then(function (response) {
|
||||
let parseDirectories = response.data;
|
||||
_this2.directories = _this2.recursiveDir(parseDirectories);
|
||||
if(_this2.test){
|
||||
_this2.nestableItems = _this2.test
|
||||
.then(response => {
|
||||
if (response.data.status === 'OK'){
|
||||
let parseDirectories = response.data.directories;
|
||||
this.directories = this.recursiveDir(parseDirectories);
|
||||
if(this.test){
|
||||
this.nestableItems = this.test
|
||||
}
|
||||
this.folderId = '';
|
||||
$('#DeleteModal').modal('hide');
|
||||
this.showAlert("Dossier supprimé !");
|
||||
}else{
|
||||
$('#DeleteModal').modal('hide');
|
||||
this.showAlertError(response.data.error);
|
||||
}
|
||||
_this2.folderId = '';
|
||||
$('#DeleteModal').modal('hide');
|
||||
_this2.showAlert("Dossier supprimé !");
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue