270 lines
7.0 KiB
JavaScript
270 lines
7.0 KiB
JavaScript
/* ZZeslint-disable */
|
|
|
|
export default {
|
|
get(key) {
|
|
// debugger;
|
|
if (!window.$gz._.has(window.$gz.store.state.localeText, key)) {
|
|
return "??" + key;
|
|
}
|
|
return window.$gz.store.state.localeText[key];
|
|
},
|
|
fetch(keys) {
|
|
return new Promise(function fetchLocaleKeysFromServer(resolve) {
|
|
//
|
|
//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
|
|
//for example datatables have dynamic column names so they need to fetch on demand
|
|
var needIt = [];
|
|
for (var i = 0; i < keys.length; i++) {
|
|
if (!window.$gz._.has(window.$gz.store.state.localeText, keys[i])) {
|
|
needIt.push(keys[i]);
|
|
}
|
|
}
|
|
|
|
if (needIt.length == 0) {
|
|
resolve();
|
|
return;
|
|
}
|
|
|
|
//step 2: get it
|
|
fetch(
|
|
window.$gz.api.APIUrl("locale/subset"),
|
|
window.$gz.api.fetchPostOptions(needIt)
|
|
)
|
|
.then(window.$gz.api.status)
|
|
.then(window.$gz.api.json)
|
|
.then(response => {
|
|
window.$gz._.forEach(
|
|
response.data,
|
|
function commitFetchedLTItemToStore(item) {
|
|
window.$gz.store.commit("addLocaleText", item);
|
|
}
|
|
);
|
|
|
|
resolve();
|
|
});
|
|
});
|
|
},
|
|
//Keys that will always be required for any AyaNova work for any user
|
|
coreKeys: [
|
|
//main nav options
|
|
"Home",
|
|
"Dashboard",
|
|
"Schedule",
|
|
"MemoList",
|
|
"UserSettings",
|
|
"Locale",
|
|
"SetLoginPassword",
|
|
"NotifySubscriptionList",
|
|
"UserPreferences",
|
|
"Service",
|
|
"ClientList",
|
|
"HeadOfficeList",
|
|
"WorkorderServiceList",
|
|
"WorkorderServiceTemplate",
|
|
"WorkorderQuoteList",
|
|
"WorkorderQuoteTemplate",
|
|
"WorkorderPreventiveMaintenanceList",
|
|
"WorkorderPreventiveMaintenanceTemplate",
|
|
"UnitList",
|
|
"UnitModels",
|
|
"ContractList",
|
|
"ClientServiceRequestList",
|
|
"LoanItemList",
|
|
"PartList",
|
|
"PartByWarehouseInventoryList",
|
|
"WorkorderItemPartRequestList",
|
|
"InventoryPurchaseOrders",
|
|
"InventoryPurchaseOrderReceipts",
|
|
"InventoryPartInventoryAdjustments",
|
|
"WidgetList",
|
|
"VendorList",
|
|
"AdministrationGlobalSettings",
|
|
"HelpLicense",
|
|
"UserList",
|
|
"LocalizedTextDesign",
|
|
"ReportList",
|
|
"ReminderList",
|
|
"Inventory",
|
|
"Accounting",
|
|
"Administration",
|
|
"Operations",
|
|
"Attachments",
|
|
"Review",
|
|
"History",
|
|
"Statistics",
|
|
"Backup",
|
|
"ServerJobs",
|
|
"ServerLog",
|
|
"ServerMetrics",
|
|
"NotificationSettings",
|
|
"HelpAboutAyaNova",
|
|
"MenuHelp",
|
|
"More",
|
|
"Logout",
|
|
//form required options
|
|
"Active",
|
|
"Add",
|
|
"Cancel",
|
|
"Close",
|
|
"Save",
|
|
"Delete",
|
|
"OK",
|
|
"Print",
|
|
"Report",
|
|
"WikiPage",
|
|
"Duplicate",
|
|
"RecordHistory",
|
|
"Search",
|
|
"TypeToSearchOrAdd",
|
|
"NoData",
|
|
"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",
|
|
"ErrorUserNotAuthorized",
|
|
"DeletePrompt",
|
|
"AreYouSureUnsavedChanges",
|
|
"Leave",
|
|
"Copy",
|
|
"Tags",
|
|
"Customize",
|
|
"ObjectCustomFieldCustomGrid",
|
|
"RowsPerPage",
|
|
"PageOfPageText",
|
|
"Loading",
|
|
"AM",
|
|
"PM"
|
|
],
|
|
decimalValidate(required) {
|
|
return { required: required, decimal: [2, this.format().decimalSeparator] };
|
|
},
|
|
decimalParse(v) {
|
|
if (v) {
|
|
if (
|
|
this.decimalSeparator != "." &&
|
|
v.includes(this.format().decimalSeparator)
|
|
) {
|
|
v = v.replace(this.format().decimalSeparator, ".");
|
|
}
|
|
v = parseFloat(v);
|
|
}
|
|
return v;
|
|
},
|
|
format() {
|
|
return window.$gz.store.state.locale;
|
|
},
|
|
////////////////////////////////////////////////////////
|
|
// 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;
|
|
},
|
|
////////////////////////////////////////////////////////
|
|
// attempt to determine user's preferred language settings
|
|
// As of Jan 2020 all major browsers support
|
|
// navigator.languages
|
|
// but some use navigator.language (singular) to denote UI language preference
|
|
// not browsing language preference
|
|
// so the ideal way to do this is to use navigator.languages[0] for the preferred language
|
|
// and ignore the singular property since we don't care about the actual browser UI language
|
|
// only how the user expects to see the page itself
|
|
//
|
|
// also for sake of future proofing and edge cases need to have it be manually settable as well
|
|
// ############### TODO: modify all of these to put the user's manual override first in line (if there is one)
|
|
getBrowserLanguages() {
|
|
return window.navigator.languages;
|
|
},
|
|
getBrowserFirstLanguage() {
|
|
return window.navigator.languages[0];
|
|
},
|
|
///////////////////////////////////////////
|
|
// Get users default time zone
|
|
//
|
|
getTimeZoneName() {
|
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
},
|
|
///////////////////////////////////////////
|
|
// Turn a utc date into a displayable
|
|
// short date and time
|
|
//
|
|
utcDateToShortDateAndTimeLocalized(
|
|
value,
|
|
timeZoneName,
|
|
languageName,
|
|
hour12
|
|
) {
|
|
if (!value) {
|
|
return "";
|
|
}
|
|
if (!timeZoneName) {
|
|
timeZoneName = this.getTimeZoneName();
|
|
}
|
|
if (!languageName) {
|
|
languageName = this.getBrowserLanguages();
|
|
}
|
|
|
|
if (!hour12) {
|
|
hour12 = window.$gz.store.state.locale.hour12;
|
|
}
|
|
|
|
//parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z")
|
|
var parsedDate = new Date(value);
|
|
|
|
//is it a valid date?
|
|
if (!(parsedDate instanceof Date && !isNaN(parsedDate))) {
|
|
return "not valid";
|
|
}
|
|
|
|
return parsedDate.toLocaleString(languageName, {
|
|
timeZone: timeZoneName,
|
|
dateStyle: "short",
|
|
timeStyle: "short",
|
|
hour12: hour12
|
|
});
|
|
},
|
|
////////////////////////////////////////////////////////
|
|
// dynamically set the vuetify language elements from
|
|
// users localized text (am/pm etc)
|
|
// Keeping vuetify using en locale and just adjusting on top of that
|
|
//
|
|
setVuetifyDefaultLanguageElements(vm) {
|
|
vm.$vuetify.lang.locales.en.close = this.get("OK");
|
|
vm.$vuetify.lang.locales.en.timePicker.am = this.get("AM");
|
|
vm.$vuetify.lang.locales.en.timePicker.pm = this.get("PM");
|
|
}
|
|
};
|