This commit is contained in:
@@ -100,6 +100,7 @@ export default {
|
||||
addState() {
|
||||
if (this.selectedStatus != null) {
|
||||
this.value.states.push({
|
||||
workOrderId: this.value.id,
|
||||
workOrderStatusId: this.selectedStatus,
|
||||
userId: window.$gz.store.state.userId,
|
||||
created: window.$gz.locale.nowUTC8601String()
|
||||
|
||||
@@ -393,48 +393,60 @@ export default {
|
||||
vm: vm,
|
||||
loading: true
|
||||
});
|
||||
let url = API_BASE_URL; // + vm.$route.params.recordid;
|
||||
//let url = API_BASE_URL; // + vm.$route.params.recordid;
|
||||
//clear any errors vm might be around from previous submit
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
|
||||
//###############################
|
||||
//walk the tree and save dirty
|
||||
//items in order starting with
|
||||
//state here
|
||||
//items in order
|
||||
//individual save will throw on
|
||||
//exception short circuiting here
|
||||
//###############################
|
||||
let fail = false;
|
||||
|
||||
let res = await window.$gz.api.upsert(url, vm.obj);
|
||||
//STATE first
|
||||
if (!fail) await saveState(vm);
|
||||
|
||||
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
|
||||
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()
|
||||
//WOITEMS
|
||||
//if (!fail) await saveState(vm);
|
||||
|
||||
this.$router.push({
|
||||
name: "workorder-edit",
|
||||
params: {
|
||||
recordid: res.data.id,
|
||||
obj: res.data // Pass data object to new form
|
||||
}
|
||||
});
|
||||
} 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)
|
||||
vm.obj.concurrency = res.data.concurrency;
|
||||
}
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
valid: true
|
||||
});
|
||||
}
|
||||
//## UPDATE DIRTY HERE FOR WHOLE WO
|
||||
|
||||
// let res = await window.$gz.api.upsert(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
|
||||
// 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.push({
|
||||
// name: "workorder-edit",
|
||||
// params: {
|
||||
// recordid: res.data.id,
|
||||
// obj: res.data // Pass data object to new form
|
||||
// }
|
||||
// });
|
||||
// } 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)
|
||||
// vm.obj.concurrency = res.data.concurrency;
|
||||
// }
|
||||
|
||||
// //============================================== END ALL UPDATES ==================================================
|
||||
// //Update the form status
|
||||
// window.$gz.form.setFormState({
|
||||
// vm: vm,
|
||||
// dirty: false,
|
||||
// valid: true
|
||||
// });
|
||||
// }
|
||||
} catch (ex) {
|
||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||
} finally {
|
||||
@@ -528,6 +540,35 @@ export default {
|
||||
}
|
||||
};
|
||||
|
||||
//########################################## SAVE METHODS ##############################################
|
||||
|
||||
/////////////////////////////
|
||||
// STATES
|
||||
//
|
||||
async function saveState(vm) {
|
||||
//CHANGED?
|
||||
let totalItems = vm.obj.states.length;
|
||||
if (totalItems == 0) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < totalItems; i++) {
|
||||
let o = vm.obj.states[i];
|
||||
if (o.concurrency == null) {
|
||||
//it's new so save it
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
|
||||
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
return false;
|
||||
} else {
|
||||
vm.obj.states[i] = res.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//######################################### UTILITY METHODS ###########################################
|
||||
/////////////////////////////
|
||||
//
|
||||
//
|
||||
@@ -745,4 +786,196 @@ async function populateSelectionLists(vm) {
|
||||
|
||||
//---------
|
||||
}
|
||||
|
||||
/*
|
||||
Example workorder
|
||||
{
|
||||
id: 10,
|
||||
concurrency: 7728489,
|
||||
serial: 10,
|
||||
notes: "Quae officia placeat aliquid ducimus consequatur quia.",
|
||||
wiki: null,
|
||||
customFields: null,
|
||||
tags: ["green", "zone6"],
|
||||
customerId: 12,
|
||||
projectId: null,
|
||||
internalReferenceNumber: "irf-3339",
|
||||
customerReferenceNumber: "crf-1889",
|
||||
customerContactName: "contact name here",
|
||||
fromQuoteId: null,
|
||||
fromPMId: null,
|
||||
fromCSRId: null,
|
||||
serviceDate: "2021-05-29T21:25:31.421011Z",
|
||||
completeByDate: "2021-06-03T21:25:31.421011Z",
|
||||
invoiceNumber: null,
|
||||
customerSignature: null,
|
||||
customerSignatureName: null,
|
||||
customerSignatureCaptured: "0001-01-01T00:00:00Z",
|
||||
postAddress: null,
|
||||
postCity: null,
|
||||
postRegion: null,
|
||||
postCountry: null,
|
||||
postCode: null,
|
||||
address: null,
|
||||
city: null,
|
||||
region: null,
|
||||
country: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
items: [
|
||||
{
|
||||
id: 21,
|
||||
concurrency: 7728489,
|
||||
notes: "itemnotes",
|
||||
wiki: null,
|
||||
customFields: null,
|
||||
tags: [],
|
||||
workOrderId: 10,
|
||||
techNotes: "technotes",
|
||||
workorderItemStatusId: null,
|
||||
workorderItemPriorityId: null,
|
||||
requestDate: "2021-05-29T21:25:31.421011Z",
|
||||
warrantyService: false,
|
||||
isDirty: false,
|
||||
expenses: [],
|
||||
labors: [],
|
||||
loans: [],
|
||||
parts: [],
|
||||
partRequests: [],
|
||||
scheduledUsers: [
|
||||
{
|
||||
id: 41,
|
||||
concurrency: 7728489,
|
||||
userId: 15,
|
||||
estimatedQuantity: 1.0,
|
||||
startDate: null,
|
||||
stopDate: null,
|
||||
serviceRateId: null,
|
||||
isDirty: false,
|
||||
workOrderItemId: 21
|
||||
},
|
||||
{
|
||||
id: 42,
|
||||
concurrency: 7728489,
|
||||
userId: 22,
|
||||
estimatedQuantity: 2.0,
|
||||
startDate: null,
|
||||
stopDate: null,
|
||||
serviceRateId: null,
|
||||
isDirty: false,
|
||||
workOrderItemId: 21
|
||||
}
|
||||
],
|
||||
tasks: [],
|
||||
travels: [],
|
||||
units: [],
|
||||
outsideServices: []
|
||||
},
|
||||
{
|
||||
id: 22,
|
||||
concurrency: 7728489,
|
||||
notes: "itemnotes",
|
||||
wiki: null,
|
||||
customFields: null,
|
||||
tags: [],
|
||||
workOrderId: 10,
|
||||
techNotes: "technotes",
|
||||
workorderItemStatusId: null,
|
||||
workorderItemPriorityId: null,
|
||||
requestDate: "2021-05-29T21:25:31.421011Z",
|
||||
warrantyService: false,
|
||||
isDirty: false,
|
||||
expenses: [],
|
||||
labors: [],
|
||||
loans: [],
|
||||
parts: [],
|
||||
partRequests: [],
|
||||
scheduledUsers: [
|
||||
{
|
||||
id: 43,
|
||||
concurrency: 7728489,
|
||||
userId: 24,
|
||||
estimatedQuantity: 1.0,
|
||||
startDate: null,
|
||||
stopDate: null,
|
||||
serviceRateId: null,
|
||||
isDirty: false,
|
||||
workOrderItemId: 22
|
||||
},
|
||||
{
|
||||
id: 44,
|
||||
concurrency: 7728489,
|
||||
userId: 40,
|
||||
estimatedQuantity: 2.0,
|
||||
startDate: null,
|
||||
stopDate: null,
|
||||
serviceRateId: null,
|
||||
isDirty: false,
|
||||
workOrderItemId: 22
|
||||
}
|
||||
],
|
||||
tasks: [],
|
||||
travels: [],
|
||||
units: [],
|
||||
outsideServices: []
|
||||
}
|
||||
],
|
||||
states: [
|
||||
{
|
||||
id: 37,
|
||||
concurrency: 7728489,
|
||||
workOrderId: 10,
|
||||
workOrderStatusId: 2,
|
||||
created: "2021-05-29T21:30:31.421011Z",
|
||||
userId: 37,
|
||||
isDirty: false,
|
||||
workOrderStatus: null
|
||||
},
|
||||
{
|
||||
id: 38,
|
||||
concurrency: 7728489,
|
||||
workOrderId: 10,
|
||||
workOrderStatusId: 3,
|
||||
created: "2021-05-29T22:25:31.421011Z",
|
||||
userId: 10,
|
||||
isDirty: false,
|
||||
workOrderStatus: null
|
||||
},
|
||||
{
|
||||
id: 39,
|
||||
concurrency: 7728489,
|
||||
workOrderId: 10,
|
||||
workOrderStatusId: 1,
|
||||
created: "2021-05-29T22:30:31.421011Z",
|
||||
userId: 31,
|
||||
isDirty: false,
|
||||
workOrderStatus: null
|
||||
},
|
||||
{
|
||||
id: 40,
|
||||
concurrency: 7728489,
|
||||
workOrderId: 10,
|
||||
workOrderStatusId: 3,
|
||||
created: "2021-05-29T23:25:31.421011Z",
|
||||
userId: 2,
|
||||
isDirty: false,
|
||||
workOrderStatus: null
|
||||
},
|
||||
{
|
||||
id: 41,
|
||||
concurrency: 7728489,
|
||||
workOrderId: 10,
|
||||
workOrderStatusId: 9,
|
||||
created: "2021-04-06T00:10:44.636Z",
|
||||
userId: 1,
|
||||
isDirty: false,
|
||||
workOrderStatus: null
|
||||
}
|
||||
],
|
||||
isDirty: false,
|
||||
isLocked: false
|
||||
};
|
||||
|
||||
|
||||
*/
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user