re-factor / cleanup
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
<v-row>
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="name"
|
||||
v-model="obj.name"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartName')"
|
||||
:rules="[form().required(this, 'name')]"
|
||||
:error-messages="form().serverErrors(this, 'name')"
|
||||
ref="name"
|
||||
data-cy="name"
|
||||
@input="fieldValueChanged('name')"
|
||||
></v-text-field>
|
||||
@@ -26,10 +26,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="description"
|
||||
v-model="obj.description"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartDescription')"
|
||||
ref="description"
|
||||
data-cy="description"
|
||||
:error-messages="form().serverErrors(this, 'description')"
|
||||
@input="fieldValueChanged('description')"
|
||||
@@ -38,10 +38,10 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-currency
|
||||
ref="rateYear"
|
||||
v-model="obj.cost"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartCost')"
|
||||
ref="rateYear"
|
||||
data-cy="rateYear"
|
||||
:rules="[
|
||||
form().decimalValid(this, 'cost'),
|
||||
@@ -54,10 +54,10 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-currency
|
||||
ref="rateYear"
|
||||
v-model="obj.retail"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartRetail')"
|
||||
ref="rateYear"
|
||||
data-cy="rateYear"
|
||||
:rules="[
|
||||
form().decimalValid(this, 'retail'),
|
||||
@@ -76,14 +76,14 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-combobox
|
||||
ref="unitOfMeasure"
|
||||
v-model="obj.unitOfMeasure"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UnitOfMeasure')"
|
||||
ref="unitOfMeasure"
|
||||
data-cy="unitOfMeasure"
|
||||
:error-messages="form().serverErrors(this, 'unitOfMeasure')"
|
||||
@input="fieldValueChanged('unitOfMeasure')"
|
||||
:items="selectLists.priorUnits"
|
||||
@input="fieldValueChanged('unitOfMeasure')"
|
||||
></v-combobox>
|
||||
</v-col>
|
||||
|
||||
@@ -95,10 +95,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="upc"
|
||||
v-model="obj.upc"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartUPC')"
|
||||
ref="upc"
|
||||
data-cy="upc"
|
||||
:error-messages="form().serverErrors(this, 'upc')"
|
||||
@input="fieldValueChanged('upc')"
|
||||
@@ -113,12 +113,12 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
ref="manufacturerId"
|
||||
v-model="obj.manufacturerId"
|
||||
:aya-type="ayaTypes().Vendor"
|
||||
show-edit-icon
|
||||
v-model="obj.manufacturerId"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartManufacturerID')"
|
||||
ref="manufacturerId"
|
||||
data-cy="manufacturerId"
|
||||
:error-messages="form().serverErrors(this, 'manufacturerId')"
|
||||
@input="fieldValueChanged('manufacturerId')"
|
||||
@@ -133,10 +133,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="manufacturerNumber"
|
||||
v-model="obj.manufacturerNumber"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartManufacturerNumber')"
|
||||
ref="manufacturerNumber"
|
||||
data-cy="manufacturerNumber"
|
||||
:error-messages="form().serverErrors(this, 'manufacturerNumber')"
|
||||
@input="fieldValueChanged('manufacturerNumber')"
|
||||
@@ -151,12 +151,12 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
ref="wholeSalerId"
|
||||
v-model="obj.wholeSalerId"
|
||||
:aya-type="ayaTypes().Vendor"
|
||||
show-edit-icon
|
||||
v-model="obj.wholeSalerId"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartWholesalerID')"
|
||||
ref="wholeSalerId"
|
||||
data-cy="wholeSalerId"
|
||||
:error-messages="form().serverErrors(this, 'wholeSalerId')"
|
||||
@input="fieldValueChanged('wholeSalerId')"
|
||||
@@ -171,10 +171,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="wholeSalerNumber"
|
||||
v-model="obj.wholeSalerNumber"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartWholesalerNumber')"
|
||||
ref="wholeSalerNumber"
|
||||
data-cy="wholeSalerNumber"
|
||||
:error-messages="form().serverErrors(this, 'wholeSalerNumber')"
|
||||
@input="fieldValueChanged('wholeSalerNumber')"
|
||||
@@ -189,12 +189,12 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
ref="alternativeWholeSalerId"
|
||||
v-model="obj.alternativeWholeSalerId"
|
||||
:aya-type="ayaTypes().Vendor"
|
||||
show-edit-icon
|
||||
v-model="obj.alternativeWholeSalerId"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartAlternativeWholesalerID')"
|
||||
ref="alternativeWholeSalerId"
|
||||
data-cy="alternativeWholeSalerId"
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'alternativeWholeSalerId')
|
||||
@@ -211,10 +211,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="alternativeWholeSalerNumber"
|
||||
v-model="obj.alternativeWholeSalerNumber"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartAlternativeWholesalerNumber')"
|
||||
ref="alternativeWholeSalerNumber"
|
||||
data-cy="alternativeWholeSalerNumber"
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'alternativeWholeSalerNumber')
|
||||
@@ -226,10 +226,10 @@
|
||||
<!-- --------------------------------- -->
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-checkbox
|
||||
ref="active"
|
||||
v-model="obj.active"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('Active')"
|
||||
ref="active"
|
||||
data-cy="active"
|
||||
:error-messages="form().serverErrors(this, 'active')"
|
||||
@change="fieldValueChanged('active')"
|
||||
@@ -238,22 +238,22 @@
|
||||
|
||||
<v-col v-if="form().showMe(this, 'Notes')" cols="12">
|
||||
<v-textarea
|
||||
ref="notes"
|
||||
v-model="obj.notes"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('PartNotes')"
|
||||
:error-messages="form().serverErrors(this, 'notes')"
|
||||
ref="notes"
|
||||
data-cy="notes"
|
||||
@input="fieldValueChanged('notes')"
|
||||
auto-grow
|
||||
@input="fieldValueChanged('notes')"
|
||||
></v-textarea>
|
||||
</v-col>
|
||||
|
||||
<v-col v-if="form().showMe(this, 'Tags')" cols="12">
|
||||
<gz-tag-picker
|
||||
ref="tags"
|
||||
v-model="obj.tags"
|
||||
:readonly="formState.readOnly"
|
||||
ref="tags"
|
||||
data-cy="tags"
|
||||
:error-messages="form().serverErrors(this, 'tags')"
|
||||
@input="fieldValueChanged('tags')"
|
||||
@@ -262,11 +262,11 @@
|
||||
|
||||
<v-col cols="12">
|
||||
<gz-custom-fields
|
||||
ref="customFields"
|
||||
v-model="obj.customFields"
|
||||
:form-key="formCustomTemplateKey"
|
||||
:readonly="formState.readOnly"
|
||||
:parent-v-m="this"
|
||||
ref="customFields"
|
||||
data-cy="customFields"
|
||||
:error-messages="form().serverErrors(this, 'customFields')"
|
||||
@input="fieldValueChanged('customFields')"
|
||||
@@ -275,10 +275,10 @@
|
||||
|
||||
<v-col v-if="form().showMe(this, 'Wiki')" cols="12">
|
||||
<gz-wiki
|
||||
:aya-type="ayaType"
|
||||
:aya-id="obj.id"
|
||||
ref="wiki"
|
||||
v-model="obj.wiki"
|
||||
:aya-type="ayaType"
|
||||
:aya-id="obj.id"
|
||||
:readonly="formState.readOnly"
|
||||
@input="fieldValueChanged('wiki')"
|
||||
></gz-wiki
|
||||
@@ -304,63 +304,6 @@ const FORM_KEY = "inv-part-edit";
|
||||
const API_BASE_URL = "part/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Part";
|
||||
export default {
|
||||
async created() {
|
||||
const vm = this;
|
||||
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Part);
|
||||
vm.formState.readOnly = !vm.rights.change;
|
||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||
let setDirty = false;
|
||||
//id 0 means create or duplicate to new
|
||||
if (vm.$route.params.recordid != 0) {
|
||||
//is there already an obj from a prior operation?
|
||||
if (this.$route.params.obj) {
|
||||
//yes, no need to fetch it
|
||||
this.obj = this.$route.params.obj;
|
||||
} else {
|
||||
await vm.getDataFromApi(vm.$route.params.recordid);
|
||||
}
|
||||
} else {
|
||||
//Might be a duplicate and contain another record
|
||||
if (this.$route.params.obj) {
|
||||
this.obj = this.$route.params.obj;
|
||||
this.obj.concurrency = undefined;
|
||||
this.obj.id = 0;
|
||||
this.obj.name = `${this.obj.name} - ${window.$gz.translation.get(
|
||||
"Copy"
|
||||
)}`;
|
||||
setDirty = true;
|
||||
}
|
||||
}
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false,
|
||||
dirty: setDirty,
|
||||
valid: true
|
||||
});
|
||||
generateMenu(vm);
|
||||
} catch (error) {
|
||||
window.$gz.errorHandler.handleFormError(error, vm);
|
||||
} finally {
|
||||
vm.formState.ready = true;
|
||||
}
|
||||
},
|
||||
async beforeRouteLeave(to, from, next) {
|
||||
if (!this.formState.dirty || JUST_DELETED) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
|
||||
next();
|
||||
} else {
|
||||
next(false);
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.$gz.eventBus.$off("menu-click", clickHandler);
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
|
||||
@@ -373,7 +316,6 @@ export default {
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
name: null,
|
||||
description: null,
|
||||
manufacturerId: null,
|
||||
manufacturerNumber: null,
|
||||
@@ -431,6 +373,63 @@ export default {
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const vm = this;
|
||||
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Part);
|
||||
vm.formState.readOnly = !vm.rights.change;
|
||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||
let setDirty = false;
|
||||
//id 0 means create or duplicate to new
|
||||
if (vm.$route.params.recordid != 0) {
|
||||
//is there already an obj from a prior operation?
|
||||
if (this.$route.params.obj) {
|
||||
//yes, no need to fetch it
|
||||
this.obj = this.$route.params.obj;
|
||||
} else {
|
||||
await vm.getDataFromApi(vm.$route.params.recordid);
|
||||
}
|
||||
} else {
|
||||
//Might be a duplicate and contain another record
|
||||
if (this.$route.params.obj) {
|
||||
this.obj = this.$route.params.obj;
|
||||
this.obj.concurrency = undefined;
|
||||
this.obj.id = 0;
|
||||
this.obj.name = `${this.obj.name} - ${window.$gz.translation.get(
|
||||
"Copy"
|
||||
)}`;
|
||||
setDirty = true;
|
||||
}
|
||||
}
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false,
|
||||
dirty: setDirty,
|
||||
valid: true
|
||||
});
|
||||
generateMenu(vm);
|
||||
} catch (error) {
|
||||
window.$gz.errorHandler.handleFormError(error, vm);
|
||||
} finally {
|
||||
vm.formState.ready = true;
|
||||
}
|
||||
},
|
||||
async beforeRouteLeave(to, from, next) {
|
||||
if (!this.formState.dirty || JUST_DELETED) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
|
||||
next();
|
||||
} else {
|
||||
next(false);
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.$gz.eventBus.$off("menu-click", clickHandler);
|
||||
},
|
||||
methods: {
|
||||
canSave: function() {
|
||||
return this.formState.valid && this.formState.dirty;
|
||||
@@ -609,17 +608,19 @@ async function clickHandler(menuItem) {
|
||||
m.vm.duplicate();
|
||||
break;
|
||||
case "report":
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.Part,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
},
|
||||
m.id
|
||||
);
|
||||
if (res == null) {
|
||||
return;
|
||||
{
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.Part,
|
||||
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 "PartSerialNumbersAvailable":
|
||||
m.vm.$router.push({
|
||||
@@ -847,7 +848,7 @@ let JUST_DELETED = false;
|
||||
//
|
||||
async function initForm(vm) {
|
||||
await populateSelectionLists(vm);
|
||||
await fetchTranslatedText(vm);
|
||||
await fetchTranslatedText();
|
||||
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
|
||||
}
|
||||
|
||||
@@ -868,7 +869,7 @@ async function populateSelectionLists(vm) {
|
||||
//
|
||||
// Ensures UI translated text is available
|
||||
//
|
||||
async function fetchTranslatedText(vm) {
|
||||
async function fetchTranslatedText() {
|
||||
await window.$gz.translation.cacheTranslations([
|
||||
"Part",
|
||||
"PartByWarehouseInventoryList",
|
||||
|
||||
Reference in New Issue
Block a user