re-factor / cleanup
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
<template>
|
||||
<div>
|
||||
<gz-report-selector ref="reportSelector"></gz-report-selector>
|
||||
<v-form ref="form" v-if="formState.ready">
|
||||
<v-form v-if="formState.ready" ref="form">
|
||||
<v-row>
|
||||
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
|
||||
|
||||
<v-col cols="12">
|
||||
<gz-pick-list
|
||||
readonly
|
||||
v-model="obj.customerId"
|
||||
readonly
|
||||
:aya-type="ayaTypes().Customer"
|
||||
show-edit-icon
|
||||
:label="$ay.t('Customer')"
|
||||
@@ -17,23 +17,23 @@
|
||||
|
||||
<v-col cols="12">
|
||||
<v-textarea
|
||||
ref="notes"
|
||||
v-model="obj.notes"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('CustomerNoteNotes')"
|
||||
:error-messages="form().serverErrors(this, 'notes')"
|
||||
ref="notes"
|
||||
data-cy="notes"
|
||||
@input="fieldValueChanged('notes')"
|
||||
auto-grow
|
||||
:clearable="!formState.readOnly"
|
||||
@input="fieldValueChanged('notes')"
|
||||
></v-textarea>
|
||||
</v-col>
|
||||
|
||||
<v-col 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')"
|
||||
@@ -42,10 +42,10 @@
|
||||
|
||||
<v-col cols="12">
|
||||
<gz-date-time-picker
|
||||
:label="$ay.t('CustomerNoteNoteDate')"
|
||||
v-model="obj.noteDate"
|
||||
:readonly="formState.readOnly"
|
||||
ref="noteDate"
|
||||
v-model="obj.noteDate"
|
||||
:label="$ay.t('CustomerNoteNoteDate')"
|
||||
:readonly="formState.readOnly"
|
||||
data-cy="noteDate"
|
||||
:error-messages="form().serverErrors(this, 'noteDate')"
|
||||
@input="fieldValueChanged('noteDate')"
|
||||
@@ -62,6 +62,55 @@
|
||||
const FORM_KEY = "customer-note-edit";
|
||||
const API_BASE_URL = "customer-note/";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
selectLists: {
|
||||
usertypes: []
|
||||
},
|
||||
customername: undefined,
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
notes: null,
|
||||
noteDate: window.$gz.locale.nowUTC8601String(),
|
||||
tags: [],
|
||||
customerId: undefined,
|
||||
userId: undefined
|
||||
},
|
||||
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.CustomerNote
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
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");
|
||||
}
|
||||
if (!val.dirty && val.valid && !val.readOnly) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":new");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
@@ -121,55 +170,6 @@ export default {
|
||||
beforeDestroy() {
|
||||
window.$gz.eventBus.$off("menu-click", clickHandler);
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
selectLists: {
|
||||
usertypes: []
|
||||
},
|
||||
customername: undefined,
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
notes: null,
|
||||
noteDate: window.$gz.locale.nowUTC8601String(),
|
||||
tags: [],
|
||||
customerId: undefined,
|
||||
userId: undefined
|
||||
},
|
||||
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.CustomerNote
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
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");
|
||||
}
|
||||
if (!val.dirty && val.valid && !val.readOnly) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":new");
|
||||
} else {
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":new");
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
canSave: function() {
|
||||
return this.formState.valid && this.formState.dirty;
|
||||
@@ -336,17 +336,19 @@ async function clickHandler(menuItem) {
|
||||
});
|
||||
break;
|
||||
case "report":
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.CustomerNote,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
},
|
||||
m.id
|
||||
);
|
||||
if (res == null) {
|
||||
return;
|
||||
{
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.CustomerNote,
|
||||
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;
|
||||
default:
|
||||
window.$gz.eventBus.$emit(
|
||||
@@ -428,15 +430,15 @@ let JUST_DELETED = false;
|
||||
/////////////////////////////////
|
||||
//
|
||||
//
|
||||
async function initForm(vm) {
|
||||
await fetchTranslatedText(vm);
|
||||
async function initForm() {
|
||||
await fetchTranslatedText();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// Ensures UI translated text is available
|
||||
//
|
||||
async function fetchTranslatedText(vm) {
|
||||
async function fetchTranslatedText() {
|
||||
await window.$gz.translation.cacheTranslations([
|
||||
"CustomerNoteNotes",
|
||||
"CustomerNoteNoteDate"
|
||||
@@ -453,7 +455,7 @@ async function fetchCustomerName(vm) {
|
||||
const res = await window.$gz.api.get(
|
||||
`name/${window.$gz.type.Customer}/${vm.obj.customerId}`
|
||||
);
|
||||
if (!res.hasOwnProperty("data")) {
|
||||
if (!Object.prototype.hasOwnProperty.call(res, "data")) {
|
||||
return Promise.reject(res);
|
||||
} else {
|
||||
vm.customername = res.data;
|
||||
|
||||
Reference in New Issue
Block a user