HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -227,30 +227,20 @@
|
||||
</v-overlay>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* Xeslint-disable */
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
const FORM_KEY = "csr-edit";
|
||||
const API_BASE_URL = "csr/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "CustomerServiceRequest"; //<-- Should always be CoreBizObject AyaType name here where possible
|
||||
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "CustomerServiceRequest";
|
||||
export default {
|
||||
async created() {
|
||||
let vm = this;
|
||||
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
|
||||
vm.rights = window.$gz.role.getRights(
|
||||
window.$gz.type.CustomerServiceRequest
|
||||
);
|
||||
vm.formState.readOnly = !vm.rights.change || vm.obj.status != 0;
|
||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||
|
||||
//id 0 means create or duplicate to new
|
||||
if (vm.$route.params.recordid != 0) {
|
||||
//is there already an obj from a prior operation?
|
||||
@@ -262,7 +252,7 @@ export default {
|
||||
loading: false
|
||||
});
|
||||
} else {
|
||||
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
|
||||
await vm.getDataFromApi(vm.$route.params.recordid);
|
||||
}
|
||||
} else {
|
||||
window.$gz.form.setFormState({
|
||||
@@ -306,50 +296,24 @@ export default {
|
||||
status: [],
|
||||
priorities: []
|
||||
},
|
||||
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
|
||||
/*{
|
||||
"data": {
|
||||
"id": 1,
|
||||
"concurrency": 3058764,
|
||||
"name": "We need to quantify the optical SQL circuit!",
|
||||
"notes": "Ab impedit unde voluptate ipsam doloremque deserunt est eos ut.",
|
||||
"wiki": null,
|
||||
"customFields": null,
|
||||
"tags": [
|
||||
"green",
|
||||
"violet"
|
||||
],
|
||||
"dateRequested": "2020-01-10T18:20:31.294229Z",
|
||||
"customerId": 28,
|
||||
"unitId": null,
|
||||
"workOrderItemId": null,
|
||||
"requestedByUserId": 48,
|
||||
"customerReferenceNumber": "65560804",
|
||||
"status": 0,
|
||||
"priority": 2
|
||||
}
|
||||
} */
|
||||
{
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
name: null,
|
||||
active: true,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
dateRequested: window.$gz.locale.nowUTC8601String(),
|
||||
customerId: null,
|
||||
unitId: null,
|
||||
workOrderItemId: null,
|
||||
requestedByUserId: null, //window.$gz.store.state.userId, for outside version of this form
|
||||
customerReferenceNumber: null,
|
||||
status: 0,
|
||||
priority: 0
|
||||
},
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
name: null,
|
||||
active: true,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
dateRequested: window.$gz.locale.nowUTC8601String(),
|
||||
customerId: null,
|
||||
unitId: null,
|
||||
workOrderItemId: null,
|
||||
requestedByUserId: null,
|
||||
customerReferenceNumber: null,
|
||||
status: 0,
|
||||
priority: 0
|
||||
},
|
||||
formState: {
|
||||
ready: false,
|
||||
dirty: false,
|
||||
@@ -364,30 +328,23 @@ export default {
|
||||
ayaType: window.$gz.type.CustomerServiceRequest
|
||||
};
|
||||
},
|
||||
//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",
|
||||
FORM_KEY + ":duplicate"
|
||||
);
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":new");
|
||||
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":reject");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit(
|
||||
@@ -395,7 +352,6 @@ export default {
|
||||
FORM_KEY + ":duplicate"
|
||||
);
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
|
||||
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":reject");
|
||||
}
|
||||
if (!val.dirty && val.valid) {
|
||||
@@ -452,7 +408,7 @@ export default {
|
||||
}
|
||||
},
|
||||
async getDataFromApi(recordId) {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
@@ -460,14 +416,10 @@ 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);
|
||||
}
|
||||
@@ -475,9 +427,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,
|
||||
@@ -496,46 +446,36 @@ 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: "csr-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,
|
||||
@@ -552,42 +492,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
|
||||
@@ -596,16 +527,14 @@ export default {
|
||||
}
|
||||
},
|
||||
async reject() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (vm.obj.status != 0 || vm.$route.params.recordid == 0) {
|
||||
return;
|
||||
}
|
||||
//change status to rejected and save
|
||||
vm.obj.status = 2; //declined=2, accepted=1
|
||||
|
||||
try {
|
||||
await this.submit();
|
||||
// navigate backwards
|
||||
vm.$router.go(-1);
|
||||
} catch (ex) {
|
||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||
@@ -619,16 +548,14 @@ export default {
|
||||
async accept() {
|
||||
//generate work order from this csr
|
||||
//flag this csr as accepted
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (vm.$route.params.recordid == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//create new workorder for this csr
|
||||
//navigate to the new workorder so it can be edited and or saved
|
||||
//workorder is responsible for flagging as fromcsr so that server can update the csr when it sees the wo is new and the fromcsrid is set
|
||||
|
||||
let w = {
|
||||
const w = {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
serial: 0,
|
||||
@@ -672,8 +599,7 @@ export default {
|
||||
isLockedAtServer: false,
|
||||
alertViz: null
|
||||
};
|
||||
|
||||
let wi = {
|
||||
const wi = {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
fromCSRId: this.obj.id,
|
||||
@@ -701,7 +627,6 @@ export default {
|
||||
units: [],
|
||||
outsideServices: []
|
||||
};
|
||||
|
||||
if (this.obj.unitId != null) {
|
||||
wi.units.push({
|
||||
id: 0,
|
||||
@@ -717,10 +642,7 @@ export default {
|
||||
warrantyViz: null
|
||||
});
|
||||
}
|
||||
|
||||
w.items.push(wi);
|
||||
|
||||
//Navigate to new record
|
||||
this.$router.push({
|
||||
name: "workorder-edit",
|
||||
params: {
|
||||
@@ -729,7 +651,6 @@ export default {
|
||||
}
|
||||
});
|
||||
}
|
||||
//end methods
|
||||
}
|
||||
};
|
||||
|
||||
@@ -740,7 +661,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":
|
||||
@@ -749,7 +670,6 @@ async function clickHandler(menuItem) {
|
||||
case "delete":
|
||||
m.vm.remove();
|
||||
break;
|
||||
|
||||
case "reject":
|
||||
m.vm.reject();
|
||||
break;
|
||||
@@ -757,7 +677,7 @@ async function clickHandler(menuItem) {
|
||||
m.vm.accept();
|
||||
break;
|
||||
case "report":
|
||||
let res = await m.vm.$refs.reportSelector.open(
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.CustomerServiceRequest,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
@@ -783,7 +703,7 @@ async function clickHandler(menuItem) {
|
||||
//
|
||||
//
|
||||
function generateMenu(vm) {
|
||||
let menuOptions = {
|
||||
const menuOptions = {
|
||||
isMain: false,
|
||||
readOnly: vm.formState.readOnly || vm.obj.status != 0,
|
||||
icon: "$ayiConciergeBell",
|
||||
@@ -822,8 +742,6 @@ function generateMenu(vm) {
|
||||
});
|
||||
}
|
||||
|
||||
//REPORTS
|
||||
//Report not Print, print is a further option
|
||||
menuOptions.menuItems.push({
|
||||
title: "Report",
|
||||
icon: "$ayiFileAlt",
|
||||
@@ -831,8 +749,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,
|
||||
@@ -863,12 +780,10 @@ function generateMenu(vm) {
|
||||
vm: vm
|
||||
});
|
||||
}
|
||||
|
||||
menuOptions.menuItems.push({ divider: true, inset: false });
|
||||
}
|
||||
window.$gz.eventBus.$emit("menu-change", menuOptions);
|
||||
}
|
||||
|
||||
let JUST_DELETED = false;
|
||||
|
||||
/////////////////////////////////
|
||||
@@ -922,12 +837,10 @@ async function fetchTranslatedText() {
|
||||
//
|
||||
//
|
||||
async function populateSelectionLists(vm) {
|
||||
//ensure the pick lists required are pre-fetched
|
||||
await window.$gz.enums.fetchEnumList("CustomerServiceRequestStatus");
|
||||
vm.selectLists.status = window.$gz.enums.getSelectionList(
|
||||
"CustomerServiceRequestStatus"
|
||||
);
|
||||
|
||||
await window.$gz.enums.fetchEnumList("CustomerServiceRequestPriority");
|
||||
vm.selectLists.priorities = window.$gz.enums.getSelectionList(
|
||||
"CustomerServiceRequestPriority"
|
||||
|
||||
Reference in New Issue
Block a user