This commit is contained in:
2020-02-10 23:00:27 +00:00
parent 3c5890bc7b
commit abacdabd14
2 changed files with 39 additions and 47 deletions

View File

@@ -1,63 +1,33 @@
/* ZZeslint-disable */
//TODO: Need enum translator
//AuthorizationRoles.128
//window.$gz.local.enumLocalized(enumType, enumValue)
//(in locale) check if have that type already featched, if not fetches the whole list and caches it locally
//also a method to return the list of enumerated types in ID order with localized names
//window.$gz.local.enumList(enumType) - returns a list usable on edit forms
/* enums: {
AuthorizationRoles0:"No role",
AuthorizationRoles1:"Business admin limited"
etc
to get all authorization roles iterate list looking for start of key that is AuthorizationRoles
To get individual one same but only need to fetch actual value i.e. AuthorizationRoles1
if not one item starts with AuthorizationRoles then list needs to be fetched, maybe can use the enumpicklist route for that
This way entirely bypasses locale stuff
//big object so maybe it's own thing, not part of locale at all or locale fronts for it??
*/
export default {
//enums.AuthorizationRoles[0]
getEnumDisplay(enumKey, enumValue) {
// debugger;
get(enumKey, enumValue) {
enumKey = enumKey.toLowerCase();
if (!window.$gz._.has(window.$gz.store.state.localeText, key)) {
return "??" + key;
}
return window.$gz.store.state.localeText[key];
return window.$gz.store.state.enums[enumKey][enumValue];
},
///////////////////////////////////
//
// Returns an array of enum value and display objects
// for enum key specified
// e.g. [{0:"no role"},{1:"Limited role"}]
// Fetches enum list from server
// and puts in store. if necessary
//
getEnumList(enumKey) {
//debugger;
async fetchEnumList(enumKey) {
//check if list
//if not then fetch it and store it
enumKey = enumKey.toLowerCase();
if (!window.$gz._.has(window.$gz.store.state.enums, enumKey)) {
var that = this;
(async function() {
await that.fetch(enumKey).then(dat => {
//massage the data as necessary
debugger;
var e = { enumKey: enumKey, items: {} };
for (var i = 0; i < dat.length; i++) {
var o = dat[i];
e.items[o.id] = o.name;
}
//stuff the data into the store
window.$gz.store.commit("setEnum", e);
return window.$gz.store.state.enums[enumKey];
});
})();
} else {
return window.$gz.store.state.enums[enumKey];
await that.fetch(enumKey).then(dat => {
//massage the data as necessary
var e = { enumKey: enumKey, items: {} };
for (var i = 0; i < dat.length; i++) {
var o = dat[i];
e.items[o.id] = o.name;
}
//stuff the data into the store
window.$gz.store.commit("setEnum", e);
});
}
},
fetch(enumKey) {