Sending parent id from vuejs to laravel to enable renaming child folders

parent f2a33802
...@@ -73,10 +73,13 @@ ...@@ -73,10 +73,13 @@
v-if="singleModal"> v-if="singleModal">
{{ trans('media.insert') }} {{ trans('media.insert') }}
</a> </a>
<a class="btn btn-default btn-flat" :href="getEditMediaUrl(scope)" <a class="btn btn-default btn-flat" @click.prevent="loadEditForm(scope)"
v-if="! singleModal && ! scope.row.is_folder"><i class="fa fa-pencil"></i></a> v-if="! singleModal && ! scope.row.is_folder"><i class="fa fa-pencil"></i></a>
<rename-folder :current-folder="scope.row" v-if="! singleModal && scope.row.is_folder">
</rename-folder> <a @click.prevent="showEditFolder(scope.row)" class="btn btn-default btn-flat"
v-if="! singleModal && scope.row.is_folder">
<i class="fa fa-pencil"></i>
</a>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
...@@ -95,6 +98,7 @@ ...@@ -95,6 +98,7 @@
</div> </div>
</div> </div>
</div> </div>
<rename-folder></rename-folder>
</div> </div>
</template> </template>
...@@ -195,6 +199,12 @@ ...@@ -195,6 +199,12 @@
getEditMediaUrl(scope) { getEditMediaUrl(scope) {
return route('admin.media.media.edit', {media: scope.row.id}); return route('admin.media.media.edit', {media: scope.row.id});
}, },
loadEditForm(scope) {
this.$events.emit('editMediaWasClicked', scope.row);
},
showEditFolder(scope) {
this.$events.emit('editFolderWasClicked', scope);
},
changeRoot(folderId, index) { changeRoot(folderId, index) {
this.tableIsLoading = true; this.tableIsLoading = true;
this.queryServer({folder_id: folderId}); this.queryServer({folder_id: folderId});
......
<template> <template>
<div> <div>
<a @click.prevent="dialogFormVisible = true" class="btn btn-default btn-flat">
<i class="fa fa-pencil"></i>
</a>
<el-dialog title="Rename Folder" :visible.sync="dialogFormVisible" size="tiny"> <el-dialog title="Rename Folder" :visible.sync="dialogFormVisible" size="tiny">
<el-form :model="folder" v-loading.body="loading" @submit.native.prevent="onSubmit()"> <el-form :model="folder" v-loading.body="loading" @submit.native.prevent="onSubmit()">
<el-form-item label="Folder name" :class="{'el-form-item is-error': form.errors.has('name') }"> <el-form-item label="Folder name" :class="{'el-form-item is-error': form.errors.has('name') }">
...@@ -24,15 +20,16 @@ ...@@ -24,15 +20,16 @@
import Form from 'form-backend-validation' import Form from 'form-backend-validation'
export default { export default {
props: { // props: {
currentFolder: {type: Object} // currentFolder: {type: Object}
}, // },
data() { data() {
return { return {
dialogFormVisible: false, dialogFormVisible: false,
folder: { folder: {
name: '', name: '',
id: '', id: '',
parent_id: '',
}, },
form: new Form(), form: new Form(),
loading: false, loading: false,
...@@ -67,8 +64,12 @@ ...@@ -67,8 +64,12 @@
}, },
}, },
mounted() { mounted() {
this.folder.name = this.currentFolder.filename; this.$events.listen('editFolderWasClicked', eventData => {
this.folder.id = this.currentFolder.id; this.folder.name = eventData.filename;
this.folder.id = eventData.id;
this.folder.parent_id = eventData.folder_id;
this.dialogFormVisible = true;
});
} }
} }
</script> </script>
...@@ -47,6 +47,7 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR ...@@ -47,6 +47,7 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
$formattedData = [ $formattedData = [
'filename' => array_get($data, 'name'), 'filename' => array_get($data, 'name'),
'path' => $this->getPath($data), 'path' => $this->getPath($data),
'parent_id' => array_get($data, 'parent_id'),
]; ];
event($event = new FolderIsUpdating($formattedData)); event($event = new FolderIsUpdating($formattedData));
......
...@@ -31,6 +31,7 @@ class MediaTransformer extends Resource ...@@ -31,6 +31,7 @@ class MediaTransformer extends Resource
'media_type' => $this->media_type, 'media_type' => $this->media_type,
'fa_icon' => FileHelper::getFaIcon($this->media_type), 'fa_icon' => FileHelper::getFaIcon($this->media_type),
'created_at' => $this->created_at, 'created_at' => $this->created_at,
'folder_id' => $this->folder_id,
'small_thumb' => $this->imagy->getThumbnail($this->path, 'smallThumb'), 'small_thumb' => $this->imagy->getThumbnail($this->path, 'smallThumb'),
'medium_thumb' => $this->imagy->getThumbnail($this->path, 'mediumThumb'), 'medium_thumb' => $this->imagy->getThumbnail($this->path, 'mediumThumb'),
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment