61 lines
1.6 KiB
JavaScript
61 lines
1.6 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 picklist data
|
|
//
|
|
getPickList(enumKey) {
|
|
enumKey = enumKey.toLowerCase();
|
|
var e = window.$gz.store.state.enums[enumKey];
|
|
if (!e) {
|
|
throw "ERROR enums::getPickList -> enumKey " +
|
|
enumKey +
|
|
" is missing from store";
|
|
}
|
|
var ret = [];
|
|
//turn it into an array suitable for picklists
|
|
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
|
|
//
|
|
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;
|
|
|
|
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) {
|
|
return window.$gz.api.get("EnumPickList/list/" + enumKey).then(res => {
|
|
if (res.error) {
|
|
throw res.error;
|
|
}
|
|
return res.data;
|
|
});
|
|
}
|
|
};
|