diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 81acac2b..ccbb7eb7 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -71,7 +71,7 @@ todo: attachments - form key for hiding / showing customization todo: attachment - rename a file or add notes after already uploaded https://medium.com/js-dojo/upload-files-to-cloudinary-using-vue-vuetify-dd45472c4fd6 - +1578595824571 todo: ATTACHMENTS - TODO: PLANNING - should attachments be actually attached in the db to their object? like Wiki was changed to do? - is this even possible? diff --git a/ayanova/src/api/gzapi.js b/ayanova/src/api/gzapi.js index 06ac6891..47d13fe0 100644 --- a/ayanova/src/api/gzapi.js +++ b/ayanova/src/api/gzapi.js @@ -392,6 +392,47 @@ export default { handleError("DUPLICATE", error, route, reject); }); }); + }, + /////////////////////////////////// + // POST FILE ATTACHMENTS + // @param {ayId:objectid, ayType:objectType, files:[array of files]} + // + uploadAttachment(at) { + let that = this; + + var files = at.files; + var data = new FormData(); + for (var i = 0; i < files.length; i++) { + data.append(files[i].name, files[i]); + } + + data.append("AttachToObjectType", at.ayaType); + data.append("AttachToObjectId", at.ayaId); + + //----------------- + + return new Promise(function postAttachmentToServer(resolve, reject) { + let fetchOptions = { + method: "post", + mode: "cors", + headers: { + Authorization: "Bearer " + window.$gz.store.state.apiToken + }, + body: data + }; + + fetch(that.APIUrl("Attachment"), fetchOptions) + .then(that.status) + .then(that.json) + // eslint-disable-next-line + .then((response) => { + resolve(response); + }) + .catch(function handlePostAttachment(error) { + handleError("POSTATTACHMENT", error, route, reject); + }); + }); + //--------------- } //new functions above here diff --git a/ayanova/src/components/attachment-control.vue b/ayanova/src/components/attachment-control.vue index 6c7718b6..6e3ce669 100644 --- a/ayanova/src/components/attachment-control.vue +++ b/ayanova/src/components/attachment-control.vue @@ -69,7 +69,57 @@ export default { data() { return { height: 300, - items: [ + items: [], + notes: null, + tab: null, + uploadFiles: [] + }; + }, + props: { + ayaType: Number, + ayaId: Number, + readonly: Boolean + }, + + methods: { + onResize() { + this.height = window.innerHeight * 0.8; + }, + cardTextStyle() { + return "height: " + this.height + "px;overflow-y:auto;"; + }, + upload() { + let at = { + ayaId: this.ayaId, + ayaType: this.ayaType, + files: this.uploadFiles + }; + window.$gz.api.uploadAttachment(at).then(res => { + //vm.formState.loading = false; + if (res.error) { + console.log(res.error); + // vm.formState.serverError = res.error; + // window.$gz.form.setErrorBoxErrors(vm); + } else { + console.log("SUCCESS"); + } + }); + // .catch(function handleSubmitError(error) { + // vm.formState.loading = false; + // window.$gz.errorHandler.handleFormError(error, vm); + // }); + // if (this.uploadFiles.length > 0) { + // this.uploadFiles.forEach(file => { + // window.console.log(file); + // }); + // } + }, + aClick() { + console.log("CLICK"); + } + } + + /**[ { icon: "fa-file-image", title: "drawings.pdf", @@ -130,35 +180,6 @@ export default { // title: "4Work", // subtitle: "Jan 28, 2014" // } - ], - notes: null, - tab: null, - uploadFiles: [] - }; - }, - props: { - ayaType: Number, - ayaId: Number, - readonly: Boolean - }, - - methods: { - onResize() { - this.height = window.innerHeight * 0.8; - }, - cardTextStyle() { - return "height: " + this.height + "px;overflow-y:auto;"; - }, - upload() { - if (this.uploadFiles.length > 0) { - this.uploadFiles.forEach(file => { - window.console.log(file); - }); - } - }, - aClick() { - console.log("CLICK"); - } - } + ], */ };