diff --git a/app/Http/Controllers/FoldersController.php b/app/Http/Controllers/FoldersController.php index aae26a0..2294826 100644 --- a/app/Http/Controllers/FoldersController.php +++ b/app/Http/Controllers/FoldersController.php @@ -65,12 +65,13 @@ class FoldersController extends Controller $directory = Directories::where('id', $folder['id'])->first(); $directory->order = $folder['order']; $directory->parent = null; + $directory->needAuthorization = 0; $directory->save(); if(isset($folder['children']) && count($folder['children']) > 0 ){ $this->recordOrder($folder['children'], $folder['id']); } } - return 'OK'; + return ['status' => 'OK', 'directories' => Directories::all()]; } private function recordOrder($folders, $parentId) { diff --git a/resources/js/components/FoldersComponent.vue b/resources/js/components/FoldersComponent.vue index 673e2ab..ab29cd0 100644 --- a/resources/js/components/FoldersComponent.vue +++ b/resources/js/components/FoldersComponent.vue @@ -16,15 +16,15 @@ - - - - {{ item.name.fr }} + + + + {{ item.name.fr }} - Autorisation : - - + Autorisation : + + @@ -93,7 +93,11 @@ get: function() { let allDirectories = this.directories.sort((a, b) =>(a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0)); allDirectories.forEach(child => { - child.name = JSON.parse(child.name); + + if (typeof child.name === 'string') { + child.name = JSON.parse(child.name); + } + if(child.children && child.children.length){ child.children = this.orderChildren(child); } else { @@ -137,15 +141,14 @@ }, methods: { toggleAuthorization(item) { - let _this2 = this; axios.post('/folders/toggle-authorization', {id: item.id}) - .then(function (response) { + .then(response => { let parseDirectories = response.data; - _this2.directories = _this2.recursiveDir(parseDirectories); - if(_this2.test){ - _this2.nestableItems = _this2.test + this.directories = this.recursiveDir(parseDirectories); + if(this.test){ + this.nestableItems = this.test } - _this2.showAlert("Sauvegardé !"); + this.showAlert("Sauvegardé !"); }) .catch(function (error) { console.log(error); @@ -182,16 +185,15 @@ }, registerNewName() { this.done = false; - let _this2 = this; axios.post('/save-folder-name', {id: this.folderId, name: JSON.stringify({fr: this.folderNameFR, en: this.folderNameEN, de: this.folderNameDE})}) - .then(function (response) { + .then(response => { let parseDirectories = response.data; - _this2.directories = _this2.recursiveDir(parseDirectories); - if(_this2.test){ - _this2.nestableItems = _this2.test + this.directories = this.recursiveDir(parseDirectories); + if(this.test){ + this.nestableItems = this.test } $('#staticBackdrop').modal('hide'); - _this2.showAlert("Dossier renommé !"); + this.showAlert("Dossier renommé !"); }) .catch(function (error) { console.log(error); @@ -203,16 +205,15 @@ return; } this.done = false; - let _this2 = this; axios.post('/add-folder', {name: JSON.stringify({fr: this.newFolderFR}), order: this.nestableItems.length}) - .then(function (response) { + .then(response => { let parseDirectories = response.data; - _this2.directories = _this2.recursiveDir(parseDirectories); - if(_this2.test){ - _this2.nestableItems = _this2.test + this.directories = this.recursiveDir(parseDirectories); + if(this.test){ + this.nestableItems = this.test } - _this2.newFolderFR = ''; - _this2.showAlert("Dossier ajouté !"); + this.newFolderFR = ''; + this.showAlert("Dossier ajouté !"); }) .catch(function (error) { console.log(error); @@ -280,7 +281,9 @@ if (folder.children && folder.children.length) { folder.children = folder.children.sort((a, b) => (a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0)) folder.children.forEach(child => { - child.name = JSON.parse(child.name); + if (typeof child.name === 'string') { + child.name = JSON.parse(child.name); + } if (child.children && child.children.length) { child.children = this.orderChildren(child); } else { @@ -295,12 +298,16 @@ axios.post('/save-folder-order', { folders: list, }) - .then(function (response) { - console.log(response); - }) - .catch(function (error) { - console.log(error); - }); + .then(response => { + let parseDirectories = response.data.directories; + this.directories = this.recursiveDir(parseDirectories); + if(this.test){ + this.nestableItems = this.test + } + }) + .catch(function (error) { + console.log(error); + }); }, recursiveDir(list, parent = null) { let root = list.filter(e => e.parent == parent);