HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -182,24 +182,17 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import EmailControl from "../components/email-control.vue";
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* Xeslint-disable */
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const FORM_KEY = "user-settings";
|
||||
const API_BASE_URL = "user-option/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "UserOptions"; //<- Should always be CoreBizObject AyaType name here
|
||||
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "UserOptions";
|
||||
export default {
|
||||
async created() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
|
||||
vm.rights = window.$gz.role.fullRightsObject(); //getRights(window.$gz.type.UserOptions);
|
||||
vm.rights = window.$gz.role.fullRightsObject();
|
||||
vm.formState.ready = true;
|
||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||
//UserOptions never creates a new one so this code is a little different than other forms
|
||||
@@ -208,7 +201,6 @@ export default {
|
||||
//OF THESE SAME FIELDS FOR THAT PURPOSE
|
||||
//SO ALWAYS USER CURRENT LOGGED IN USER ID FOR THIS
|
||||
//id 0 means create or duplicate to new but thats not applicable here
|
||||
|
||||
await vm.getDataFromApi();
|
||||
} catch (err) {
|
||||
vm.formState.ready = true;
|
||||
@@ -239,15 +231,6 @@ export default {
|
||||
activeTranslationId: null,
|
||||
darkMode: this.$store.state.darkMode,
|
||||
obj: {
|
||||
/*concurrency": 7490431,
|
||||
"translationId": 1,
|
||||
"emailAddress": null,
|
||||
"uiColor": "#000000",
|
||||
"languageOverride": null,
|
||||
"timeZoneOverride": null,
|
||||
"currencyName": "USD",
|
||||
"hour12": true,
|
||||
"userId": 1 */
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
emailAddress: null,
|
||||
@@ -275,17 +258,13 @@ export default {
|
||||
rights: window.$gz.role.defaultRightsObject()
|
||||
};
|
||||
},
|
||||
//WATCHERS
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
//,oldval is available here too if necessary
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
//enable / disable save button
|
||||
let canSave = val.dirty && val.valid && !val.readOnly;
|
||||
const canSave = val.dirty && val.valid && !val.readOnly;
|
||||
if (canSave) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
|
||||
} else {
|
||||
@@ -317,7 +296,7 @@ export default {
|
||||
return window.$gz.form;
|
||||
},
|
||||
darkModeChanged() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
vm.darkMode = !vm.darkMode;
|
||||
vm.$store.commit("setDarkMode", vm.darkMode);
|
||||
vm.$vuetify.theme.dark = vm.darkMode;
|
||||
@@ -337,93 +316,78 @@ export default {
|
||||
}
|
||||
},
|
||||
async getDataFromApi() {
|
||||
let vm = this;
|
||||
vm.formState.loading = true;
|
||||
//always fetch on this form for the current logged in user id
|
||||
let url = API_BASE_URL + vm.$store.state.userId;
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
this.formState.loading = true;
|
||||
window.$gz.form.deleteAllErrorBoxErrors(this);
|
||||
try {
|
||||
let res = await window.$gz.api.get(url);
|
||||
|
||||
const res = await window.$gz.api.get(
|
||||
API_BASE_URL + this.$store.state.userId
|
||||
);
|
||||
if (res.error) {
|
||||
//Not found?
|
||||
if (res.error.code == "2010") {
|
||||
window.$gz.form.handleObjectNotFound(vm);
|
||||
window.$gz.form.handleObjectNotFound(this);
|
||||
}
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
this.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(this);
|
||||
} else {
|
||||
vm.obj = res.data;
|
||||
vm.activeTranslationId = res.data.translationId;
|
||||
|
||||
//Update the form status
|
||||
this.obj = res.data;
|
||||
this.activeTranslationId = res.data.translationId;
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
vm: this,
|
||||
dirty: false,
|
||||
valid: true,
|
||||
loading: false
|
||||
});
|
||||
//modify the menu as necessary
|
||||
generateMenu(vm);
|
||||
generateMenu(this);
|
||||
}
|
||||
} catch (error) {
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
vm: this,
|
||||
loading: false
|
||||
});
|
||||
window.$gz.errorHandler.handleFormError(error, vm);
|
||||
window.$gz.errorHandler.handleFormError(error, this);
|
||||
}
|
||||
},
|
||||
async submit() {
|
||||
let vm = this;
|
||||
if (vm.canSave) {
|
||||
vm.formState.loading = true;
|
||||
|
||||
//always submit from this form for the current logged in user id
|
||||
let url = API_BASE_URL + vm.$store.state.userId;
|
||||
|
||||
//clear any errors vm might be around from previous submit
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
if (this.canSave) {
|
||||
this.formState.loading = true;
|
||||
window.$gz.form.deleteAllErrorBoxErrors(this);
|
||||
try {
|
||||
let res = await window.$gz.api.upsert(url, vm.obj);
|
||||
|
||||
vm.formState.loading = false;
|
||||
const res = await window.$gz.api.upsert(
|
||||
API_BASE_URL + this.$store.state.userId,
|
||||
this.obj
|
||||
);
|
||||
this.formState.loading = false;
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
this.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(this);
|
||||
} else {
|
||||
//UserOptions is never a POST as it always exists and can't be deleted so always a PUT
|
||||
|
||||
//Handle "put" of an existing record (UPDATE)
|
||||
vm.obj.concurrency = res.data.concurrency;
|
||||
this.obj.concurrency = res.data.concurrency;
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
vm: this,
|
||||
dirty: false
|
||||
});
|
||||
|
||||
//Set values in store so they are updated immediately for user
|
||||
let l = vm.$store.state.userOptions;
|
||||
l.languageOverride = vm.obj.languageOverride;
|
||||
l.timeZoneOverride = vm.obj.timeZoneOverride;
|
||||
l.currencyName = vm.obj.currencyName;
|
||||
l.hour12 = vm.obj.hour12;
|
||||
l.uiColor = vm.obj.uiColor;
|
||||
l.emailAddress = vm.obj.emailAddress;
|
||||
l.mapUrlTemplate = vm.obj.mapUrlTemplate;
|
||||
const l = this.$store.state.userOptions;
|
||||
l.languageOverride = this.obj.languageOverride;
|
||||
l.timeZoneOverride = this.obj.timeZoneOverride;
|
||||
l.currencyName = this.obj.currencyName;
|
||||
l.hour12 = this.obj.hour12;
|
||||
l.uiColor = this.obj.uiColor;
|
||||
l.emailAddress = this.obj.emailAddress;
|
||||
l.mapUrlTemplate = this.obj.mapUrlTemplate;
|
||||
window.$gz.store.commit("setUserOptions", l);
|
||||
|
||||
if (
|
||||
vm.activeTranslationId &&
|
||||
vm.activeTranslationId != vm.obj.translationId
|
||||
this.activeTranslationId &&
|
||||
this.activeTranslationId != this.obj.translationId
|
||||
) {
|
||||
await window.$gz.translation.updateCache();
|
||||
vm.activeTranslationId = vm.obj.translationId;
|
||||
this.activeTranslationId = this.obj.translationId;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
vm.formState.loading = false;
|
||||
window.$gz.errorHandler.handleFormError(error, vm);
|
||||
this.formState.loading = false;
|
||||
window.$gz.errorHandler.handleFormError(error, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -437,7 +401,7 @@ function clickHandler(menuItem) {
|
||||
if (!menuItem) {
|
||||
return;
|
||||
}
|
||||
let m = window.$gz.menu.parseMenuItem(menuItem);
|
||||
const m = window.$gz.menu.parseMenuItem(menuItem);
|
||||
if (m.owner == FORM_KEY && !m.disabled) {
|
||||
switch (m.key) {
|
||||
case "save":
|
||||
@@ -460,7 +424,7 @@ function clickHandler(menuItem) {
|
||||
//
|
||||
//
|
||||
function generateMenu(vm) {
|
||||
let menuOptions = {
|
||||
const menuOptions = {
|
||||
isMain: true,
|
||||
icon: "$ayiUserCog",
|
||||
title: "UserSettings",
|
||||
@@ -543,15 +507,12 @@ async function fetchTranslatedText(vm) {
|
||||
//
|
||||
async function populateSelectionLists(vm) {
|
||||
//http://localhost:7575/api/v8/translation/list
|
||||
let res = await window.$gz.api.get("translation/list");
|
||||
const res = await window.$gz.api.get("translation/list");
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
//window.$gz.errorHandler.handleFormError(res.error, vm);
|
||||
} else {
|
||||
vm.selectLists.translations = res.data;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
|
||||
Reference in New Issue
Block a user