HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -3,13 +3,11 @@
|
||||
<gz-report-selector ref="reportSelector"></gz-report-selector>
|
||||
<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-tab>{{ $ay.t("Customer") }}</v-tab>
|
||||
<v-tab>{{ $ay.t("Address") }}</v-tab>
|
||||
<v-tab>{{ $ay.t("Contacts") }}</v-tab>
|
||||
|
||||
<v-tabs-items v-model="tab">
|
||||
<v-tab-item class="mt-4 ml-2">
|
||||
<v-row>
|
||||
@@ -25,7 +23,6 @@
|
||||
@input="fieldValueChanged('name')"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
|
||||
<v-col
|
||||
v-if="form().showMe(this, 'AccountNumber')"
|
||||
cols="12"
|
||||
@@ -170,28 +167,6 @@
|
||||
></gz-phone>
|
||||
</v-col>
|
||||
|
||||
<!-- <v-col
|
||||
v-if="form().showMe(this, 'DefaultServiceTemplateId')"
|
||||
cols="12"
|
||||
sm="6"
|
||||
lg="4"
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
:aya-type="ayaTypes().WorkOrderTemplate"
|
||||
show-edit-icon
|
||||
v-model="obj.defaultServiceTemplatedId"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('WorkOrderTemplate')"
|
||||
ref="defaultServiceTemplateId"
|
||||
data-cy="defaultServiceTemplateId"
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'defaultServiceTemplateId')
|
||||
"
|
||||
@input="fieldValueChanged('defaultServiceTemplateId')"
|
||||
></gz-pick-list>
|
||||
</v-col> -->
|
||||
|
||||
<v-col
|
||||
v-if="form().showMe(this, 'BillHeadOffice')"
|
||||
cols="12"
|
||||
@@ -742,40 +717,20 @@
|
||||
</v-overlay>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* Xeslint-disable */
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
const FORM_KEY = "customer-edit";
|
||||
const API_BASE_URL = "customer/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Customer"; //<-- Should always be CoreBizObject AyaType name here where possible
|
||||
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Customer";
|
||||
export default {
|
||||
async created() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
let completelyNew = false;
|
||||
//Prevent returning back to the /0 NEW route after having just created a new record and instead return to the original new source page
|
||||
// console.log("cust-customer created params: ", vm.$route.params);
|
||||
// if (
|
||||
// vm.$route.params.recordid == null ||
|
||||
// (vm.$route.params.recordid == 0 && vm.$route.params.newRecord == null) //here recordid will technically be "0" if returned back to it from prior new
|
||||
// ) {
|
||||
// // navigate backwards
|
||||
// vm.$router.go(-1);
|
||||
// return;
|
||||
// }
|
||||
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;
|
||||
let setValid = true;
|
||||
|
||||
//id 0 means create or duplicate to new
|
||||
if (vm.$route.params.recordid != 0) {
|
||||
//is there already an obj from a prior operation?
|
||||
@@ -783,7 +738,7 @@ export default {
|
||||
//yes, no need to fetch it
|
||||
this.obj = this.$route.params.obj;
|
||||
} else {
|
||||
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
|
||||
await vm.getDataFromApi(vm.$route.params.recordid);
|
||||
}
|
||||
} else {
|
||||
//Might be a duplicate and contain another record
|
||||
@@ -799,12 +754,11 @@ export default {
|
||||
completelyNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false,
|
||||
dirty: setDirty,
|
||||
valid: setValid
|
||||
valid: true
|
||||
});
|
||||
generateMenu(vm);
|
||||
} catch (error) {
|
||||
@@ -841,47 +795,43 @@ export default {
|
||||
selectLists: {
|
||||
usertypes: []
|
||||
},
|
||||
obj:
|
||||
//IMPORTANT NOTE: Fields that are NON NULLABLE in the schema for the table but *are* hideable **MUST** have a default value set here or else there will be no way to save the record
|
||||
//I.E. Serial, usertype fields, ACTIVE
|
||||
//Also, if it's a non-nullable Enum backed field then it should have a valid selection i.e. not zero if there is no zero
|
||||
{
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
name: undefined,
|
||||
active: true,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
webAddress: null,
|
||||
alertNotes: null,
|
||||
billHeadOffice: false,
|
||||
headOfficeId: null,
|
||||
techNotes: null,
|
||||
accountNumber: null,
|
||||
//usesBanking: false,
|
||||
contractId: null,
|
||||
contractExpires: null,
|
||||
defaultServiceTemplateId: null,
|
||||
phone1: null,
|
||||
phone2: null,
|
||||
phone3: null,
|
||||
phone4: null,
|
||||
phone5: null,
|
||||
emailAddress: null,
|
||||
postAddress: null,
|
||||
postCity: null,
|
||||
postRegion: null,
|
||||
postCountry: null,
|
||||
postCode: null,
|
||||
address: null,
|
||||
city: null,
|
||||
region: null,
|
||||
country: null,
|
||||
latitude: null,
|
||||
longitude: null
|
||||
},
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
name: undefined,
|
||||
active: true,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
webAddress: null,
|
||||
alertNotes: null,
|
||||
billHeadOffice: false,
|
||||
headOfficeId: null,
|
||||
techNotes: null,
|
||||
accountNumber: null,
|
||||
//usesBanking: false,
|
||||
contractId: null,
|
||||
contractExpires: null,
|
||||
defaultServiceTemplateId: null,
|
||||
phone1: null,
|
||||
phone2: null,
|
||||
phone3: null,
|
||||
phone4: null,
|
||||
phone5: null,
|
||||
emailAddress: null,
|
||||
postAddress: null,
|
||||
postCity: null,
|
||||
postRegion: null,
|
||||
postCountry: null,
|
||||
postCode: null,
|
||||
address: null,
|
||||
city: null,
|
||||
region: null,
|
||||
country: null,
|
||||
latitude: null,
|
||||
longitude: null
|
||||
},
|
||||
tab: 0,
|
||||
formState: {
|
||||
ready: false,
|
||||
@@ -905,23 +855,19 @@ export default {
|
||||
hour12: window.$gz.locale.getHour12()
|
||||
};
|
||||
},
|
||||
//WATCHERS
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
//,oldval is available here too if necessary
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
//enable / disable save button
|
||||
if (val.dirty && val.valid && !val.readOnly) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
|
||||
}
|
||||
|
||||
//enable / disable duplicate / new button
|
||||
if (!val.dirty && val.valid && !val.readOnly) {
|
||||
window.$gz.eventBus.$emit(
|
||||
"menu-enable-item",
|
||||
@@ -978,7 +924,7 @@ export default {
|
||||
}
|
||||
},
|
||||
async getDataFromApi(recordId) {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
@@ -986,14 +932,11 @@ export default {
|
||||
if (!recordId) {
|
||||
throw new Error(FORM_KEY + "::getDataFromApi -> Missing recordID!");
|
||||
}
|
||||
let url = API_BASE_URL + recordId;
|
||||
|
||||
try {
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
|
||||
let res = await window.$gz.api.get(url);
|
||||
|
||||
const res = await window.$gz.api.get(API_BASE_URL + recordId);
|
||||
if (res.error) {
|
||||
//Not found?
|
||||
if (res.error.code == "2010") {
|
||||
window.$gz.form.handleObjectNotFound(vm);
|
||||
}
|
||||
@@ -1001,9 +944,7 @@ export default {
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
vm.obj = res.data;
|
||||
//modify the menu as necessary
|
||||
generateMenu(vm);
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
@@ -1021,46 +962,35 @@ export default {
|
||||
}
|
||||
},
|
||||
async submit() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (vm.canSave == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
});
|
||||
let url = API_BASE_URL; // + vm.$route.params.recordid;
|
||||
//clear any errors vm might be around from previous submit
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
|
||||
let res = await window.$gz.api.upsert(url, vm.obj);
|
||||
|
||||
const res = await window.$gz.api.upsert(API_BASE_URL, vm.obj);
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
||||
if (res.data.id) {
|
||||
//POST - whole new object returned
|
||||
//POST
|
||||
vm.obj = res.data;
|
||||
//Change URL to new record
|
||||
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
|
||||
|
||||
this.$router.replace({
|
||||
name: "customer-edit",
|
||||
params: {
|
||||
recordid: res.data.id,
|
||||
obj: res.data // Pass data object to new form
|
||||
obj: res.data
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//PUT - only concurrency token is returned (**warning, if server changes object other fields then this needs to act more like POST above but is more efficient this way**)
|
||||
//Handle "put" of an existing record (UPDATE)
|
||||
//PUT
|
||||
vm.obj.concurrency = res.data.concurrency;
|
||||
}
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
@@ -1077,42 +1007,33 @@ export default {
|
||||
}
|
||||
},
|
||||
async remove() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
try {
|
||||
let dialogResult = await window.$gz.dialog.confirmDelete();
|
||||
const dialogResult = await window.$gz.dialog.confirmDelete();
|
||||
if (dialogResult != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
//do the delete
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
});
|
||||
//No need to delete a new record, just abandon it...
|
||||
if (vm.$route.params.recordid == 0) {
|
||||
//this should not get offered for delete but to be safe and clear just in case:
|
||||
JUST_DELETED = true;
|
||||
// navigate backwards
|
||||
vm.$router.go(-1);
|
||||
} else {
|
||||
let url = API_BASE_URL + vm.$route.params.recordid;
|
||||
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
let res = await window.$gz.api.remove(url);
|
||||
const res = await window.$gz.api.remove(
|
||||
API_BASE_URL + vm.$route.params.recordid
|
||||
);
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
//workaround to prevent warning about leaving dirty record
|
||||
//For some reason I couldn't just reset isdirty in formstate
|
||||
JUST_DELETED = true;
|
||||
// navigate backwards
|
||||
vm.$router.go(-1);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false
|
||||
@@ -1121,7 +1042,6 @@ export default {
|
||||
}
|
||||
},
|
||||
duplicate() {
|
||||
//Navigate to new record
|
||||
this.$router.push({
|
||||
name: "customer-edit",
|
||||
params: {
|
||||
@@ -1137,10 +1057,6 @@ export default {
|
||||
await this.contactsGetDataFromApi();
|
||||
}
|
||||
}
|
||||
// let vm = this;
|
||||
// if (vm[tabIndexToRoute(vm.tab)].isnew) {
|
||||
// vm.getDataFromApi();
|
||||
// }
|
||||
},
|
||||
addContact() {
|
||||
if (this.obj.id == 0) {
|
||||
@@ -1159,10 +1075,10 @@ export default {
|
||||
});
|
||||
},
|
||||
rolesDisplayFromRoles(roles) {
|
||||
let roleNames = [];
|
||||
const roleNames = [];
|
||||
if (roles != null && roles != 0) {
|
||||
for (let i = 0; i < this.availableRoles.length; i++) {
|
||||
let role = this.availableRoles[i];
|
||||
const role = this.availableRoles[i];
|
||||
if (!!(roles & role.id)) {
|
||||
roleNames.push(role.name);
|
||||
}
|
||||
@@ -1171,16 +1087,15 @@ export default {
|
||||
return roleNames.join(", ");
|
||||
},
|
||||
async contactsGetDataFromApi() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
vm.formState.loading = true;
|
||||
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
try {
|
||||
let res = await window.$gz.api.get(
|
||||
const res = await window.$gz.api.get(
|
||||
`user/customer-contacts/${vm.obj.id}`
|
||||
);
|
||||
vm.hasFetchedContacts = true;
|
||||
|
||||
if (res.error) {
|
||||
if (res.error.code == "2010") {
|
||||
window.$gz.form.handleObjectNotFound(vm);
|
||||
@@ -1189,14 +1104,9 @@ export default {
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
if (res.data) {
|
||||
/* Id = z.Id,
|
||||
Active = z.Active,
|
||||
Name = z.Name,
|
||||
UserType = z.UserType,
|
||||
LastLogin = z.LastLogin */
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
for (let i = 0; i < res.data.length; i++) {
|
||||
let o = res.data[i];
|
||||
const o = res.data[i];
|
||||
ret.push({
|
||||
id: o.id,
|
||||
name: o.name,
|
||||
@@ -1213,13 +1123,11 @@ export default {
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
vm.contactsObj = ret;
|
||||
} else {
|
||||
vm.rawObj = [];
|
||||
vm.contactsObj = [];
|
||||
}
|
||||
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
@@ -1237,25 +1145,23 @@ export default {
|
||||
}
|
||||
},
|
||||
AddressCopyToPostal() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
vm.obj.postAddress = vm.obj.address;
|
||||
vm.obj.postCity = vm.obj.city;
|
||||
vm.obj.postRegion = vm.obj.region;
|
||||
vm.obj.postCountry = vm.obj.country;
|
||||
//flag form dirty
|
||||
this.formState.dirty = true;
|
||||
},
|
||||
AddressCopyToPhysical() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
vm.obj.address = vm.obj.postAddress;
|
||||
vm.obj.city = vm.obj.postCity;
|
||||
vm.obj.region = vm.obj.postRegion;
|
||||
vm.obj.country = vm.obj.postCountry;
|
||||
//flag form dirty
|
||||
this.formState.dirty = true;
|
||||
},
|
||||
AddressCopyPhysicalToClipBoard() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
let ret = "";
|
||||
if (vm.obj.name) {
|
||||
ret += vm.obj.name + "\n";
|
||||
@@ -1278,20 +1184,20 @@ export default {
|
||||
window.$gz.util.copyToClipboard(ret);
|
||||
/* todo maybe down the road if asked for?
|
||||
|
||||
if(mAddressType==AddressTypes.Physical)
|
||||
{
|
||||
if(mLatitude!=0 || mLongitude!=0)
|
||||
{
|
||||
sb.Append(" \r\n");
|
||||
sb.Append(LongitudeToString(mLongitude));
|
||||
sb.Append(" ");
|
||||
sb.Append(LatitudeToString(mLatitude));
|
||||
sb.Append(" \r\n");
|
||||
}
|
||||
} */
|
||||
if(mAddressType==AddressTypes.Physical)
|
||||
{
|
||||
if(mLatitude!=0 || mLongitude!=0)
|
||||
{
|
||||
sb.Append(" \r\n");
|
||||
sb.Append(LongitudeToString(mLongitude));
|
||||
sb.Append(" ");
|
||||
sb.Append(LatitudeToString(mLatitude));
|
||||
sb.Append(" \r\n");
|
||||
}
|
||||
} */
|
||||
},
|
||||
AddressCopyPostalToClipBoard() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
let ret = "";
|
||||
if (vm.obj.name) {
|
||||
ret += vm.obj.name + "\n";
|
||||
@@ -1319,10 +1225,10 @@ export default {
|
||||
window.$gz.util.copyToClipboard(ret);
|
||||
},
|
||||
async GeoCapture() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
try {
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
let loc = await window.$gz.util.getGeoLocation();
|
||||
const loc = await window.$gz.util.getGeoLocation();
|
||||
vm.obj.latitude = loc.latitude;
|
||||
vm.fieldValueChanged("latitude");
|
||||
vm.obj.longitude = loc.longitude;
|
||||
@@ -1331,8 +1237,6 @@ export default {
|
||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||
}
|
||||
}
|
||||
|
||||
//end methods
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1343,7 +1247,7 @@ async function clickHandler(menuItem) {
|
||||
if (!menuItem) {
|
||||
return;
|
||||
}
|
||||
let m = window.$gz.menu.parseMenuItem(menuItem);
|
||||
const m = window.$gz.menu.parseMenuItem(menuItem);
|
||||
if (m.owner == FORM_KEY && !m.disabled) {
|
||||
switch (m.key) {
|
||||
case "save":
|
||||
@@ -1362,7 +1266,7 @@ async function clickHandler(menuItem) {
|
||||
m.vm.duplicate();
|
||||
break;
|
||||
case "report":
|
||||
let res = await m.vm.$refs.reportSelector.open(
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.Customer,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
@@ -1445,7 +1349,7 @@ async function clickHandler(menuItem) {
|
||||
//
|
||||
//
|
||||
function generateMenu(vm) {
|
||||
let menuOptions = {
|
||||
const menuOptions = {
|
||||
isMain: false,
|
||||
readOnly: vm.formState.readOnly,
|
||||
icon: "$ayiAddressCard",
|
||||
@@ -1480,8 +1384,6 @@ function generateMenu(vm) {
|
||||
});
|
||||
}
|
||||
|
||||
//REPORTS
|
||||
//Report not Print, print is a further option
|
||||
menuOptions.menuItems.push({
|
||||
title: "Report",
|
||||
icon: "$ayiFileAlt",
|
||||
@@ -1489,8 +1391,7 @@ function generateMenu(vm) {
|
||||
vm: vm
|
||||
});
|
||||
|
||||
//get last report selected
|
||||
let lastReport = window.$gz.form.getLastReport(FORM_KEY);
|
||||
const lastReport = window.$gz.form.getLastReport(FORM_KEY);
|
||||
if (lastReport != null) {
|
||||
menuOptions.menuItems.push({
|
||||
title: lastReport.name,
|
||||
@@ -1544,7 +1445,6 @@ function generateMenu(vm) {
|
||||
vm: vm
|
||||
});
|
||||
|
||||
//MIGRATE_OUTSTANDING show all: unitlist, quotelist, pmlist
|
||||
menuOptions.menuItems.push({
|
||||
title: "QuoteList",
|
||||
icon: "$ayiPencilAlt",
|
||||
@@ -1558,7 +1458,6 @@ function generateMenu(vm) {
|
||||
key: FORM_KEY + ":PMList",
|
||||
vm: vm
|
||||
});
|
||||
//--- /show all ---
|
||||
|
||||
menuOptions.menuItems.push({
|
||||
title: "GeoView",
|
||||
@@ -1568,7 +1467,6 @@ function generateMenu(vm) {
|
||||
});
|
||||
|
||||
menuOptions.menuItems.push({ divider: true, inset: false });
|
||||
|
||||
window.$gz.eventBus.$emit("menu-change", menuOptions);
|
||||
}
|
||||
|
||||
@@ -1580,8 +1478,6 @@ let JUST_DELETED = false;
|
||||
async function initForm(vm) {
|
||||
await fetchTranslatedText(vm);
|
||||
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
|
||||
// await populateSelectionLists(vm);
|
||||
// await cacheEnums(vm);
|
||||
await createTableHeaders(vm);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user