re-factor / cleanup
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<div v-if="formState.ready">
|
||||
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
|
||||
<v-form ref="form">
|
||||
<v-tabs mobile-breakpoint="100" v-model="tab">
|
||||
<v-tabs v-model="tab" mobile-breakpoint="100">
|
||||
<v-tab>{{ $ay.t("Contact") }}</v-tab>
|
||||
<v-tab>{{ $ay.t("UserSettings") }}</v-tab>
|
||||
<v-tabs-items v-model="tab">
|
||||
@@ -18,14 +18,14 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
ref="customerId"
|
||||
v-model="obj.customerId"
|
||||
:aya-type="ayaTypes().Customer"
|
||||
show-edit-icon
|
||||
:include-inactive="true"
|
||||
v-model="obj.customerId"
|
||||
:readonly="true"
|
||||
:disabled="true"
|
||||
:label="$ay.t('Customer')"
|
||||
ref="customerId"
|
||||
data-cy="customerId"
|
||||
:error-messages="form().serverErrors(this, 'customerId')"
|
||||
@input="fieldValueChanged('customerId')"
|
||||
@@ -42,14 +42,14 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-pick-list
|
||||
ref="headOfficeId"
|
||||
v-model="obj.headOfficeId"
|
||||
:aya-type="ayaTypes().HeadOffice"
|
||||
show-edit-icon
|
||||
:include-inactive="true"
|
||||
v-model="obj.headOfficeId"
|
||||
:readonly="true"
|
||||
:disabled="true"
|
||||
:label="$ay.t('HeadOffice')"
|
||||
ref="headOfficeId"
|
||||
data-cy="headOfficeId"
|
||||
:error-messages="form().serverErrors(this, 'headOfficeId')"
|
||||
@input="fieldValueChanged('headOfficeId')"
|
||||
@@ -58,12 +58,12 @@
|
||||
|
||||
<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('Name')"
|
||||
:rules="[form().required(this, 'name')]"
|
||||
:error-messages="form().serverErrors(this, 'name')"
|
||||
ref="name"
|
||||
data-cy="name"
|
||||
@input="fieldValueChanged('name')"
|
||||
></v-text-field>
|
||||
@@ -71,22 +71,23 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-role-picker
|
||||
:label="$ay.t('AuthorizationRoles')"
|
||||
v-model="obj.roles"
|
||||
:readonly="formState.readOnly"
|
||||
ref="roles"
|
||||
v-model="obj.roles"
|
||||
:label="$ay.t('AuthorizationRoles')"
|
||||
:readonly="formState.readOnly"
|
||||
data-cy="roles"
|
||||
:error-messages="form().serverErrors(this, 'roles')"
|
||||
@input="fieldValueChanged('roles')"
|
||||
limit-selection-to="outside"
|
||||
@input="fieldValueChanged('roles')"
|
||||
></gz-role-picker>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
name="username"
|
||||
id="username"
|
||||
ref="login"
|
||||
v-model="login"
|
||||
name="username"
|
||||
:readonly="formState.readOnly"
|
||||
prepend-icon="$ayiUser"
|
||||
autocomplete="off"
|
||||
@@ -95,42 +96,41 @@
|
||||
spellcheck="false"
|
||||
:label="$ay.t('NewLogin')"
|
||||
:error-messages="form().serverErrors(this, 'login')"
|
||||
ref="login"
|
||||
@input="fieldValueChanged('login')"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
name="password"
|
||||
id="password"
|
||||
ref="password"
|
||||
v-model="password"
|
||||
name="password"
|
||||
:readonly="formState.readOnly"
|
||||
:append-outer-icon="reveal ? '$ayiEye' : '$ayiEyeSlash'"
|
||||
prepend-icon="$ayiKey"
|
||||
:label="$ay.t('NewPassword')"
|
||||
:type="reveal ? 'text' : 'password'"
|
||||
:error-messages="form().serverErrors(this, 'password')"
|
||||
ref="password"
|
||||
@input="fieldValueChanged('password')"
|
||||
@click:append-outer="reveal = !reveal"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-date-time-picker
|
||||
:label="$ay.t('LastLogin')"
|
||||
v-model="obj.lastLogin"
|
||||
readonly
|
||||
ref="lastLogin"
|
||||
v-model="obj.lastLogin"
|
||||
:label="$ay.t('LastLogin')"
|
||||
readonly
|
||||
data-cy="lastLogin"
|
||||
></gz-date-time-picker>
|
||||
</v-col>
|
||||
<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')"
|
||||
@@ -138,22 +138,22 @@
|
||||
</v-col>
|
||||
<v-col v-if="form().showMe(this, 'Notes')" cols="12">
|
||||
<v-textarea
|
||||
ref="notes"
|
||||
v-model="obj.notes"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UserNotes')"
|
||||
: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')"
|
||||
@@ -162,11 +162,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')"
|
||||
@@ -175,10 +175,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
|
||||
@@ -200,13 +200,13 @@
|
||||
<v-row>
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-select
|
||||
ref="translationId"
|
||||
v-model="optionsObj.translationId"
|
||||
:items="selectLists.translations"
|
||||
item-text="name"
|
||||
item-value="id"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('Translation')"
|
||||
ref="translationId"
|
||||
:error-messages="form().serverErrors(this, 'translationId')"
|
||||
@input="fieldValueChanged('translationId')"
|
||||
></v-select>
|
||||
@@ -214,13 +214,13 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-email
|
||||
ref="emailAddress"
|
||||
v-model="optionsObj.emailAddress"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UserEmailAddress')"
|
||||
:error-messages="form().serverErrors(this, 'emailAddress')"
|
||||
ref="emailAddress"
|
||||
@input="fieldValueChanged('emailAddress')"
|
||||
data-cy="emailAddress"
|
||||
@input="fieldValueChanged('emailAddress')"
|
||||
></gz-email>
|
||||
</v-col>
|
||||
<v-col
|
||||
@@ -231,10 +231,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone1"
|
||||
v-model="optionsObj.phone1"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UserPhone1')"
|
||||
ref="phone1"
|
||||
data-cy="phone1"
|
||||
:error-messages="form().serverErrors(this, 'phone1')"
|
||||
@input="fieldValueChanged('phone1')"
|
||||
@@ -249,10 +249,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone2"
|
||||
v-model="optionsObj.phone2"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UserPhone2')"
|
||||
ref="phone2"
|
||||
data-cy="phone2"
|
||||
:error-messages="form().serverErrors(this, 'phone2')"
|
||||
@input="fieldValueChanged('phone2')"
|
||||
@@ -267,10 +267,10 @@
|
||||
xl="3"
|
||||
>
|
||||
<gz-phone
|
||||
ref="phone3"
|
||||
v-model="optionsObj.phone3"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UserPageAddress')"
|
||||
ref="phone3"
|
||||
data-cy="phone3"
|
||||
:error-messages="form().serverErrors(this, 'phone3')"
|
||||
@input="fieldValueChanged('phone3')"
|
||||
@@ -279,17 +279,17 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="mapUrlTemplate"
|
||||
v-model="optionsObj.mapUrlTemplate"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('MapUrlTemplate')"
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'mapUrlTemplate')
|
||||
"
|
||||
ref="mapUrlTemplate"
|
||||
@input="fieldValueChanged('mapUrlTemplate')"
|
||||
data-cy="mapUrlTemplate"
|
||||
:hint="obj.mapUrlTemplate == null ? 'Google maps' : ''"
|
||||
persistent-hint
|
||||
@input="fieldValueChanged('mapUrlTemplate')"
|
||||
></v-text-field>
|
||||
<v-select
|
||||
:items="selectLists.mapUrls"
|
||||
@@ -301,10 +301,10 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-checkbox
|
||||
ref="hour12"
|
||||
v-model="optionsObj.hour12"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('Hour12')"
|
||||
ref="hour12"
|
||||
:error-messages="form().serverErrors(this, 'hour12')"
|
||||
@change="fieldValueChanged('hour12')"
|
||||
></v-checkbox>
|
||||
@@ -312,6 +312,7 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="currencyName"
|
||||
v-model="optionsObj.currencyName"
|
||||
:hint="
|
||||
optionsObj.currencyName == null ||
|
||||
@@ -323,15 +324,15 @@
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('CurrencyCode')"
|
||||
:error-messages="form().serverErrors(this, 'currencyName')"
|
||||
ref="currencyName"
|
||||
@input="fieldValueChanged('currencyName')"
|
||||
append-outer-icon="$ayiQuestionCircle"
|
||||
@input="fieldValueChanged('currencyName')"
|
||||
@click:append-outer="goHelp()"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="languageOverride"
|
||||
v-model="optionsObj.languageOverride"
|
||||
:hint="locale().getResolvedLanguage()"
|
||||
persistent-hint
|
||||
@@ -340,15 +341,15 @@
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'languageOverride')
|
||||
"
|
||||
ref="languageOverride"
|
||||
@input="fieldValueChanged('languageOverride')"
|
||||
append-outer-icon="$ayiQuestionCircle"
|
||||
@input="fieldValueChanged('languageOverride')"
|
||||
@click:append-outer="goHelp()"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="timeZoneOverride"
|
||||
v-model="optionsObj.timeZoneOverride"
|
||||
:hint="locale().getResolvedTimeZoneName()"
|
||||
persistent-hint
|
||||
@@ -357,9 +358,8 @@
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'timeZoneOverride')
|
||||
"
|
||||
ref="timeZoneOverride"
|
||||
@input="fieldValueChanged('timeZoneOverride')"
|
||||
append-outer-icon="$ayiQuestionCircle"
|
||||
@input="fieldValueChanged('timeZoneOverride')"
|
||||
@click:append-outer="goHelp()"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
@@ -396,83 +396,6 @@ const API_BASE_URL = "user/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Contact"; //<--- deliberately not 'User' as is customary as this is it's own form but also edit's User type objects so needs it's own customization key
|
||||
|
||||
export default {
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
//## NOTE: This is a Contact form so follows Customer rights even though User object
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Customer);
|
||||
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;
|
||||
this.optionsObj = this.$route.params.optionsObj;
|
||||
} 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.optionsObj = this.$route.params.optionsObj;
|
||||
this.obj.concurrency = undefined;
|
||||
this.optionsObj.concurrency = undefined;
|
||||
this.obj.id = 0;
|
||||
this.optionsObj.id = 0;
|
||||
this.obj.name = `${this.obj.name} - ${window.$gz.translation.get(
|
||||
"Copy"
|
||||
)}`;
|
||||
this.password = window.$gz.util.getRandomPassword();
|
||||
setDirty = true;
|
||||
} else {
|
||||
vm.password = window.$gz.util.getRandomPassword();
|
||||
if (vm.$route.params.customerid && vm.$route.params.customerid != 0) {
|
||||
vm.obj.customerId = vm.$route.params.customerid;
|
||||
vm.obj.userType = 3;
|
||||
} else if (
|
||||
vm.$route.params.headofficeid &&
|
||||
vm.$route.params.headofficeid != 0
|
||||
) {
|
||||
vm.obj.headOfficeId = vm.$route.params.headofficeid;
|
||||
vm.obj.userType = 4;
|
||||
} else {
|
||||
//no customer or headoffice id, can't proceed
|
||||
vm.$router.go(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
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,
|
||||
@@ -559,6 +482,83 @@ export default {
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
//## NOTE: This is a Contact form so follows Customer rights even though User object
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Customer);
|
||||
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;
|
||||
this.optionsObj = this.$route.params.optionsObj;
|
||||
} 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.optionsObj = this.$route.params.optionsObj;
|
||||
this.obj.concurrency = undefined;
|
||||
this.optionsObj.concurrency = undefined;
|
||||
this.obj.id = 0;
|
||||
this.optionsObj.id = 0;
|
||||
this.obj.name = `${this.obj.name} - ${window.$gz.translation.get(
|
||||
"Copy"
|
||||
)}`;
|
||||
this.password = window.$gz.util.getRandomPassword();
|
||||
setDirty = true;
|
||||
} else {
|
||||
vm.password = window.$gz.util.getRandomPassword();
|
||||
if (vm.$route.params.customerid && vm.$route.params.customerid != 0) {
|
||||
vm.obj.customerId = vm.$route.params.customerid;
|
||||
vm.obj.userType = 3;
|
||||
} else if (
|
||||
vm.$route.params.headofficeid &&
|
||||
vm.$route.params.headofficeid != 0
|
||||
) {
|
||||
vm.obj.headOfficeId = vm.$route.params.headofficeid;
|
||||
vm.obj.userType = 4;
|
||||
} else {
|
||||
//no customer or headoffice id, can't proceed
|
||||
vm.$router.go(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
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: {
|
||||
goHelp() {
|
||||
window.open(
|
||||
@@ -840,17 +840,19 @@ async function clickHandler(menuItem) {
|
||||
m.vm.duplicate();
|
||||
break;
|
||||
case "report":
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.User,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
},
|
||||
m.id
|
||||
);
|
||||
if (res == null) {
|
||||
return;
|
||||
{
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.User,
|
||||
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 "directnotify":
|
||||
//nav to direct notify with list of users appended to route
|
||||
@@ -981,7 +983,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);
|
||||
}
|
||||
@@ -990,7 +992,7 @@ async function initForm(vm) {
|
||||
//
|
||||
// Ensures UI translated text is available
|
||||
//
|
||||
async function fetchTranslatedText(vm) {
|
||||
async function fetchTranslatedText() {
|
||||
await window.$gz.translation.cacheTranslations([
|
||||
"UserSettings",
|
||||
"Contact",
|
||||
|
||||
Reference in New Issue
Block a user