/* 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; await that.fetch(k).then(dat => { //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); }); } } }, fetch(enumKey) { return window.$gz.api.get("EnumList/List/" + enumKey).then(res => { if (res.error) { throw res.error; } return res.data; }); } };