This commit is contained in:
@@ -66,9 +66,12 @@ export default {
|
||||
//set base rights
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.WorkOrder);
|
||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||
let setDirty = false;
|
||||
let setValid = true;
|
||||
|
||||
//id 0 means create a new record don't load one
|
||||
//id 0 means create or duplicate to new
|
||||
if (vm.$route.params.recordid != 0) {
|
||||
//open existing path
|
||||
//is there already an obj from a prior operation?
|
||||
if (this.$route.params.obj) {
|
||||
//yes, no need to fetch it
|
||||
@@ -82,19 +85,88 @@ export default {
|
||||
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
|
||||
}
|
||||
} else {
|
||||
//NEW
|
||||
this.formState.loading = false;
|
||||
this.formState.ready = true;
|
||||
//trigger rule breaking / validation
|
||||
this.$nextTick(() => {
|
||||
this.obj.customerId = null;
|
||||
this.fieldValueChanged(`customerId`);
|
||||
});
|
||||
//new path
|
||||
if (this.$route.params.obj) {
|
||||
//DUPLICATE
|
||||
this.obj = this.$route.params.obj;
|
||||
this.obj.concurrency = undefined;
|
||||
this.obj.id = 0;
|
||||
this.obj.serial = 0;
|
||||
this.obj.isDirty = true;
|
||||
vm.obj.items.forEach(z => {
|
||||
z.id = 0;
|
||||
z.concurrency = undefined;
|
||||
z.workOrderId = 0;
|
||||
z.isDirty = true;
|
||||
z.expenses.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.labors.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.loans.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.parts.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.partRequests.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.scheduledUsers.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.tasks.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.travels.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.units.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
z.outsideServices.forEach(x => {
|
||||
x.id = 0;
|
||||
x.concurrency = undefined;
|
||||
x.isDirty = true;
|
||||
});
|
||||
});
|
||||
setDirty = true;
|
||||
} else {
|
||||
//NEW
|
||||
this.formState.loading = false;
|
||||
this.formState.ready = true;
|
||||
//trigger rule breaking / validation
|
||||
this.$nextTick(() => {
|
||||
this.obj.customerId = null;
|
||||
this.fieldValueChanged(`customerId`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
valid: true
|
||||
loading: false,
|
||||
dirty: setDirty,
|
||||
valid: setValid
|
||||
});
|
||||
|
||||
//update which areas are available to user and force generate menu
|
||||
@@ -645,41 +717,16 @@ export default {
|
||||
}
|
||||
},
|
||||
async duplicate() {
|
||||
let vm = this;
|
||||
if (!vm.canDuplicate || vm.$route.params.recordid == 0) {
|
||||
return;
|
||||
}
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
});
|
||||
let url = API_BASE_URL + "duplicate/" + vm.$route.params.recordid;
|
||||
|
||||
try {
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
let res = await window.$gz.api.upsert(url);
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
//Navigate to new record
|
||||
this.$router.push({
|
||||
name: "workorder-edit",
|
||||
params: {
|
||||
recordid: res.data.id,
|
||||
obj: res.data // Pass data object to new form
|
||||
}
|
||||
});
|
||||
//Navigate to new record
|
||||
this.$router.push({
|
||||
name: "workorder-edit",
|
||||
params: {
|
||||
recordid: 0,
|
||||
obj: this.obj
|
||||
}
|
||||
} catch (ex) {
|
||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||
} finally {
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//end methods
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user