1 import draggable from "vuedraggable";
2 import dropzone from "./components/dropzone";
5 this.pageId = this.$el.getAttribute('page-id');
6 this.file = this.newFile();
8 this.$http.get(window.baseUrl(`/attachments/get/page/${this.pageId}`)).then(resp => {
9 this.files = resp.data;
11 this.checkValidationErrors('get', err);
22 errors: {link: {}, edit: {}, delete: {}}
25 const components = {dropzone, draggable};
30 return {page_id: this.pageId};
34 if (file.external && file.path.indexOf('http') !== 0) {
37 return window.baseUrl(`/attachments/${file.id}`);
41 this.$http.put(window.baseUrl(`/attachments/sort/page/${this.pageId}`), {files: this.files}).then(resp => {
42 this.$events.emit('success', resp.data.message);
44 this.checkValidationErrors('sort', err);
49 this.fileToEdit = Object.assign({}, file);
50 this.fileToEdit.link = file.external ? file.path : '';
51 this.editTab = file.external ? 'link' : 'file';
56 return this.$set(file, 'deleting', true);
59 this.$http.delete(window.baseUrl(`/attachments/${file.id}`)).then(resp => {
60 this.$events.emit('success', resp.data.message);
61 this.files.splice(this.files.indexOf(file), 1);
63 this.checkValidationErrors('delete', err)
67 uploadSuccess(upload) {
68 this.files.push(upload.data);
69 this.$events.emit('success', trans('entities.attachments_file_uploaded'));
72 uploadSuccessUpdate(upload) {
73 let fileIndex = this.filesIndex(upload.data);
74 if (fileIndex === -1) {
75 this.files.push(upload.data)
77 this.files.splice(fileIndex, 1, upload.data);
80 if (this.fileToEdit && this.fileToEdit.id === upload.data.id) {
81 this.fileToEdit = Object.assign({}, upload.data);
83 this.$events.emit('success', trans('entities.attachments_file_updated'));
86 checkValidationErrors(groupName, err) {
87 if (typeof err.response.data === "undefined" && typeof err.response.data === "undefined") return;
88 this.errors[groupName] = err.response.data;
92 let url = window.baseUrl(`/attachments/upload`);
93 if (typeof file !== 'undefined') url += `/${file.id}`;
98 this.fileToEdit = null;
101 attachNewLink(file) {
102 file.uploaded_to = this.pageId;
103 this.errors.link = {};
104 this.$http.post(window.baseUrl('/attachments/link'), file).then(resp => {
105 this.files.push(resp.data);
106 this.file = this.newFile();
107 this.$events.emit('success', trans('entities.attachments_link_attached'));
109 this.checkValidationErrors('link', err);
114 $http.put(window.baseUrl(`/attachments/${file.id}`), file).then(resp => {
115 let search = this.filesIndex(resp.data);
117 this.files.push(resp.data);
119 this.files.splice(search, 1, resp.data);
122 if (this.fileToEdit && !file.external) this.fileToEdit.link = '';
123 this.fileToEdit = false;
125 this.$events.emit('success', trans('entities.attachments_updated_success'));
127 this.checkValidationErrors('edit', err);
132 for (let i = 0, len = this.files.length; i < len; i++) {
133 if (this.files[i].id === file.id) return i;
141 data, methods, mounted, components,