99 lines
3.7 KiB
TypeScript
99 lines
3.7 KiB
TypeScript
|
|
import * as Utility from "./Utility"
|
|
import { Forms } from "./Forms"
|
|
import * as JqueryExtensions from "./JQueryExtensions"
|
|
import { loadCldr, setCulture } from "@syncfusion/ej2-base";
|
|
import * as Globalize from "globalize"
|
|
|
|
/**
|
|
* Hilfklasse die alle notwendigen Basis-Moldule lädt und initialisiert
|
|
*/
|
|
class BootStrapper {
|
|
|
|
private _initialized: boolean = false;
|
|
private _forms : Forms;
|
|
|
|
constructor() {
|
|
if (!this._initialized) {
|
|
this.init();
|
|
this._forms = Forms.getInstance("is-invalid", "is-valid");
|
|
this._forms.resetValidation();
|
|
JqueryExtensions.extendJQueryStatic();
|
|
}
|
|
}
|
|
|
|
public init(): void {
|
|
var self = this;
|
|
if (!self._initialized) {
|
|
self._initialized = true;
|
|
var currentCulture = $("html").prop("lang");
|
|
if (currentCulture) {
|
|
$.when(
|
|
$.get(`/lib/cldr-data/main/${currentCulture}/ca-gregorian.json`, null, function(data) {
|
|
loadCldr(data);
|
|
}),
|
|
$.get(`/lib/cldr-data/main/${currentCulture}/numbers.json`, null, function (data) {
|
|
loadCldr(data);
|
|
}),
|
|
$.get("/lib/cldr-data/supplemental/likelySubtags.json", null, function (data) {
|
|
loadCldr(data);
|
|
}),
|
|
$.get("/lib/cldr-data/supplemental/timeData.json", null, function (data) {
|
|
loadCldr(data);
|
|
}),
|
|
$.get("/lib/cldr-data/supplemental/weekData.json", null, function (data) {
|
|
loadCldr(data);
|
|
}),
|
|
$.get("/lib/cldr-data/supplemental/numberingSystems.json", null, function (data) {
|
|
loadCldr(data);
|
|
})
|
|
).then(function () {
|
|
// Normalize $.get results, we only need the JSON, not the request statuses.
|
|
return [].slice.apply(arguments, [0]).map(result => result[0]);
|
|
}).then(Globalize.load).then(() => {
|
|
Globalize.locale(currentCulture);
|
|
}).then(() => {
|
|
//Globales setzen der Culture für Syncfusion Controls
|
|
setCulture(currentCulture);
|
|
});
|
|
}
|
|
|
|
//Zeitzonen setzen
|
|
var offset = Utility.getTimezoneOffsetInHours();
|
|
$("input[name='jsTimezoneId']").each(function () {
|
|
$(this).val(offset);
|
|
});
|
|
|
|
//Polyfill Object.values
|
|
(<any>Object).values = (<any>Object).values ? (<any>Object).values: function (obj) {
|
|
var allowedTypes = ["[object String]", "[object Object]", "[object Array]", "[object Function]"];
|
|
var objType = Object.prototype.toString.call(obj);
|
|
|
|
if (obj === null || typeof obj === "undefined") {
|
|
throw new TypeError("Cannot convert undefined or null to object");
|
|
} else if (!~allowedTypes.indexOf(objType)) {
|
|
return [];
|
|
} else {
|
|
// if ES6 is supported
|
|
if (Object.keys) {
|
|
return Object.keys(obj).map(function (key) {
|
|
return obj[key];
|
|
});
|
|
}
|
|
|
|
var result = [];
|
|
for (var prop in obj) {
|
|
if (obj.hasOwnProperty(prop)) {
|
|
result.push(obj[prop]);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
export let bootStrapper: BootStrapper = new BootStrapper();
|