/* ZZeslint-disable */ import store from "../store"; import apiUtil from "./gzapi"; import _ from "../libs/lodash.min.js"; export default { get(key) { // debugger; if (!_.has(store.state.localeText, key)) { return "??" + key; } return store.state.localeText[key]; }, fetch(keys) { return new Promise(function fetchLocaleKeysFromServer(resolve) { //, reject //step 1: build an array of keys that we don't have already //Note: this will ensure only unique keys go into the store so it's safe to call this with dupes as can happen var needIt = []; for (var i = 0; i < keys.length; i++) { if (!_.has(store.state.localeText, keys[i])) { needIt.push(keys[i]); } } if (needIt.length == 0) { resolve(); return; } //step 2: get it fetch(apiUtil.APIUrl("locale/subset"), apiUtil.fetchPostOptions(needIt)) .then(apiUtil.status) .then(apiUtil.json) .then(response => { _.forEach(response.data, function commitFetchedLTItemToStore(item) { store.commit("addLocaleText", item); }); resolve(); }); }); }, //Keys that will always be required for any AyaNova work for any user coreKeys: [ //main nav options "Home", "Service", "Dispatch", "Inventory", "Accounting", "Administration", "Operations", "HelpAboutAyaNova", "MenuHelp", "Logout", //form required options "Active", "Add", "Cancel", "Close", "Save", "Delete", "OK", "Print", "WikiPage", "Duplicate", "RecordHistory", "ErrorFieldLengthExceeded", "ErrorStartDateAfterEndDate", "ErrorRequiredFieldEmpty", "ErrorFieldValueNotInteger", "ErrorFieldValueNotDecimal", "ErrorAPI2000", "ErrorAPI2001", "ErrorAPI2002", "ErrorAPI2003", "ErrorAPI2004", "ErrorAPI2005", "ErrorAPI2010", "ErrorAPI2020", "ErrorAPI2030", "ErrorAPI2200", "ErrorAPI2201", "ErrorAPI2202", "ErrorAPI2203", "ErrorAPI2204", "ErrorAPI2205", "ErrorAPI2206", "ErrorAPI2207", "ErrorAPI2208", "ErrorAPI2209", "ErrorServerUnresponsive", "ErrorUserNotAuthenticated" ], decimalValidate(required) { return { required: required, decimal: [2, this.formats.decimalSeparator] }; }, decimalParse(v) { if (v) { if ( this.decimalSeparator != "." && v.includes(this.formats.decimalSeparator) ) { v = v.replace(this.formats.decimalSeparator, "."); } v = parseFloat(v); } return v; }, formats: { decimalSeparator: ".", currencySymbol: "$", shortDate: "YYYY-MM-DD", shortTime: "hh:mm:ss A", shortDateAndTime: "YYYY-MM-DD hh:mm:ss A" }, //timeZoneOffset is in decimal hours timeZoneOffset: -8.0, //////////////////////////////////////////////////////// // Take in a string that contains one or more //locale keys between square brackets //translate each and return the string translated // translateString(s) { var ret = s; var pattern = /\[(.*?)\]/g; var match; while ((match = pattern.exec(s)) != null) { var foundMatch = match[0]; var ltKey = match[1]; var newValue = this.get(ltKey); ret = ret.replace(foundMatch, newValue); } return ret; } };