re-factor / cleanup
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
|
||||
|
||||
<v-form ref="form">
|
||||
<v-tabs mobile-breakpoint="100" v-model="tab">
|
||||
<v-tabs v-model="tab" mobile-breakpoint="100">
|
||||
<v-tab>{{ $ay.t("Vendor") }}</v-tab>
|
||||
<v-tab>{{ $ay.t("Address") }}</v-tab>
|
||||
<v-tabs-items v-model="tab">
|
||||
@@ -13,12 +13,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('VendorName')"
|
||||
:rules="[form().required(this, 'name')]"
|
||||
:error-messages="form().serverErrors(this, 'name')"
|
||||
ref="name"
|
||||
data-cy="name"
|
||||
@input="fieldValueChanged('name')"
|
||||
></v-text-field>
|
||||
@@ -32,10 +32,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="accountNumber"
|
||||
v-model="obj.accountNumber"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorAccountNumber')"
|
||||
ref="accountNumber"
|
||||
data-cy="accountNumber"
|
||||
:error-messages="form().serverErrors(this, 'accountNumber')"
|
||||
@input="fieldValueChanged('accountNumber')"
|
||||
@@ -50,10 +50,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-url
|
||||
ref="webAddress"
|
||||
v-model="obj.webAddress"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('WebAddress')"
|
||||
ref="webAddress"
|
||||
data-cy="webAddress"
|
||||
:error-messages="form().serverErrors(this, 'webAddress')"
|
||||
@input="fieldValueChanged('webAddress')"
|
||||
@@ -68,10 +68,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="contact"
|
||||
v-model="obj.contact"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorContact')"
|
||||
ref="contact"
|
||||
data-cy="contact"
|
||||
:error-messages="form().serverErrors(this, 'contact')"
|
||||
@input="fieldValueChanged('contact')"
|
||||
@@ -86,10 +86,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-email
|
||||
ref="emailAddress"
|
||||
v-model="obj.emailAddress"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorEmail')"
|
||||
ref="emailAddress"
|
||||
data-cy="emailAddress"
|
||||
:error-messages="form().serverErrors(this, 'emailAddress')"
|
||||
@input="fieldValueChanged('emailAddress')"
|
||||
@@ -104,10 +104,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone1"
|
||||
v-model="obj.phone1"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorPhone1')"
|
||||
ref="phone1"
|
||||
data-cy="phone1"
|
||||
:error-messages="form().serverErrors(this, 'phone1')"
|
||||
@input="fieldValueChanged('phone1')"
|
||||
@@ -122,10 +122,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone2"
|
||||
v-model="obj.phone2"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorPhone2')"
|
||||
ref="phone2"
|
||||
data-cy="phone2"
|
||||
:error-messages="form().serverErrors(this, 'phone2')"
|
||||
@input="fieldValueChanged('phone2')"
|
||||
@@ -140,10 +140,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone3"
|
||||
v-model="obj.phone3"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorPhone3')"
|
||||
ref="phone3"
|
||||
data-cy="phone3"
|
||||
:error-messages="form().serverErrors(this, 'phone3')"
|
||||
@input="fieldValueChanged('phone3')"
|
||||
@@ -158,10 +158,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone4"
|
||||
v-model="obj.phone4"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorPhone4')"
|
||||
ref="phone4"
|
||||
data-cy="phone4"
|
||||
:error-messages="form().serverErrors(this, 'phone4')"
|
||||
@input="fieldValueChanged('phone4')"
|
||||
@@ -176,10 +176,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone5"
|
||||
v-model="obj.phone5"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorPhone5')"
|
||||
ref="phone5"
|
||||
data-cy="phone5"
|
||||
:error-messages="form().serverErrors(this, 'phone5')"
|
||||
@input="fieldValueChanged('phone5')"
|
||||
@@ -187,10 +187,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')"
|
||||
@@ -199,51 +199,51 @@
|
||||
<!-- --------------------------------- -->
|
||||
<v-col v-if="form().showMe(this, 'Notes')" cols="12">
|
||||
<v-textarea
|
||||
ref="notes"
|
||||
v-model="obj.notes"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorNotes')"
|
||||
: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, 'ContactNotes')" cols="12">
|
||||
<v-textarea
|
||||
ref="contactNotes"
|
||||
v-model="obj.contactNotes"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorContactNotes')"
|
||||
:error-messages="form().serverErrors(this, 'contactNotes')"
|
||||
ref="contactNotes"
|
||||
data-cy="contactNotes"
|
||||
@input="fieldValueChanged('contactNotes')"
|
||||
auto-grow
|
||||
prepend-icon="$ayiUser"
|
||||
@input="fieldValueChanged('contactNotes')"
|
||||
></v-textarea>
|
||||
</v-col>
|
||||
|
||||
<v-col v-if="form().showMe(this, 'VendorAlertNotes')" cols="12">
|
||||
<v-textarea
|
||||
ref="alertNotes"
|
||||
v-model="obj.alertNotes"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('VendorAlertNotes')"
|
||||
:error-messages="form().serverErrors(this, 'alertNotes')"
|
||||
ref="alertNotes"
|
||||
data-cy="alertNotes"
|
||||
@input="fieldValueChanged('alertNotes')"
|
||||
auto-grow
|
||||
prepend-icon="$ayiInfoCircle"
|
||||
color="primary"
|
||||
@input="fieldValueChanged('alertNotes')"
|
||||
></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')"
|
||||
@@ -252,11 +252,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')"
|
||||
@@ -265,10 +265,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
|
||||
@@ -289,7 +289,7 @@
|
||||
<v-tab-item class="mt-4 ml-2">
|
||||
<v-row>
|
||||
<v-col cols="12">
|
||||
<v-menu offset-y v-if="rights.change">
|
||||
<v-menu v-if="rights.change" offset-y>
|
||||
<template v-slot:activator="{ on, attrs }">
|
||||
<span class="text-h6">
|
||||
{{ $ay.t("AddressTypePhysical") }}</span
|
||||
@@ -324,7 +324,7 @@
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
<span class="text-h6" v-else>
|
||||
<span v-else class="text-h6">
|
||||
{{ $ay.t("AddressTypePhysical") }}</span
|
||||
>
|
||||
</v-col>
|
||||
@@ -336,10 +336,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="address"
|
||||
v-model="obj.address"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressDeliveryAddress')"
|
||||
ref="address"
|
||||
data-cy="address"
|
||||
:error-messages="form().serverErrors(this, 'address')"
|
||||
@input="fieldValueChanged('address')"
|
||||
@@ -354,10 +354,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="city"
|
||||
v-model="obj.city"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressCity')"
|
||||
ref="city"
|
||||
data-cy="city"
|
||||
:error-messages="form().serverErrors(this, 'city')"
|
||||
@input="fieldValueChanged('city')"
|
||||
@@ -372,10 +372,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="region"
|
||||
v-model="obj.region"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressStateProv')"
|
||||
ref="region"
|
||||
data-cy="region"
|
||||
:error-messages="form().serverErrors(this, 'region')"
|
||||
@input="fieldValueChanged('region')"
|
||||
@@ -390,10 +390,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="country"
|
||||
v-model="obj.country"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressCountry')"
|
||||
ref="country"
|
||||
data-cy="country"
|
||||
:error-messages="form().serverErrors(this, 'country')"
|
||||
@input="fieldValueChanged('country')"
|
||||
@@ -408,15 +408,15 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-decimal
|
||||
ref="latitude"
|
||||
v-model="obj.latitude"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressLatitude')"
|
||||
ref="latitude"
|
||||
data-cy="latitude"
|
||||
:rules="[form().decimalValid(this, 'latitude')]"
|
||||
:error-messages="form().serverErrors(this, 'latitude')"
|
||||
@input="fieldValueChanged('latitude')"
|
||||
:precision="6"
|
||||
@input="fieldValueChanged('latitude')"
|
||||
></gz-decimal>
|
||||
</v-col>
|
||||
|
||||
@@ -428,20 +428,20 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-decimal
|
||||
ref="longitude"
|
||||
v-model="obj.longitude"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressLongitude')"
|
||||
ref="longitude"
|
||||
data-cy="longitude"
|
||||
:rules="[form().decimalValid(this, 'longitude')]"
|
||||
:error-messages="form().serverErrors(this, 'longitude')"
|
||||
@input="fieldValueChanged('longitude')"
|
||||
:precision="6"
|
||||
@input="fieldValueChanged('longitude')"
|
||||
></gz-decimal>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12">
|
||||
<v-menu offset-y v-if="rights.change">
|
||||
<v-menu v-if="rights.change" offset-y>
|
||||
<template v-slot:activator="{ on, attrs }">
|
||||
<span class="text-h6">
|
||||
{{ $ay.t("AddressTypePostal") }}</span
|
||||
@@ -468,7 +468,7 @@
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
<span class="text-h6" v-else>
|
||||
<span v-else class="text-h6">
|
||||
{{ $ay.t("AddressTypePostal") }}</span
|
||||
>
|
||||
</v-col>
|
||||
@@ -481,10 +481,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="postAddress"
|
||||
v-model="obj.postAddress"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressPostalDeliveryAddress')"
|
||||
ref="postAddress"
|
||||
data-cy="postAddress"
|
||||
:error-messages="form().serverErrors(this, 'postAddress')"
|
||||
@input="fieldValueChanged('postAddress')"
|
||||
@@ -499,10 +499,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="postCity"
|
||||
v-model="obj.postCity"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressPostalCity')"
|
||||
ref="postCity"
|
||||
data-cy="postCity"
|
||||
:error-messages="form().serverErrors(this, 'postCity')"
|
||||
@input="fieldValueChanged('postCity')"
|
||||
@@ -517,10 +517,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="postRegion"
|
||||
v-model="obj.postRegion"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressPostalStateProv')"
|
||||
ref="postRegion"
|
||||
data-cy="postRegion"
|
||||
:error-messages="form().serverErrors(this, 'postRegion')"
|
||||
@input="fieldValueChanged('postRegion')"
|
||||
@@ -535,10 +535,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="postCountry"
|
||||
v-model="obj.postCountry"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressPostalCountry')"
|
||||
ref="postCountry"
|
||||
data-cy="postCountry"
|
||||
:error-messages="form().serverErrors(this, 'postCountry')"
|
||||
@input="fieldValueChanged('postCountry')"
|
||||
@@ -553,10 +553,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="postCode"
|
||||
v-model="obj.postCode"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('AddressPostalPostal')"
|
||||
ref="postCode"
|
||||
data-cy="postCode"
|
||||
:error-messages="form().serverErrors(this, 'postCode')"
|
||||
@input="fieldValueChanged('postCode')"
|
||||
@@ -578,64 +578,6 @@ const FORM_KEY = "vendor-edit";
|
||||
const API_BASE_URL = "vendor/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Vendor";
|
||||
export default {
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Vendor);
|
||||
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,
|
||||
@@ -716,6 +658,64 @@ export default {
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Vendor);
|
||||
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;
|
||||
@@ -976,17 +976,19 @@ async function clickHandler(menuItem) {
|
||||
m.vm.duplicate();
|
||||
break;
|
||||
case "report":
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.Vendor,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
},
|
||||
m.id
|
||||
);
|
||||
if (res == null) {
|
||||
return;
|
||||
{
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.Vendor,
|
||||
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;
|
||||
case "geoview":
|
||||
window.$gz.util.viewGeoLocation({
|
||||
@@ -1103,7 +1105,7 @@ let JUST_DELETED = false;
|
||||
//
|
||||
//
|
||||
async function initForm(vm) {
|
||||
await fetchTranslatedText(vm);
|
||||
await fetchTranslatedText();
|
||||
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
|
||||
}
|
||||
|
||||
@@ -1111,7 +1113,7 @@ async function initForm(vm) {
|
||||
//
|
||||
// Ensures UI translated text is available
|
||||
//
|
||||
async function fetchTranslatedText(vm) {
|
||||
async function fetchTranslatedText() {
|
||||
await window.$gz.translation.cacheTranslations([
|
||||
"Vendor",
|
||||
"VendorName",
|
||||
|
||||
Reference in New Issue
Block a user