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

@@ -4,7 +4,7 @@
<div v-if="formState.ready">
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
<v-form ref="form">
<v-tabs mobile-breakpoint="100" v-model="tab" @change="tabChanged">
<v-tabs v-model="tab" mobile-breakpoint="100" @change="tabChanged">
<v-tab>{{ $ay.t("Customer") }}</v-tab>
<v-tab>{{ $ay.t("Address") }}</v-tab>
<v-tab>{{ $ay.t("Contacts") }}</v-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('CustomerName')"
:rules="[form().required(this, 'name')]"
:error-messages="form().serverErrors(this, 'name')"
ref="name"
data-cy="name"
@input="fieldValueChanged('name')"
></v-text-field>
@@ -31,10 +31,10 @@
xl="3"
>
<v-text-field
ref="accountNumber"
v-model="obj.accountNumber"
:readonly="formState.readOnly"
:label="$ay.t('CustomerAccountNumber')"
ref="accountNumber"
data-cy="accountNumber"
:error-messages="form().serverErrors(this, 'accountNumber')"
@input="fieldValueChanged('accountNumber')"
@@ -49,10 +49,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')"
@@ -67,10 +67,10 @@
xl="3"
>
<gz-email
ref="emailAddress"
v-model="obj.emailAddress"
:readonly="formState.readOnly"
:label="$ay.t('CustomerEmail')"
ref="emailAddress"
data-cy="emailAddress"
:error-messages="form().serverErrors(this, 'emailAddress')"
@input="fieldValueChanged('emailAddress')"
@@ -85,10 +85,10 @@
xl="3"
>
<gz-phone
ref="phone1"
v-model="obj.phone1"
:readonly="formState.readOnly"
:label="$ay.t('CustomerPhone1')"
ref="phone1"
data-cy="phone1"
:error-messages="form().serverErrors(this, 'phone1')"
@input="fieldValueChanged('phone1')"
@@ -103,10 +103,10 @@
xl="3"
>
<gz-phone
ref="phone2"
v-model="obj.phone2"
:readonly="formState.readOnly"
:label="$ay.t('CustomerPhone2')"
ref="phone2"
data-cy="phone2"
:error-messages="form().serverErrors(this, 'phone2')"
@input="fieldValueChanged('phone2')"
@@ -121,10 +121,10 @@
xl="3"
>
<gz-phone
ref="phone3"
v-model="obj.phone3"
:readonly="formState.readOnly"
:label="$ay.t('CustomerPhone3')"
ref="phone3"
data-cy="phone3"
:error-messages="form().serverErrors(this, 'phone3')"
@input="fieldValueChanged('phone3')"
@@ -139,10 +139,10 @@
xl="3"
>
<gz-phone
ref="phone4"
v-model="obj.phone4"
:readonly="formState.readOnly"
:label="$ay.t('CustomerPhone4')"
ref="phone4"
data-cy="phone4"
:error-messages="form().serverErrors(this, 'phone4')"
@input="fieldValueChanged('phone4')"
@@ -157,10 +157,10 @@
xl="3"
>
<gz-phone
ref="phone5"
v-model="obj.phone5"
:readonly="formState.readOnly"
:label="$ay.t('CustomerPhone5')"
ref="phone5"
data-cy="phone5"
:error-messages="form().serverErrors(this, 'phone5')"
@input="fieldValueChanged('phone5')"
@@ -175,10 +175,10 @@
xl="3"
>
<v-checkbox
ref="billHeadOffice"
v-model="obj.billHeadOffice"
:readonly="formState.readOnly"
:label="$ay.t('CustomerBillHeadOffice')"
ref="billHeadOffice"
data-cy="billHeadOffice"
:error-messages="
form().serverErrors(this, 'billHeadOffice')
@@ -195,12 +195,12 @@
xl="3"
>
<gz-pick-list
ref="headOfficeId"
v-model="obj.headOfficeId"
:aya-type="ayaTypes().HeadOffice"
show-edit-icon
v-model="obj.headOfficeId"
:readonly="formState.readOnly"
:label="$ay.t('HeadOffice')"
ref="headOfficeId"
data-cy="headOfficeId"
:error-messages="form().serverErrors(this, 'headOfficeId')"
@input="fieldValueChanged('headOfficeId')"
@@ -215,12 +215,12 @@
xl="3"
>
<gz-pick-list
ref="contractId"
v-model="obj.contractId"
:aya-type="ayaTypes().Contract"
show-edit-icon
v-model="obj.contractId"
:readonly="formState.readOnly"
:label="$ay.t('Contract')"
ref="contractId"
data-cy="contractId"
:error-messages="form().serverErrors(this, 'contractId')"
@input="fieldValueChanged('contractId')"
@@ -237,10 +237,10 @@
xl="3"
>
<gz-date-time-picker
:label="$ay.t('ContractExpires')"
v-model="obj.contractExpires"
:readonly="formState.readOnly"
ref="contractExpires"
v-model="obj.contractExpires"
:label="$ay.t('ContractExpires')"
:readonly="formState.readOnly"
data-cy="contractExpires"
:error-messages="
form().serverErrors(this, 'contractExpires')
@@ -280,10 +280,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')"
@@ -292,28 +292,28 @@
<!-------------------------------- -->
<v-col v-if="form().showMe(this, 'Notes')" cols="12">
<v-textarea
ref="notes"
v-model="obj.notes"
:readonly="formState.readOnly"
:label="$ay.t('CustomerNotes')"
: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, 'TechNotes')" cols="12">
<v-textarea
ref="techNotes"
v-model="obj.techNotes"
:readonly="formState.readOnly"
:label="$ay.t('CustomerTechNotes')"
:error-messages="form().serverErrors(this, 'techNotes')"
ref="techNotes"
data-cy="techNotes"
@input="fieldValueChanged('techNotes')"
auto-grow
prepend-icon="$ayiTools"
@input="fieldValueChanged('techNotes')"
></v-textarea>
</v-col>
@@ -322,24 +322,24 @@
cols="12"
>
<v-textarea
ref="alertNotes"
v-model="obj.alertNotes"
:readonly="formState.readOnly"
:label="$ay.t('CustomerAlertNotes')"
: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')"
@@ -348,11 +348,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')"
@@ -361,10 +361,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
@@ -385,7 +385,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
@@ -420,7 +420,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>
@@ -432,10 +432,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')"
@@ -450,10 +450,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')"
@@ -468,10 +468,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')"
@@ -486,10 +486,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')"
@@ -504,15 +504,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>
@@ -524,20 +524,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
@@ -564,7 +564,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>
@@ -577,10 +577,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')"
@@ -595,10 +595,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')"
@@ -613,10 +613,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')"
@@ -631,10 +631,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')"
@@ -649,10 +649,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')"
@@ -671,12 +671,12 @@
:disable-pagination="true"
:disable-filtering="true"
hide-default-footer
@click:row="contactsRowClick"
:sort-by="['name']"
:show-select="false"
:header-props="{ sortByText: $ay.t('Sort') }"
data-cy="custUsersTable"
:no-data-text="$ay.t('NoData')"
@click:row="contactsRowClick"
>
<template v-slot:[`item.active`]="{ item }">
<v-simple-checkbox
@@ -688,15 +688,15 @@
<template v-slot:top>
<div class="text-right mb-6">
<v-btn
@click="contactsGetDataFromApi"
:disabled="obj.id == 0"
@click="contactsGetDataFromApi"
>
<v-icon data-cy="refresh">$ayiSync</v-icon>
</v-btn>
<v-btn
class="ml-12"
@click="addContact"
:disabled="obj.id == 0 || formState.readOnly"
@click="addContact"
>
<v-icon data-cy="add">$ayiPlus</v-icon>
</v-btn>
@@ -720,73 +720,6 @@ const FORM_KEY = "customer-edit";
const API_BASE_URL = "customer/";
const FORM_CUSTOM_TEMPLATE_KEY = "Customer";
export default {
async created() {
const vm = this;
let completelyNew = false;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.Customer);
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;
} else {
completelyNew = 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;
if (completelyNew) {
//completely new record pre-break name rule so it shows as required
//trigger rule breaking / validation
this.$nextTick(() => {
this.obj.name = null;
this.fieldValueChanged(`name`);
});
}
}
},
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,
@@ -883,6 +816,73 @@ export default {
deep: true
}
},
async created() {
const vm = this;
let completelyNew = false;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.Customer);
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;
} else {
completelyNew = 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;
if (completelyNew) {
//completely new record pre-break name rule so it shows as required
//trigger rule breaking / validation
this.$nextTick(() => {
this.obj.name = null;
this.fieldValueChanged(`name`);
});
}
}
},
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: {
// canOpenServiceBank: function() {
// return this.obj.usesBanking == true && this.$route.params.recordid != 0;
@@ -1078,7 +1078,7 @@ export default {
if (roles != null && roles != 0) {
for (let i = 0; i < this.availableRoles.length; i++) {
const role = this.availableRoles[i];
if (!!(roles & role.id)) {
if (roles & role.id) {
roleNames.push(role.name);
}
}
@@ -1265,17 +1265,19 @@ async function clickHandler(menuItem) {
m.vm.duplicate();
break;
case "report":
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.Customer,
selectedRowIds: [m.vm.obj.id]
},
m.id
);
if (res == null) {
return;
{
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.Customer,
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({
@@ -1484,7 +1486,7 @@ let JUST_DELETED = false;
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
await fetchTranslatedText();
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
await createTableHeaders(vm);
}
@@ -1493,7 +1495,7 @@ async function initForm(vm) {
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
async function fetchTranslatedText() {
await window.$gz.translation.cacheTranslations([
"Customer",
"CustomerName",