/*Xeslint-disable */ ///Add data key names which make the custom fields control work more easily ///Since the names can be inferred from the data that comes from the server it saves bandwidth to do it here at the client function addDataKeyNames(obj) { //iterate the array of objects //if it has a "type" property then it's a custom field so add its data key name for (let i = 0; i < obj.length; i++) { if (obj[i].type) { obj[i]["dataKey"] = "c" + parseInt(obj[i].fld.replace(/^\D+/g, "")); } } //return the whole thing again now translated return obj; } export default { // cache the form customization data if it's not already present async get(formKey) { if (!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)) { //fetch and populate the store let res = await window.$gz.api.get("form-custom/" + formKey); if (res.error) { throw res.error; } window.$gz.store.commit("setFormCustomTemplateItem", { formKey: formKey, concurrency: res.data.concurrency, value: addDataKeyNames(JSON.parse(res.data.template)) }); } }, set(formKey, token, template) { window.$gz.store.commit("setFormCustomTemplateItem", { formKey: formKey, concurrency: token, value: addDataKeyNames(JSON.parse(template)) }); }, getFieldTemplateValue(formKey, fieldKey) { if (fieldKey === undefined) { throw "ERROR form-custom-template::getFieldTemplateValue -> fieldKey not specified for template for form [" + formKey + "]"; } let template = window.$gz.store.state.formCustomTemplate[formKey]; if (template === undefined) { throw "ERROR form-custom-template::getFieldTemplateValue -> Store is missing form template for [" + formKey + "]"; } //_https://lodash.com/docs#find //Note that not every field being requested will exist so it's valid to return undefined let templateItem = window.$gz._.find(template, ["fld", fieldKey]); return templateItem; }, getTemplateConcurrencyToken(formKey) { let tok = window.$gz.store.state.formCustomTemplate[formKey + "_concurrencyToken"]; if (tok === undefined) { throw "ERROR form-custom-template::getTemplateConcurrencyToken -> Store is missing concurrency token for [" + formKey + "]"; } return tok; } };