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('UnitModelName')"
:rules="[form().required(this, 'name')]"
:error-messages="form().serverErrors(this, 'name')"
ref="name"
data-cy="name"
@input="fieldValueChanged('name')"
></v-text-field>
@@ -26,12 +26,12 @@
xl="3"
>
<gz-pick-list
ref="vendorId"
v-model="obj.vendorId"
:aya-type="ayaTypes().Vendor"
show-edit-icon
v-model="obj.vendorId"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelVendorID')"
ref="vendorId"
data-cy="vendorId"
:error-messages="form().serverErrors(this, 'vendorId')"
@input="fieldValueChanged('vendorId')"
@@ -46,11 +46,11 @@
xl="3"
>
<v-text-field
ref="upc"
v-model="obj.upc"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelUPC')"
:error-messages="form().serverErrors(this, 'upc')"
ref="upc"
data-cy="upc"
@input="fieldValueChanged('upc')"
></v-text-field>
@@ -64,10 +64,10 @@
xl="3"
>
<gz-date-picker
:label="$ay.t('UnitModelIntroducedDate')"
v-model="obj.introducedDate"
:readonly="formState.readOnly"
ref="introducedDate"
v-model="obj.introducedDate"
:label="$ay.t('UnitModelIntroducedDate')"
:readonly="formState.readOnly"
data-cy="introducedDate"
:error-messages="form().serverErrors(this, 'introducedDate')"
@input="fieldValueChanged('introducedDate')"
@@ -82,10 +82,10 @@
xl="3"
>
<v-checkbox
ref="discontinued"
v-model="obj.discontinued"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelDiscontinued')"
ref="discontinued"
data-cy="discontinued"
:error-messages="form().serverErrors(this, 'discontinued')"
@change="fieldValueChanged('discontinued')"
@@ -100,10 +100,10 @@
xl="3"
>
<gz-date-picker
:label="$ay.t('UnitModelDiscontinuedDate')"
v-model="obj.discontinuedDate"
:readonly="formState.readOnly"
ref="discontinuedDate"
v-model="obj.discontinuedDate"
:label="$ay.t('UnitModelDiscontinuedDate')"
:readonly="formState.readOnly"
data-cy="discontinuedDate"
:error-messages="form().serverErrors(this, 'discontinuedDate')"
@input="fieldValueChanged('discontinuedDate')"
@@ -118,10 +118,10 @@
xl="3"
>
<v-checkbox
ref="lifeTimeWarranty"
v-model="obj.lifeTimeWarranty"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelLifeTimeWarranty')"
ref="lifeTimeWarranty"
data-cy="lifeTimeWarranty"
:error-messages="form().serverErrors(this, 'lifeTimeWarranty')"
@change="fieldValueChanged('lifeTimeWarranty')"
@@ -136,36 +136,36 @@
xl="3"
>
<v-text-field
ref="warrantyLength"
v-model="obj.warrantyLength"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelWarrantyLength')"
ref="warrantyLength"
data-cy="warrantyLength"
:rules="[form().integerValid(this, 'warrantyLength')]"
:error-messages="form().serverErrors(this, 'warrantyLength')"
@input="fieldValueChanged('warrantyLength')"
type="number"
@input="fieldValueChanged('warrantyLength')"
></v-text-field>
</v-col>
<v-col v-if="form().showMe(this, 'UnitModelWarrantyTerms')" cols="12">
<v-textarea
ref="warrantyTerms"
v-model="obj.warrantyTerms"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelWarrantyTerms')"
:error-messages="form().serverErrors(this, 'warrantyTerms')"
ref="warrantyTerms"
data-cy="warrantyTerms"
@input="fieldValueChanged('warrantyTerms')"
auto-grow
@input="fieldValueChanged('warrantyTerms')"
></v-textarea>
</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')"
@@ -176,21 +176,21 @@
<v-col v-if="form().showMe(this, 'UnitModelNotes')" cols="12">
<v-textarea
ref="notes"
v-model="obj.notes"
:readonly="formState.readOnly"
:label="$ay.t('UnitModelNotes')"
: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')"
@@ -199,11 +199,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')"
@@ -212,10 +212,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
@@ -241,64 +241,6 @@ const FORM_KEY = "unit-model-edit";
const API_BASE_URL = "unit-model/";
const FORM_CUSTOM_TEMPLATE_KEY = "UnitModel";
export default {
async created() {
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.UnitModel);
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.number = `${this.obj.number} - ${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,
@@ -363,6 +305,64 @@ export default {
deep: true
}
},
async created() {
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.UnitModel);
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.number = `${this.obj.number} - ${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;
@@ -542,17 +542,19 @@ async function clickHandler(menuItem) {
m.vm.duplicate();
break;
case "report":
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.UnitModel,
selectedRowIds: [m.vm.obj.id]
},
m.id
);
if (res == null) {
return;
{
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.UnitModel,
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:
window.$gz.eventBus.$emit(
@@ -672,7 +674,7 @@ let JUST_DELETED = false;
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
await fetchTranslatedText();
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
}
@@ -680,7 +682,7 @@ async function initForm(vm) {
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
async function fetchTranslatedText() {
await window.$gz.translation.cacheTranslations([
"UnitModel",
"UnitModelNotes",