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("User") }}</v-tab>
|
||||
<v-tab>{{ $ay.t("UserSettings") }}</v-tab>
|
||||
<v-tabs-items v-model="tab">
|
||||
@@ -12,25 +12,25 @@
|
||||
<v-row>
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="name"
|
||||
v-model="obj.name"
|
||||
:readonly="formState.readOnly"
|
||||
:disabled="obj.id === 1"
|
||||
: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>
|
||||
</v-col>
|
||||
<v-col v-if="obj.userType == 5" cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-pick-list
|
||||
ref="vendorId"
|
||||
v-model="obj.vendorId"
|
||||
:aya-type="ayaTypes().Vendor"
|
||||
show-edit-icon
|
||||
v-model="obj.vendorId"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('Vendor')"
|
||||
ref="vendorId"
|
||||
data-cy="vendorId"
|
||||
:error-messages="form().serverErrors(this, 'vendorId')"
|
||||
@input="fieldValueChanged('vendorId')"
|
||||
@@ -44,13 +44,13 @@
|
||||
xl="3"
|
||||
>
|
||||
<v-text-field
|
||||
ref="employeeNumber"
|
||||
v-model="obj.employeeNumber"
|
||||
:readonly="formState.readOnly"
|
||||
:label="$ay.t('UserEmployeeNumber')"
|
||||
:error-messages="
|
||||
form().serverErrors(this, 'employeeNumber')
|
||||
"
|
||||
ref="employeeNumber"
|
||||
data-cy="employeeNumber"
|
||||
@input="fieldValueChanged('employeeNumber')"
|
||||
></v-text-field>
|
||||
@@ -58,20 +58,21 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<gz-role-picker
|
||||
:label="$ay.t('AuthorizationRoles')"
|
||||
ref="roles"
|
||||
v-model="obj.roles"
|
||||
:label="$ay.t('AuthorizationRoles')"
|
||||
:readonly="formState.readOnly"
|
||||
:disabled="obj.id === 1"
|
||||
ref="roles"
|
||||
data-cy="roles"
|
||||
:error-messages="form().serverErrors(this, 'roles')"
|
||||
@input="fieldValueChanged('roles')"
|
||||
limit-selection-to="inside"
|
||||
@input="fieldValueChanged('roles')"
|
||||
></gz-role-picker>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-select
|
||||
ref="usertype"
|
||||
v-model="obj.userType"
|
||||
:items="selectLists.usertypes"
|
||||
item-text="name"
|
||||
@@ -79,7 +80,6 @@
|
||||
:readonly="formState.readOnly"
|
||||
:disabled="obj.id === 1"
|
||||
:label="$ay.t('UserType')"
|
||||
ref="usertype"
|
||||
data-cy="usertype"
|
||||
:rules="[form().integerValid(this, 'usertype')]"
|
||||
:error-messages="form().serverErrors(this, 'usertype')"
|
||||
@@ -89,9 +89,10 @@
|
||||
|
||||
<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"
|
||||
@@ -100,23 +101,22 @@
|
||||
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>
|
||||
@@ -129,20 +129,20 @@
|
||||
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"
|
||||
:disabled="obj.id === 1"
|
||||
:label="$ay.t('Active')"
|
||||
ref="active"
|
||||
data-cy="active"
|
||||
:error-messages="form().serverErrors(this, 'active')"
|
||||
@change="fieldValueChanged('active')"
|
||||
@@ -150,22 +150,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')"
|
||||
@@ -174,11 +174,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')"
|
||||
@@ -187,10 +187,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
|
||||
@@ -212,13 +212,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>
|
||||
@@ -226,13 +226,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
|
||||
@@ -243,10 +243,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')"
|
||||
@@ -261,10 +261,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')"
|
||||
@@ -279,10 +279,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')"
|
||||
@@ -291,17 +291,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"
|
||||
@@ -313,10 +313,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>
|
||||
@@ -324,6 +324,7 @@
|
||||
|
||||
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||
<v-text-field
|
||||
ref="currencyName"
|
||||
v-model="optionsObj.currencyName"
|
||||
:hint="
|
||||
optionsObj.currencyName == null ||
|
||||
@@ -335,15 +336,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
|
||||
@@ -352,15 +353,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
|
||||
@@ -369,9 +370,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>
|
||||
@@ -407,69 +407,6 @@ const API_BASE_URL = "user/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "User";
|
||||
|
||||
export default {
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.User);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -558,6 +495,69 @@ export default {
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.User);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -848,17 +848,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":
|
||||
if (m.vm.obj.id == 0) {
|
||||
|
||||
Reference in New Issue
Block a user