re-factor / cleanup

This commit is contained in:
2022-01-11 22:08:38 +00:00
parent e871708b20
commit e0be8a7cfe
251 changed files with 14680 additions and 15693 deletions

View File

@@ -7,12 +7,12 @@
<v-row>
<v-col cols="12" sm="6" lg="4" xl="3">
<v-text-field
ref="name"
v-model="obj.name"
:readonly="formState.readOnly"
:label="$ay.t('Name')"
:rules="[form().required(this, 'name')]"
:error-messages="form().serverErrors(this, 'name')"
ref="name"
data-cy="name"
@input="fieldValueChanged('name')"
></v-text-field>
@@ -26,10 +26,10 @@
xl="3"
>
<gz-percent
ref="taxAPct"
v-model="obj.taxAPct"
:readonly="formState.readOnly"
:label="$ay.t('TaxCodeTaxA')"
ref="taxAPct"
data-cy="taxAPct"
:rules="[
form().decimalValid(this, 'taxAPct'),
@@ -48,10 +48,10 @@
xl="3"
>
<gz-percent
ref="taxBPct"
v-model="obj.taxBPct"
:readonly="formState.readOnly"
:label="$ay.t('TaxCodeTaxB')"
ref="taxBPct"
data-cy="taxBPct"
:rules="[
form().decimalValid(this, 'taxBPct'),
@@ -70,10 +70,10 @@
xl="3"
>
<v-checkbox
ref="taxOnTax"
v-model="obj.taxOnTax"
:readonly="formState.readOnly"
:label="$ay.t('TaxCodeTaxOnTax')"
ref="taxOnTax"
data-cy="taxOnTax"
:error-messages="form().serverErrors(this, 'taxOnTax')"
@change="fieldValueChanged('taxOnTax')"
@@ -81,10 +81,10 @@
</v-col>
<v-col cols="12" sm="6" lg="4" xl="3">
<v-checkbox
ref="active"
v-model="obj.active"
:readonly="formState.readOnly"
:label="$ay.t('Active')"
ref="active"
data-cy="active"
:error-messages="form().serverErrors(this, 'active')"
@change="fieldValueChanged('active')"
@@ -93,22 +93,22 @@
<!-- --------------------------------- -->
<v-col v-if="form().showMe(this, 'Notes')" cols="12">
<v-textarea
ref="notes"
v-model="obj.notes"
:readonly="formState.readOnly"
:label="$ay.t('TaxCodeNotes')"
:error-messages="form().serverErrors(this, 'notes')"
ref="notes"
data-cy="notes"
@input="fieldValueChanged('notes')"
auto-grow
@input="fieldValueChanged('notes')"
></v-textarea>
</v-col>
<v-col v-if="form().showMe(this, 'Tags')" cols="12">
<gz-tag-picker
ref="tags"
v-model="obj.tags"
:readonly="formState.readOnly"
ref="tags"
data-cy="tags"
:error-messages="form().serverErrors(this, 'tags')"
@input="fieldValueChanged('tags')"
@@ -117,11 +117,11 @@
<v-col cols="12">
<gz-custom-fields
ref="customFields"
v-model="obj.customFields"
:form-key="formCustomTemplateKey"
:readonly="formState.readOnly"
:parent-v-m="this"
ref="customFields"
data-cy="customFields"
:error-messages="form().serverErrors(this, 'customFields')"
@input="fieldValueChanged('customFields')"
@@ -130,10 +130,10 @@
<v-col v-if="form().showMe(this, 'Wiki')" cols="12">
<gz-wiki
:aya-type="ayaType"
:aya-id="obj.id"
ref="wiki"
v-model="obj.wiki"
:aya-type="ayaType"
:aya-id="obj.id"
:readonly="formState.readOnly"
@input="fieldValueChanged('wiki')"
></gz-wiki
@@ -160,64 +160,6 @@ const API_BASE_URL = "tax-code/";
const FORM_CUSTOM_TEMPLATE_KEY = "TaxCode";
export default {
async created() {
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.TaxCode);
vm.formState.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler);
let setDirty = false;
//id 0 means create or duplicate to new
if (vm.$route.params.recordid != 0) {
//is there already an obj from a prior operation?
if (this.$route.params.obj) {
//yes, no need to fetch it
this.obj = this.$route.params.obj;
} else {
await vm.getDataFromApi(vm.$route.params.recordid);
}
} else {
//Might be a duplicate and contain another record
if (this.$route.params.obj) {
this.obj = this.$route.params.obj;
this.obj.concurrency = undefined;
this.obj.id = 0;
this.obj.name = `${this.obj.name} - ${window.$gz.translation.get(
"Copy"
)}`;
setDirty = true;
}
}
window.$gz.form.setFormState({
vm: vm,
loading: false,
dirty: setDirty,
valid: true
});
generateMenu(vm);
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
vm.formState.ready = true;
}
},
async beforeRouteLeave(to, from, next) {
if (!this.formState.dirty || JUST_DELETED) {
next();
return;
}
if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
next();
} else {
next(false);
}
},
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
data() {
return {
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
@@ -278,6 +220,64 @@ export default {
deep: true
}
},
async created() {
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.TaxCode);
vm.formState.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler);
let setDirty = false;
//id 0 means create or duplicate to new
if (vm.$route.params.recordid != 0) {
//is there already an obj from a prior operation?
if (this.$route.params.obj) {
//yes, no need to fetch it
this.obj = this.$route.params.obj;
} else {
await vm.getDataFromApi(vm.$route.params.recordid);
}
} else {
//Might be a duplicate and contain another record
if (this.$route.params.obj) {
this.obj = this.$route.params.obj;
this.obj.concurrency = undefined;
this.obj.id = 0;
this.obj.name = `${this.obj.name} - ${window.$gz.translation.get(
"Copy"
)}`;
setDirty = true;
}
}
window.$gz.form.setFormState({
vm: vm,
loading: false,
dirty: setDirty,
valid: true
});
generateMenu(vm);
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
vm.formState.ready = true;
}
},
async beforeRouteLeave(to, from, next) {
if (!this.formState.dirty || JUST_DELETED) {
next();
return;
}
if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
next();
} else {
next(false);
}
},
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
methods: {
canSave: function() {
return this.formState.valid && this.formState.dirty;
@@ -466,17 +466,19 @@ async function clickHandler(menuItem) {
m.vm.duplicate();
break;
case "report":
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.TaxCode,
selectedRowIds: [m.vm.obj.id]
},
m.id
);
if (res == null) {
return;
{
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.TaxCode,
selectedRowIds: [m.vm.obj.id]
},
m.id
);
if (res == null) {
return;
}
window.$gz.form.setLastReportMenuItem(FORM_KEY, res, m.vm);
}
window.$gz.form.setLastReportMenuItem(FORM_KEY, res, m.vm);
break;
default:
@@ -572,7 +574,7 @@ let JUST_DELETED = false;
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
await fetchTranslatedText();
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
}
@@ -580,7 +582,7 @@ async function initForm(vm) {
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
async function fetchTranslatedText() {
await window.$gz.translation.cacheTranslations([
"TaxCode",
"Name",