/* ZZeslint-disable */ export default { get(enumKey, enumValue) { enumKey = enumKey.toLowerCase(); if (enumKey != "authorizationroles") { if (window.$gz.store.state.enums[enumKey] == undefined) { throw "ERROR enums::get -> enumKey " + enumKey + " is missing from store"; } return window.$gz.store.state.enums[enumKey][enumValue]; } else { let ret = []; if (enumValue == null || enumValue == 0) { return ""; } let availableRoles = this.getSelectionList("AuthorizationRoles"); for (let i = 0; i < availableRoles.length; i++) { let role = availableRoles[i]; if (!!(enumValue & role.id)) { ret.push(role.name); } } return ret.join(", "); } }, ////////////////////////////////// // // Used by forms to fetch selection list data // Sorts alphabetically by default but can be turned off with do not sort // getSelectionList(enumKey, doNotSort) { 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 }); }); if (doNotSort == true) { return ret; } else { return window.$gz._.sortBy(ret, "name"); } }, /////////////////////////////////// // // 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.hasOwnProperty("data")) { throw res; } return res.data; } };