re-factor / cleanup
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
:pvm="this"
|
||||
:goto="this.goto"
|
||||
data-cy="woItems"
|
||||
@change="setDirty()"
|
||||
class="mt-16"
|
||||
@change="setDirty()"
|
||||
/>
|
||||
</v-form>
|
||||
</div>
|
||||
@@ -35,7 +35,7 @@
|
||||
<!-- ################################################################################-->
|
||||
<template>
|
||||
<v-row justify="center">
|
||||
<v-dialog persistent max-width="600px" v-model="duplicateDlg">
|
||||
<v-dialog v-model="duplicateDlg" persistent max-width="600px">
|
||||
<v-card>
|
||||
<v-card-title>{{ duplicateDlgTitle }}</v-card-title>
|
||||
<v-card-text>
|
||||
@@ -50,7 +50,7 @@
|
||||
></v-checkbox>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn text @click="duplicateDlg = false" color="primary">{{
|
||||
<v-btn text color="primary" @click="duplicateDlg = false">{{
|
||||
$ay.t("Cancel")
|
||||
}}</v-btn>
|
||||
<v-spacer></v-spacer>
|
||||
@@ -77,6 +77,128 @@ export default {
|
||||
GzPMHeader,
|
||||
GzPMItems
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
serial: 0,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
stopGeneratingDate: null,
|
||||
excludeDaysOfWeek: 96,
|
||||
active: true,
|
||||
nextServiceDate: null,
|
||||
repeatUnit: 7,
|
||||
generateBeforeUnit: 4,
|
||||
repeatInterval: 1,
|
||||
generateBeforeInterval: 14,
|
||||
generateDate: null,
|
||||
customerId: 0, //part of rule breaking, flip to null on new triggers broken rule
|
||||
projectId: null,
|
||||
contractId: null,
|
||||
internalReferenceNumber: null,
|
||||
customerReferenceNumber: null,
|
||||
customerContactName: null,
|
||||
onsite: true,
|
||||
postAddress: null,
|
||||
postCity: null,
|
||||
postRegion: null,
|
||||
postCountry: null,
|
||||
postCode: null,
|
||||
address: null,
|
||||
city: null,
|
||||
region: null,
|
||||
country: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
items: [],
|
||||
isDirty: true,
|
||||
isLockedAtServer: false,
|
||||
alertViz: null
|
||||
},
|
||||
formState: {
|
||||
ready: false,
|
||||
dirty: false,
|
||||
valid: true,
|
||||
readOnly: false,
|
||||
loading: true,
|
||||
errorBoxMessage: null,
|
||||
appError: null,
|
||||
serverError: {}
|
||||
},
|
||||
rights: window.$gz.role.defaultRightsObject(),
|
||||
ayaType: window.$gz.type.PM,
|
||||
currencyName: window.$gz.locale.getCurrencyName(),
|
||||
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
|
||||
languageName: window.$gz.locale.getResolvedLanguage(),
|
||||
hour12: window.$gz.locale.getHour12(),
|
||||
// resetSelections: false,
|
||||
selectLists: {
|
||||
woItemPriorities: [],
|
||||
woItemStatus: [],
|
||||
woItemTaskCompletionTypes: [],
|
||||
loanUnitRateUnits: [],
|
||||
pmTimeUnits: []
|
||||
},
|
||||
maxTableNotesLength: 50, //value to cut off notes in tables
|
||||
saveResult: {
|
||||
fatal: false, //fatal error, further save is pointless, bail early and report
|
||||
errors: null //contains error objects from save
|
||||
},
|
||||
lastGetContractId: -1, //note: -1 so that a new record updates
|
||||
lastGetCustomerId: -1,
|
||||
goto: null, //{type:ayatype,id:wodescendant id} picked up by woitem when set non-null to trigger navigate to the item in question
|
||||
duplicateDlg: false,
|
||||
duplicateDlgTitle: null,
|
||||
duplicateTo: null, //"pm","wo" or "quote"
|
||||
genCopyWiki: false,
|
||||
genCopyAttachments: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
useInventory() {
|
||||
return window.$gz.store.state.globalSettings.useInventory;
|
||||
},
|
||||
alertTechNotes() {
|
||||
return this.obj.customerTechNotesViz
|
||||
? `${this.$ay.t("CustomerTechNotes")}\n${this.obj.customerTechNotesViz}`
|
||||
: null;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (val.dirty && val.valid) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
|
||||
}
|
||||
|
||||
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");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit(
|
||||
"menu-disable-item",
|
||||
FORM_KEY + ":duplicate"
|
||||
);
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const vm = this;
|
||||
|
||||
@@ -179,128 +301,6 @@ export default {
|
||||
beforeDestroy() {
|
||||
window.$gz.eventBus.$off("menu-click", clickHandler);
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
serial: 0,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
stopGeneratingDate: null,
|
||||
excludeDaysOfWeek: 96,
|
||||
active: true,
|
||||
nextServiceDate: null,
|
||||
repeatUnit: 7,
|
||||
generateBeforeUnit: 4,
|
||||
repeatInterval: 1,
|
||||
generateBeforeInterval: 14,
|
||||
generateDate: null,
|
||||
customerId: 0, //part of rule breaking, flip to null on new triggers broken rule
|
||||
projectId: null,
|
||||
contractId: null,
|
||||
internalReferenceNumber: null,
|
||||
customerReferenceNumber: null,
|
||||
customerContactName: null,
|
||||
onsite: true,
|
||||
postAddress: null,
|
||||
postCity: null,
|
||||
postRegion: null,
|
||||
postCountry: null,
|
||||
postCode: null,
|
||||
address: null,
|
||||
city: null,
|
||||
region: null,
|
||||
country: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
items: [],
|
||||
isDirty: true,
|
||||
isLockedAtServer: false,
|
||||
alertViz: null
|
||||
},
|
||||
formState: {
|
||||
ready: false,
|
||||
dirty: false,
|
||||
valid: true,
|
||||
readOnly: false,
|
||||
loading: true,
|
||||
errorBoxMessage: null,
|
||||
appError: null,
|
||||
serverError: {}
|
||||
},
|
||||
rights: window.$gz.role.defaultRightsObject(),
|
||||
ayaType: window.$gz.type.PM,
|
||||
currencyName: window.$gz.locale.getCurrencyName(),
|
||||
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
|
||||
languageName: window.$gz.locale.getResolvedLanguage(),
|
||||
hour12: window.$gz.locale.getHour12(),
|
||||
// resetSelections: false,
|
||||
selectLists: {
|
||||
woItemPriorities: [],
|
||||
woItemStatus: [],
|
||||
woItemTaskCompletionTypes: [],
|
||||
loanUnitRateUnits: [],
|
||||
pmTimeUnits: []
|
||||
},
|
||||
maxTableNotesLength: 50, //value to cut off notes in tables
|
||||
saveResult: {
|
||||
fatal: false, //fatal error, further save is pointless, bail early and report
|
||||
errors: null //contains error objects from save
|
||||
},
|
||||
lastGetContractId: -1, //note: -1 so that a new record updates
|
||||
lastGetCustomerId: -1,
|
||||
goto: null, //{type:ayatype,id:wodescendant id} picked up by woitem when set non-null to trigger navigate to the item in question
|
||||
duplicateDlg: false,
|
||||
duplicateDlgTitle: null,
|
||||
duplicateTo: null, //"pm","wo" or "quote"
|
||||
genCopyWiki: false,
|
||||
genCopyAttachments: false
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (val.dirty && val.valid) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
|
||||
}
|
||||
|
||||
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");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit(
|
||||
"menu-disable-item",
|
||||
FORM_KEY + ":duplicate"
|
||||
);
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
useInventory() {
|
||||
return window.$gz.store.state.globalSettings.useInventory;
|
||||
},
|
||||
alertTechNotes() {
|
||||
return this.obj.customerTechNotesViz
|
||||
? `${this.$ay.t("CustomerTechNotes")}\n${this.obj.customerTechNotesViz}`
|
||||
: null;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
setDirty: function() {
|
||||
//console.log("WO HEADER SET DIRTY!! TRIGGERED");
|
||||
@@ -766,6 +766,7 @@ async function saveHeader(vm) {
|
||||
//the purpose of this is to remove the child collections so only the header itself is submitted
|
||||
//this was the cleanest way I could find to accomplish this
|
||||
//https://stackoverflow.com/a/58206483/8939
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { items: removedKey1, ...headerOnly } = vm.obj;
|
||||
|
||||
//remove *Viz keys so they don't generate traffic
|
||||
@@ -832,8 +833,10 @@ async function saveItems(vm) {
|
||||
for (let i = 0; i < vm.obj.items.length; i++) {
|
||||
if (vm.obj.items[i].isDirty) {
|
||||
//get copy of item without child collections for independant submit
|
||||
/* eslint-disable no-unused-vars*/
|
||||
const {
|
||||
expenses: removedKey1,
|
||||
|
||||
labors: removedKey2,
|
||||
loans: removedKey3,
|
||||
parts: removedKey4,
|
||||
@@ -844,7 +847,7 @@ async function saveItems(vm) {
|
||||
outsideServices: removedKey10,
|
||||
...o
|
||||
} = vm.obj.items[i];
|
||||
|
||||
/* eslint-enable no-unused-vars*/
|
||||
const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
|
||||
if (res.error) {
|
||||
@@ -1684,17 +1687,19 @@ async function clickHandler(menuItem) {
|
||||
m.vm.duplicateDlg = true;
|
||||
break;
|
||||
case "report":
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.PM,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
},
|
||||
m.id
|
||||
);
|
||||
if (res == null) {
|
||||
return;
|
||||
{
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.PM,
|
||||
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 "statuslist":
|
||||
m.vm.$router.push({
|
||||
@@ -1716,18 +1721,6 @@ async function clickHandler(menuItem) {
|
||||
name: "svc-task-groups"
|
||||
});
|
||||
break;
|
||||
case "pm":
|
||||
window.$gz.eventBus.$emit("openobject", {
|
||||
type: window.$gz.type.PM,
|
||||
id: m.vm.obj.fromPMId
|
||||
});
|
||||
break;
|
||||
case "pm":
|
||||
window.$gz.eventBus.$emit("openobject", {
|
||||
type: window.$gz.type.PM,
|
||||
id: m.vm.obj.fromPMId
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
window.$gz.eventBus.$emit(
|
||||
@@ -1885,7 +1878,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 populateSelectionLists(vm);
|
||||
}
|
||||
@@ -1894,7 +1887,7 @@ async function initForm(vm) {
|
||||
//
|
||||
// Ensures UI translated text is available
|
||||
//
|
||||
async function fetchTranslatedText(vm) {
|
||||
async function fetchTranslatedText() {
|
||||
await window.$gz.translation.cacheTranslations([
|
||||
"PM",
|
||||
"PMStopGeneratingDate",
|
||||
|
||||
Reference in New Issue
Block a user