From 99d8ea337e294b628e24c071ab992db03919c9cd Mon Sep 17 00:00:00 2001 From: Burak Civan Date: Thu, 27 May 2021 19:35:19 +0300 Subject: [PATCH] Company function development --- resources/assets/js/mixins/spa-global.js | 73 ++++++++++++++++++-- resources/assets/js/views/wizard/Company.vue | 8 ++- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/resources/assets/js/mixins/spa-global.js b/resources/assets/js/mixins/spa-global.js index 487a0e2e8..a74369bb0 100644 --- a/resources/assets/js/mixins/spa-global.js +++ b/resources/assets/js/mixins/spa-global.js @@ -38,9 +38,11 @@ export default { this.model.select = item.code ? item.code : ''; } }, + handleClickCancel() { this.currentTab = undefined; }, + dataHandleEvent() { this.newDatas = false; this.currentTab = undefined; @@ -49,10 +51,11 @@ export default { this.model.select = ''; this.model.enabled = 1; }, + onSuccessEvent(response) { let type = response.data.success ? 'success' : 'error'; let timeout = 1000; - + if (response.data.important) { timeout = 0; } @@ -66,10 +69,11 @@ export default { this.dataHandleEvent(); }, + onSuccessDelete(event) { let type = event.success ? 'success' : 'error'; let timeout = 1000; - + if (event.important) { timeout = 0; } @@ -83,6 +87,7 @@ export default { this.dataHandleEvent(); }, + onEditEvent(form_method, form_url, plus_data, form_list, form_id) { const formData = new FormData(this.$refs["form"]); const data = {}; @@ -138,6 +143,7 @@ export default { this.onFailError(error) }, this); }, + onSubmitEvent(form_method, form_url, plus_data, form_list) { const formData = new FormData(this.$refs["form"]); const data = {}; @@ -175,6 +181,63 @@ export default { this.onFailError(error); }, this); }, + + onEditCompany() { + FormData.prototype.appendRecursive = function(data, wrapper = null) { + for(var name in data) { + if (name == "previewElement" || name == "previewTemplate") { + continue; + } + if (wrapper) { + if ((typeof data[name] == 'object' || Array.isArray(data[name])) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) { + this.appendRecursive(data[name], wrapper + '[' + name + ']'); + } else { + this.append(wrapper + '[' + name + ']', data[name]); + } + } else { + if ((typeof data[name] == 'object' || Array.isArray(data[name])) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) { + this.appendRecursive(data[name], name); + } else { + this.append(name, data[name]); + } + } + } + } + + const formData = new FormData(this.$refs["form"]); + + let data_name = {}; + for (let [key, val] of formData.entries()) { + Object.assign(data_name, { + [key]: val, + ['logo']: this.$refs.dropzoneWizard.files[1], + ['_prefix']: 'company', + ['_token']: window.Laravel.csrfToken, + ['_method']: 'PATCH', + }); + } + + formData.appendRecursive(data_name); + + window.axios({ + method: 'PATCH', + url: url + "/wizard/companies", + data: formData, + headers: { + 'X-CSRF-TOKEN': window.Laravel.csrfToken, + 'X-Requested-With': 'XMLHttpRequest', + 'Content-Type': 'multipart/form-data' + } + }) + .then(response => { + this.onSuccessEvent(response); + + }, this) + .catch(error => { + this.onFailError(error) + }, this); + }, + onDeleteEvent(event, form_list, event_id) { form_list.forEach(function (item, index) { if (item.id == event_id) { @@ -182,16 +245,18 @@ export default { return; } }, this); - + this.component = ""; - + this.onSuccessDelete(event); }, + onFailErrorGet(field_name) { if(this.error_field[field_name]) { return this.error_field[field_name][0]; } }, + onFailError(error) { this.error_field = error.response.data.errors; } diff --git a/resources/assets/js/views/wizard/Company.vue b/resources/assets/js/views/wizard/Company.vue index f5f3c1dbe..1f744c37c 100644 --- a/resources/assets/js/views/wizard/Company.vue +++ b/resources/assets/js/views/wizard/Company.vue @@ -12,7 +12,7 @@ -
+
@@ -74,6 +74,7 @@ ref="dropzoneWizard" preview-classes="single" :attachments="logo" + :v-model="logo" >
@@ -83,8 +84,9 @@
{{ translations.company.save }} @@ -163,7 +165,7 @@ export default { }, onEditSave() { - this.onEditEvent("PATCH", url + "/wizard/companies", "logo", "", ""); + this.onEditCompany(); this.$router.push("/wizard/currencies"); }, },