67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
/* ZZeslint-disable */
|
|
|
|
export default {
|
|
get(enumKey, enumValue) {
|
|
enumKey = enumKey.toLowerCase();
|
|
return window.$gz.store.state.enums[enumKey][enumValue];
|
|
},
|
|
//////////////////////////////////
|
|
//
|
|
// Used by forms to fetch selection list data
|
|
//
|
|
getSelectionList(enumKey) {
|
|
enumKey = enumKey.toLowerCase();
|
|
let e = window.$gz.store.state.enums[enumKey];
|
|
if (!e) {
|
|
throw "ERROR enums::getSelectionList -> enumKey " +
|
|
enumKey +
|
|
" is missing from store";
|
|
}
|
|
let ret = [];
|
|
//turn it into an array suitable for selection lists
|
|
window.$gz._.forOwn(e, function(value, key) {
|
|
ret.push({ id: Number(key), name: value });
|
|
});
|
|
return ret;
|
|
},
|
|
///////////////////////////////////
|
|
//
|
|
// Fetches enum list from server
|
|
// and puts in store. if necessary
|
|
// ACCEPTS an ARRAY or a single STRING KEY
|
|
//
|
|
async fetchEnumList(enumKey) {
|
|
if (!window.$gz._.isArray(enumKey)) {
|
|
enumKey = [enumKey];
|
|
}
|
|
for (let i = 0; i < enumKey.length; i++) {
|
|
//check if list
|
|
//if not then fetch it and store it
|
|
let k = enumKey[i].toLowerCase();
|
|
|
|
if (!window.$gz._.has(window.$gz.store.state.enums, k)) {
|
|
let that = this;
|
|
// eslint-disable-next-line
|
|
let dat = await that.fetchEnumKey(k);
|
|
//massage the data as necessary
|
|
let e = { enumKey: k, items: {} };
|
|
for (let i = 0; i < dat.length; i++) {
|
|
let o = dat[i];
|
|
e.items[o.id] = o.name;
|
|
}
|
|
//stuff the data into the store
|
|
window.$gz.store.commit("setEnum", e);
|
|
}
|
|
}
|
|
},
|
|
async fetchEnumKey(enumKey) {
|
|
// eslint-disable-next-line
|
|
let res = await window.$gz.api.get("enum-list/list/" + enumKey);
|
|
//We never expect there to be no data here
|
|
if (!res.data) {
|
|
throw res;
|
|
}
|
|
return res.data;
|
|
}
|
|
};
|