Company function development

This commit is contained in:
Burak Civan 2021-05-27 19:35:19 +03:00
parent 31e8d54709
commit 99d8ea337e
2 changed files with 74 additions and 7 deletions

View File

@ -38,9 +38,11 @@ export default {
this.model.select = item.code ? item.code : ''; this.model.select = item.code ? item.code : '';
} }
}, },
handleClickCancel() { handleClickCancel() {
this.currentTab = undefined; this.currentTab = undefined;
}, },
dataHandleEvent() { dataHandleEvent() {
this.newDatas = false; this.newDatas = false;
this.currentTab = undefined; this.currentTab = undefined;
@ -49,10 +51,11 @@ export default {
this.model.select = ''; this.model.select = '';
this.model.enabled = 1; this.model.enabled = 1;
}, },
onSuccessEvent(response) { onSuccessEvent(response) {
let type = response.data.success ? 'success' : 'error'; let type = response.data.success ? 'success' : 'error';
let timeout = 1000; let timeout = 1000;
if (response.data.important) { if (response.data.important) {
timeout = 0; timeout = 0;
} }
@ -66,10 +69,11 @@ export default {
this.dataHandleEvent(); this.dataHandleEvent();
}, },
onSuccessDelete(event) { onSuccessDelete(event) {
let type = event.success ? 'success' : 'error'; let type = event.success ? 'success' : 'error';
let timeout = 1000; let timeout = 1000;
if (event.important) { if (event.important) {
timeout = 0; timeout = 0;
} }
@ -83,6 +87,7 @@ export default {
this.dataHandleEvent(); this.dataHandleEvent();
}, },
onEditEvent(form_method, form_url, plus_data, form_list, form_id) { onEditEvent(form_method, form_url, plus_data, form_list, form_id) {
const formData = new FormData(this.$refs["form"]); const formData = new FormData(this.$refs["form"]);
const data = {}; const data = {};
@ -138,6 +143,7 @@ export default {
this.onFailError(error) this.onFailError(error)
}, this); }, this);
}, },
onSubmitEvent(form_method, form_url, plus_data, form_list) { onSubmitEvent(form_method, form_url, plus_data, form_list) {
const formData = new FormData(this.$refs["form"]); const formData = new FormData(this.$refs["form"]);
const data = {}; const data = {};
@ -175,6 +181,63 @@ export default {
this.onFailError(error); this.onFailError(error);
}, this); }, 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) { onDeleteEvent(event, form_list, event_id) {
form_list.forEach(function (item, index) { form_list.forEach(function (item, index) {
if (item.id == event_id) { if (item.id == event_id) {
@ -182,16 +245,18 @@ export default {
return; return;
} }
}, this); }, this);
this.component = ""; this.component = "";
this.onSuccessDelete(event); this.onSuccessDelete(event);
}, },
onFailErrorGet(field_name) { onFailErrorGet(field_name) {
if(this.error_field[field_name]) { if(this.error_field[field_name]) {
return this.error_field[field_name][0]; return this.error_field[field_name][0];
} }
}, },
onFailError(error) { onFailError(error) {
this.error_field = error.response.data.errors; this.error_field = error.response.data.errors;
} }

View File

@ -12,7 +12,7 @@
<el-step :title="translations.finish.title"></el-step> <el-step :title="translations.finish.title"></el-step>
</el-steps> </el-steps>
</div> </div>
<form ref="form" class="w-100"> <form id="company-name" ref="form" class="w-100" method="PATCH">
<div class="card-body"> <div class="card-body">
<div class="row mb-4"> <div class="row mb-4">
<div class="col-12 mb-4"> <div class="col-12 mb-4">
@ -74,6 +74,7 @@
ref="dropzoneWizard" ref="dropzoneWizard"
preview-classes="single" preview-classes="single"
:attachments="logo" :attachments="logo"
:v-model="logo"
> >
</akaunting-dropzone-file-upload> </akaunting-dropzone-file-upload>
</div> </div>
@ -83,8 +84,9 @@
<div class="row"> <div class="row">
<div class="col-md-12 text-right"> <div class="col-md-12 text-right">
<base-button <base-button
id="button"
type="success" type="success"
native-type="button" native-type="submit"
@click="onEditSave()" @click="onEditSave()"
>{{ translations.company.save }}</base-button >{{ translations.company.save }}</base-button
> >
@ -163,7 +165,7 @@ export default {
}, },
onEditSave() { onEditSave() {
this.onEditEvent("PATCH", url + "/wizard/companies", "logo", "", ""); this.onEditCompany();
this.$router.push("/wizard/currencies"); this.$router.push("/wizard/currencies");
}, },
}, },