@olenbetong/appframe-core 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/af.common.js +97 -197
- package/dist/esm/af.common.legacy.js +98 -191
- package/dist/esm/af.common.legacy.min.js +1 -29
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +1 -29
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +97 -195
- package/dist/iife/af.common.legacy.js +98 -191
- package/dist/iife/af.common.legacy.min.js +1 -29
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +1 -29
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/SessionHandler.d.ts +2 -7
- package/es/SessionHandler.js +34 -135
- package/es/UserSession.d.ts +1 -2
- package/es/UserSession.js +1 -2
- package/es/downloadRequest.js +1 -4
- package/es/expose.d.ts +1 -1
- package/es/expose.js +4 -5
- package/es/index.d.ts +3 -2
- package/es/index.js +4 -3
- package/es/localize.d.ts +14 -0
- package/es/localize.js +25 -0
- package/es/parseFunc.d.ts +1 -1
- package/es/parseFunc.js +1 -1
- package/es/requireNamespace.d.ts +1 -1
- package/es/requireNamespace.js +1 -7
- package/package.json +2 -2
- package/src/SessionHandler.ts +38 -156
- package/src/UserSession.ts +1 -2
- package/src/downloadRequest.ts +1 -4
- package/src/expose.ts +4 -5
- package/src/index.ts +3 -2
- package/src/localize.ts +29 -0
- package/src/parseFunc.ts +1 -1
- package/src/requireNamespace.ts +1 -5
- package/es/warn.d.ts +0 -1
- package/es/warn.js +0 -4
- package/src/warn.ts +0 -4
|
@@ -48,6 +48,7 @@ af.common = (() => {
|
|
|
48
48
|
getSettings: () => getSettings,
|
|
49
49
|
has: () => has,
|
|
50
50
|
localStorage: () => localStorage_default,
|
|
51
|
+
localize: () => localize,
|
|
51
52
|
mitt: () => mitt_default,
|
|
52
53
|
saveSettings: () => saveSettings,
|
|
53
54
|
version: () => version
|
|
@@ -95,184 +96,44 @@ af.common = (() => {
|
|
|
95
96
|
} };
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
// src/has.ts
|
|
99
|
-
function has(obj, key) {
|
|
100
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/getLocalizedString.ts
|
|
104
|
-
async function fetchLocalizedString(text) {
|
|
105
|
-
try {
|
|
106
|
-
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
107
|
-
body: JSON.stringify({ text }),
|
|
108
|
-
headers: {
|
|
109
|
-
Accept: "application/json; */*",
|
|
110
|
-
"Content-Type": "application/json",
|
|
111
|
-
"X-Requested-With": "XMLHttpRequest"
|
|
112
|
-
},
|
|
113
|
-
method: "POST"
|
|
114
|
-
});
|
|
115
|
-
if (response.ok) {
|
|
116
|
-
return await response.json();
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
}
|
|
120
|
-
return text;
|
|
121
|
-
}
|
|
122
|
-
function getLocalizedString(string, wait) {
|
|
123
|
-
var _a;
|
|
124
|
-
if (typeof string === "string" && string.trim().length === 0) {
|
|
125
|
-
return string;
|
|
126
|
-
}
|
|
127
|
-
if (string === void 0 || string === "" || string === null) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.i18n) !== void 0) {
|
|
131
|
-
if (!has(af.article.i18n, string)) {
|
|
132
|
-
af.article.i18n[string] = string;
|
|
133
|
-
let promise = fetchLocalizedString(string).then((text) => {
|
|
134
|
-
af.article.i18n[string] = text;
|
|
135
|
-
return text;
|
|
136
|
-
});
|
|
137
|
-
if (wait) {
|
|
138
|
-
return promise;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return af.article.i18n[string];
|
|
142
|
-
} else {
|
|
143
|
-
return string;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
99
|
// src/SessionHandler.ts
|
|
148
|
-
var
|
|
100
|
+
var SessionHandler = class {
|
|
149
101
|
constructor() {
|
|
150
102
|
__publicField(this, "eventHandler", mitt_default());
|
|
151
|
-
__publicField(this, "showingDialog", false);
|
|
152
|
-
__publicField(this, "dialog", null);
|
|
153
103
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
<div class="form-group">
|
|
180
|
-
<label for="password">${getLocalizedString("Password")}</label>
|
|
181
|
-
<input type="password" autocomplete="password" class="form-control" id="password" >
|
|
182
|
-
</div>
|
|
183
|
-
<div class="form-group">
|
|
184
|
-
<div>
|
|
185
|
-
<button type="submit" class="btn btn-default sign-in">
|
|
186
|
-
${getLocalizedString("Log in")}
|
|
187
|
-
</button>
|
|
188
|
-
</div>
|
|
189
|
-
</div>
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
<div class="row">
|
|
193
|
-
<div class="" style="display:none; margin: 0px 30px;">
|
|
194
|
-
<div class="alert alert-warning" role="alert" style="margin-top:10px;"></div>
|
|
195
|
-
</div>
|
|
196
|
-
</div>
|
|
197
|
-
</div>
|
|
198
|
-
`;
|
|
199
|
-
const message = af.userSession.login ? _SessionHandler.messages.relog : _SessionHandler.messages.login;
|
|
200
|
-
const messageElem = contentContainer.querySelector(".message");
|
|
201
|
-
const statusElem = contentContainer.querySelector(".alert-warning");
|
|
202
|
-
const userElem = contentContainer.querySelector("input[type=text]");
|
|
203
|
-
const signInElem = contentContainer.querySelector(".sign-in");
|
|
204
|
-
const passwordElem = contentContainer.querySelector("input[type=password]");
|
|
205
|
-
if (messageElem !== null && userElem !== null && statusElem !== null && userElem !== null && signInElem !== null && passwordElem !== null) {
|
|
206
|
-
messageElem.innerText = getLocalizedString(message);
|
|
207
|
-
userElem.value = af.userSession.login || "";
|
|
208
|
-
userElem.disabled = !!af.userSession.login;
|
|
209
|
-
userElem.readOnly = !!af.userSession.login;
|
|
210
|
-
document.body.appendChild(contentContainer);
|
|
211
|
-
const doLogin = async () => {
|
|
212
|
-
passwordElem.disabled = true;
|
|
213
|
-
const request = new Request("/login", {
|
|
214
|
-
body: JSON.stringify({
|
|
215
|
-
username: userElem.value,
|
|
216
|
-
password: passwordElem.value,
|
|
217
|
-
remember: false
|
|
218
|
-
}),
|
|
219
|
-
headers: {
|
|
220
|
-
Accept: "application/json",
|
|
221
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
222
|
-
"X-Requested-With": "XMLHttpRequest"
|
|
223
|
-
},
|
|
224
|
-
method: "POST"
|
|
225
|
-
});
|
|
226
|
-
try {
|
|
227
|
-
const response = await fetch(request);
|
|
228
|
-
const json = await response.json();
|
|
229
|
-
if (json.success) {
|
|
230
|
-
document.body.removeChild(contentContainer);
|
|
231
|
-
this.showingDialog = false;
|
|
232
|
-
this.eventHandler.emit("onAuthenticated");
|
|
233
|
-
if (statusElem.parentNode) {
|
|
234
|
-
statusElem.parentNode.style.display = "none";
|
|
235
|
-
}
|
|
236
|
-
} else {
|
|
237
|
-
throw new Error(json.error);
|
|
238
|
-
}
|
|
239
|
-
} catch (err) {
|
|
240
|
-
if (err && typeof err === "object") {
|
|
241
|
-
let error = err;
|
|
242
|
-
passwordElem.disabled = false;
|
|
243
|
-
passwordElem.classList.toggle("invalid", true);
|
|
244
|
-
passwordElem.value = "";
|
|
245
|
-
passwordElem.focus();
|
|
246
|
-
statusElem.innerText = error.message ? error.message : String(error);
|
|
247
|
-
if (statusElem.parentNode) {
|
|
248
|
-
statusElem.parentNode.style.display = "initial";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
signInElem.addEventListener("click", doLogin);
|
|
254
|
-
passwordElem.addEventListener("keyup", (evt) => {
|
|
255
|
-
if (evt.key === "Enter") {
|
|
256
|
-
doLogin();
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
passwordElem.addEventListener("change", (evt) => {
|
|
260
|
-
if (evt.key === "Enter") {
|
|
261
|
-
doLogin();
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
userElem.addEventListener("keyup", (evt) => {
|
|
265
|
-
if (evt.key === "Enter") {
|
|
266
|
-
doLogin();
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
userElem.addEventListener("change", (evt) => {
|
|
270
|
-
if (evt.key === "Enter") {
|
|
271
|
-
doLogin();
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
passwordElem.focus();
|
|
104
|
+
authenticated() {
|
|
105
|
+
this.eventHandler.emit("onAuthenticated");
|
|
106
|
+
}
|
|
107
|
+
async expired(callback, type) {
|
|
108
|
+
let authPromise = new Promise((resolve) => {
|
|
109
|
+
let eventHandler = () => {
|
|
110
|
+
this.eventHandler.off("onAuthenticated", eventHandler);
|
|
111
|
+
callback == null ? void 0 : callback();
|
|
112
|
+
resolve();
|
|
113
|
+
};
|
|
114
|
+
this.eventHandler.on("onAuthenticated", eventHandler);
|
|
115
|
+
});
|
|
116
|
+
let dialog = document.querySelector("dialog.session-expired-dialog");
|
|
117
|
+
if (!dialog) {
|
|
118
|
+
dialog = document.createElement("dialog");
|
|
119
|
+
dialog.className = "session-expired-dialog";
|
|
120
|
+
dialog.style.display = "flex";
|
|
121
|
+
dialog.style.padding = "0";
|
|
122
|
+
dialog.style.left = "50%";
|
|
123
|
+
dialog.style.transform = "translateX(-50%)";
|
|
124
|
+
let link = "/login?ReturnUrl=%2fapi/sessionexpired/remove";
|
|
125
|
+
if (type !== "RequireTwoFactor") {
|
|
126
|
+
await fetch("/logout", { method: "POST" });
|
|
127
|
+
} else {
|
|
128
|
+
link = "/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove";
|
|
275
129
|
}
|
|
130
|
+
dialog.innerHTML = `<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="${link}" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>`;
|
|
131
|
+
document.body.append(dialog);
|
|
132
|
+
dialog.showModal();
|
|
133
|
+
await authPromise;
|
|
134
|
+
dialog.remove();
|
|
135
|
+
} else {
|
|
136
|
+
await authPromise;
|
|
276
137
|
}
|
|
277
138
|
}
|
|
278
139
|
attachEvent(eventName, handler) {
|
|
@@ -282,11 +143,6 @@ af.common = (() => {
|
|
|
282
143
|
return this.eventHandler.off(eventName, handler);
|
|
283
144
|
}
|
|
284
145
|
};
|
|
285
|
-
var SessionHandler = _SessionHandler;
|
|
286
|
-
__publicField(SessionHandler, "messages", {
|
|
287
|
-
login: "Log in",
|
|
288
|
-
relog: "Session expired - log in"
|
|
289
|
-
});
|
|
290
146
|
|
|
291
147
|
// src/UserSession.ts
|
|
292
148
|
var UserSession = class extends SessionHandler {
|
|
@@ -311,7 +167,6 @@ af.common = (() => {
|
|
|
311
167
|
__publicField(this, "shortDateFormat", "dd.MM.yyyy");
|
|
312
168
|
__publicField(this, "culture", "en-GB");
|
|
313
169
|
__publicField(this, "uiculture", "en-GB");
|
|
314
|
-
__publicField(this, "expired", () => null);
|
|
315
170
|
this.formats = {};
|
|
316
171
|
Object.assign(this, userData);
|
|
317
172
|
}
|
|
@@ -381,7 +236,6 @@ af.common = (() => {
|
|
|
381
236
|
});
|
|
382
237
|
response = new Response(stream);
|
|
383
238
|
} catch (error) {
|
|
384
|
-
console.warn("Failed to replace response stream to log download progress.");
|
|
385
239
|
}
|
|
386
240
|
const blob = await response.blob();
|
|
387
241
|
reportProgress({ bytesReceived, status: "downloaded" });
|
|
@@ -396,6 +250,11 @@ af.common = (() => {
|
|
|
396
250
|
}
|
|
397
251
|
}
|
|
398
252
|
|
|
253
|
+
// src/has.ts
|
|
254
|
+
function has(obj, key) {
|
|
255
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
256
|
+
}
|
|
257
|
+
|
|
399
258
|
// src/parseFunc.ts
|
|
400
259
|
var funcRegex = /^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;
|
|
401
260
|
function parseFunc(func) {
|
|
@@ -424,19 +283,10 @@ af.common = (() => {
|
|
|
424
283
|
current = current[namespace[i]] = current[namespace[i]] || new Namespace_default();
|
|
425
284
|
}
|
|
426
285
|
return current;
|
|
427
|
-
} else {
|
|
428
|
-
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
429
286
|
}
|
|
430
|
-
} else {
|
|
431
|
-
throw new TypeError("Invalid type of parameter 'root'");
|
|
432
287
|
}
|
|
433
288
|
}
|
|
434
289
|
|
|
435
|
-
// src/warn.ts
|
|
436
|
-
function warn(message, fallbackToAlert) {
|
|
437
|
-
console.warn(message);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
290
|
// src/expose.ts
|
|
441
291
|
function expose(name, value) {
|
|
442
292
|
if (arguments.length !== 2) {
|
|
@@ -472,13 +322,70 @@ af.common = (() => {
|
|
|
472
322
|
throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
473
323
|
}
|
|
474
324
|
if (has(namespace, keyName)) {
|
|
475
|
-
warn([name, keyName].join(".") + " is already defined!");
|
|
325
|
+
console.warn([name, keyName].join(".") + " is already defined!");
|
|
476
326
|
} else {
|
|
477
327
|
namespace[keyName] = value;
|
|
478
328
|
}
|
|
479
329
|
}
|
|
480
330
|
}
|
|
481
331
|
|
|
332
|
+
// src/getLocalizedString.ts
|
|
333
|
+
async function fetchLocalizedString(text) {
|
|
334
|
+
try {
|
|
335
|
+
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
336
|
+
body: JSON.stringify({ text }),
|
|
337
|
+
headers: {
|
|
338
|
+
Accept: "application/json; */*",
|
|
339
|
+
"Content-Type": "application/json",
|
|
340
|
+
"X-Requested-With": "XMLHttpRequest"
|
|
341
|
+
},
|
|
342
|
+
method: "POST"
|
|
343
|
+
});
|
|
344
|
+
if (response.ok) {
|
|
345
|
+
return await response.json();
|
|
346
|
+
}
|
|
347
|
+
} catch (error) {
|
|
348
|
+
}
|
|
349
|
+
return text;
|
|
350
|
+
}
|
|
351
|
+
function getLocalizedString(string, wait) {
|
|
352
|
+
var _a;
|
|
353
|
+
if (typeof string === "string" && string.trim().length === 0) {
|
|
354
|
+
return string;
|
|
355
|
+
}
|
|
356
|
+
if (string === void 0 || string === "" || string === null) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.i18n) !== void 0) {
|
|
360
|
+
if (!has(af.article.i18n, string)) {
|
|
361
|
+
af.article.i18n[string] = string;
|
|
362
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
363
|
+
af.article.i18n[string] = text;
|
|
364
|
+
return text;
|
|
365
|
+
});
|
|
366
|
+
if (wait) {
|
|
367
|
+
return promise;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return af.article.i18n[string];
|
|
371
|
+
} else {
|
|
372
|
+
return string;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/localize.ts
|
|
377
|
+
function localize(stringParts, ...args) {
|
|
378
|
+
if (!Array.isArray(stringParts) || (stringParts == null ? void 0 : stringParts.length) || stringParts.length !== args.length + 1) {
|
|
379
|
+
throw TypeError("Method 'localize' must be used as a tag function");
|
|
380
|
+
}
|
|
381
|
+
let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : `${s}$${i}`).join("");
|
|
382
|
+
let localized = getLocalizedString(stringToLocalize);
|
|
383
|
+
args.forEach((arg, index) => {
|
|
384
|
+
localized = localized.replace("$" + index, arg);
|
|
385
|
+
});
|
|
386
|
+
return localized;
|
|
387
|
+
}
|
|
388
|
+
|
|
482
389
|
// src/localStorage.ts
|
|
483
390
|
function getLocalKey(key) {
|
|
484
391
|
var _a;
|
|
@@ -551,6 +458,6 @@ af.common = (() => {
|
|
|
551
458
|
}
|
|
552
459
|
|
|
553
460
|
// src/index.ts
|
|
554
|
-
var version = "2.0
|
|
461
|
+
var version = "2.1.0";
|
|
555
462
|
return __toCommonJS(src_exports);
|
|
556
463
|
})();
|
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
var af=af||{};af.common=(()=>{var
|
|
2
|
-
<div class="session-expired-log-in" style="margin-top: 20px;">
|
|
3
|
-
<div class="row">
|
|
4
|
-
<div class="sessionExpired">
|
|
5
|
-
<h4 class="message">Frakoblet - tidsavbrudd</h4>
|
|
6
|
-
<div class="form-group">
|
|
7
|
-
<label for="username">${y("Username")}</label>
|
|
8
|
-
<input type="text" class="form-control" id="username" autofocus>
|
|
9
|
-
</div>
|
|
10
|
-
<div class="form-group">
|
|
11
|
-
<label for="password">${y("Password")}</label>
|
|
12
|
-
<input type="password" autocomplete="password" class="form-control" id="password" >
|
|
13
|
-
</div>
|
|
14
|
-
<div class="form-group">
|
|
15
|
-
<div>
|
|
16
|
-
<button type="submit" class="btn btn-default sign-in">
|
|
17
|
-
${y("Log in")}
|
|
18
|
-
</button>
|
|
19
|
-
</div>
|
|
20
|
-
</div>
|
|
21
|
-
</div>
|
|
22
|
-
</div>
|
|
23
|
-
<div class="row">
|
|
24
|
-
<div class="" style="display:none; margin: 0px 30px;">
|
|
25
|
-
<div class="alert alert-warning" role="alert" style="margin-top:10px;"></div>
|
|
26
|
-
</div>
|
|
27
|
-
</div>
|
|
28
|
-
</div>
|
|
29
|
-
`;let o=af.userSession.login?S.messages.relog:S.messages.login,l=r.querySelector(".message"),a=r.querySelector(".alert-warning"),s=r.querySelector("input[type=text]"),p=r.querySelector(".sign-in"),c=r.querySelector("input[type=password]");if(l!==null&&s!==null&&a!==null&&s!==null&&p!==null&&c!==null){l.innerText=y(o),s.value=af.userSession.login||"",s.disabled=!!af.userSession.login,s.readOnly=!!af.userSession.login,document.body.appendChild(r);let g=async()=>{c.disabled=!0;let u=new Request("/login",{body:JSON.stringify({username:s.value,password:c.value,remember:!1}),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"});try{let d=await(await fetch(u)).json();if(d.success)document.body.removeChild(r),this.showingDialog=!1,this.eventHandler.emit("onAuthenticated"),a.parentNode&&(a.parentNode.style.display="none");else throw new Error(d.error)}catch(m){if(m&&typeof m=="object"){let d=m;c.disabled=!1,c.classList.toggle("invalid",!0),c.value="",c.focus(),a.innerText=d.message?d.message:String(d),a.parentNode&&(a.parentNode.style.display="initial")}}};p.addEventListener("click",g),c.addEventListener("keyup",u=>{u.key==="Enter"&&g()}),c.addEventListener("change",u=>{u.key==="Enter"&&g()}),s.addEventListener("keyup",u=>{u.key==="Enter"&&g()}),s.addEventListener("change",u=>{u.key==="Enter"&&g()}),c.focus()}}}attachEvent(e,n){return this.eventHandler.on(e,n)}detachEvent(e,n){return this.eventHandler.off(e,n)}},f=S;i(f,"messages",{login:"Log in",relog:"Session expired - log in"});var w=class extends f{constructor(n){super();i(this,"amDesignator","a.m.");i(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);i(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);i(this,"decimalSeparator",".");i(this,"domain","OB");i(this,"email");i(this,"formats");i(this,"groupSeparator",null);i(this,"integratedSecurity",!1);i(this,"isDeveloper",!1);i(this,"login","");i(this,"loginType");i(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);i(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);i(this,"name");i(this,"pmDesignator","p.m.");i(this,"shortDateFormat","dd.MM.yyyy");i(this,"culture","en-GB");i(this,"uiculture","en-GB");i(this,"expired",()=>null);this.formats={},Object.assign(this,n)}};function x(t,e){return new Promise(function(n,r){try{let o=URL.createObjectURL(t),l=document.body,a=document.createElement("a");a.setAttribute("download",e),a.href=o,l.append(a),a.click(),l.removeChild(a),setTimeout(function(){URL.revokeObjectURL(o),n()},250)}catch(o){r(o)}})}async function B(t,{fileName:e,signal:n,onProgress:r}){var a;function o(s){typeof r=="function"&&r(H({},s))}let l=0;o({status:"requested"});try{let s=await fetch(t);if(!s.ok||!s.body){if((a=s.headers.get("content-type"))!=null&&a.includes("application/json")){let c=await s.json();if(c.error)throw new Error(c.error)}throw new Error(`${s.status} ${s.statusText}`)}try{let c=s.body.getReader(),g=new ReadableStream({start:function(u){function m(){return c.read().then(function(d){if(d.done){u.close();return}return l+=d.value.length,o({bytesReceived:l,status:"downloading"}),u.enqueue(d.value),m()})}return m()}});s=new Response(g)}catch(c){console.warn("Failed to replace response stream to log download progress.")}let p=await s.blob();o({bytesReceived:l,status:"downloaded"}),await x(p,e),o({bytesReceived:l,status:"completed"})}catch(s){n!=null&&n.aborted?o({status:"cancelled"}):o({error:s.message,status:"error"})}}var J=/^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;function E(t){var e=t.toString().match(J);if(e===null)throw new TypeError("Unable to parse function!");return{name:e[1],args:e[2].split(","),body:e[3]}}function O(){}O.prototype=Object.create(null);var q=O;function L(t,e){if(typeof t=="object")if(typeof e=="string"){let n=e.split(".");return L(t,n)}else if(Array.isArray(e)){let n=t;for(let r=0;r<e.length;r++)n=n[e[r]]=n[e[r]]||new q;return n}else throw new TypeError("Invalid type of parameter 'namespace'");else throw new TypeError("Invalid type of parameter 'root'")}function T(t,e){console.warn(t)}function A(t,e){if(arguments.length!==2)throw new Error("Incorrect number of arguments passed to the expose function!");if(Array.isArray(e))for(let n of e){let{name:r}=E(n);if(r)A(t,n);else throw new Error("Unable to detect name of function! Name it, or only supply one function and include name in first parameter.")}else{let n,r;if(typeof e=="function"&&(n=E(e).name),typeof t=="string"){let o=t.split(".");n||(n=o[o.length-1],o=o.slice(0,o.length-1)),r=L(window,o)}else if(n&&(typeof t=="object"||typeof t=="function"))r=t;else throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");h(r,n)?T([t,n].join(".")+" is already defined!"):r[n]=e}}function z(t){var e;return[((e=af==null?void 0:af.article)==null?void 0:e.id)||"","common",t].join(".")}var N=class{isPersisted(){return!0}getLocalStorageKey(e,n){return n?["common",e].join("."):z(e)}get(e,n,r){let o=this.getLocalStorageKey(e,r),l=localStorage.getItem(o);return l!==null?JSON.parse(l):n}set(e,n,r){localStorage.setItem(this.getLocalStorageKey(e,r),JSON.stringify(n))}remove(e,n){let r=this.getLocalStorageKey(e,n);return localStorage.getItem(r)!==null?(localStorage.removeItem(r),!0):!1}clear(){let e=z("");for(let n in localStorage)n.slice(0,e.length)===e&&localStorage.removeItem(n)}},I=new N;function P(t){return`${t||af.article.id}.${af.userSession.login}`}function U(t,e){if(!(af!=null&&af.userSession))return null;let n=P(e),r=JSON.parse(localStorage.getItem(n)||"{}");return t?r[t]||null:r}function X(t,e,n){if(!(af!=null&&af.userSession))return;let r=P(n),o=JSON.parse(localStorage.getItem(r)||"{}");typeof e<"u"?o[t]=e:o=t,localStorage.setItem(r,JSON.stringify(o))}var Z="2.0.4";return C(V);})();
|
|
1
|
+
var af=af||{};af.common=(()=>{var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var S=(t,e,r)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,R=(t,e)=>{for(var r in e||(e={}))z.call(e,r)&&S(t,r,e[r]);if(E)for(var r of E(e))K.call(e,r)&&S(t,r,e[r]);return t};var k=(t,e)=>{for(var r in e)g(t,r,{get:e[r],enumerable:!0})},M=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of D(e))!z.call(t,n)&&n!==r&&g(t,n,{get:()=>e[n],enumerable:!(o=I(e,n))||o.enumerable});return t};var F=t=>M(g({},"__esModule",{value:!0}),t);var a=(t,e,r)=>(S(t,typeof e!="symbol"?e+"":e,r),r);var X={};k(X,{SessionHandler:()=>c,UserSession:()=>m,downloadBlob:()=>y,downloadRequest:()=>P,expose:()=>v,getLocalizedString:()=>h,getSettings:()=>J,has:()=>d,localStorage:()=>_,localize:()=>O,mitt:()=>p,saveSettings:()=>C,version:()=>Z});window.addEventListener("error",t=>{var e,r,o,n,i,l,s;try{let f={error:(o=(r=(e=t.error)==null?void 0:e.message)!=null?r:t.message)!=null?o:null,file:t.filename,line:(n=t.lineno)!=null?n:0,column:(i=t.colno)!=null?i:0,stack:(s=(l=t.error)==null?void 0:l.stack)!=null?s:null};fetch("/data/Logger/LogError",{body:JSON.stringify(f),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"})}catch(f){}});function p(t){return{all:t=t||new Map,on:function(e,r){var o=t.get(e);o?o.push(r):t.set(e,[r])},off:function(e,r){var o=t.get(e);o&&(r?o.splice(o.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var o=t.get(e);o&&o.slice().map(function(n){n(r)}),(o=t.get("*"))&&o.slice().map(function(n){n(e,r)})}}}var c=class{constructor(){a(this,"eventHandler",p())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(e,r){let o=new Promise(i=>{let l=()=>{this.eventHandler.off("onAuthenticated",l),e==null||e(),i()};this.eventHandler.on("onAuthenticated",l)}),n=document.querySelector("dialog.session-expired-dialog");if(n)await o;else{n=document.createElement("dialog"),n.className="session-expired-dialog",n.style.display="flex",n.style.padding="0",n.style.left="50%",n.style.transform="translateX(-50%)";let i="/login?ReturnUrl=%2fapi/sessionexpired/remove";r!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):i="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",n.innerHTML=`<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="${i}" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>`,document.body.append(n),n.showModal(),await o,n.remove()}}attachEvent(e,r){return this.eventHandler.on(e,r)}detachEvent(e,r){return this.eventHandler.off(e,r)}};var m=class extends c{constructor(r){super();a(this,"amDesignator","a.m.");a(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);a(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);a(this,"decimalSeparator",".");a(this,"domain","OB");a(this,"email");a(this,"formats");a(this,"groupSeparator",null);a(this,"integratedSecurity",!1);a(this,"isDeveloper",!1);a(this,"login","");a(this,"loginType");a(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);a(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);a(this,"name");a(this,"pmDesignator","p.m.");a(this,"shortDateFormat","dd.MM.yyyy");a(this,"culture","en-GB");a(this,"uiculture","en-GB");this.formats={},Object.assign(this,r)}};function y(t,e){return new Promise(function(r,o){try{let n=URL.createObjectURL(t),i=document.body,l=document.createElement("a");l.setAttribute("download",e),l.href=n,i.append(l),l.click(),i.removeChild(l),setTimeout(function(){URL.revokeObjectURL(n),r()},250)}catch(n){o(n)}})}async function P(t,{fileName:e,signal:r,onProgress:o}){var l;function n(s){typeof o=="function"&&o(R({},s))}let i=0;n({status:"requested"});try{let s=await fetch(t);if(!s.ok||!s.body){if((l=s.headers.get("content-type"))!=null&&l.includes("application/json")){let u=await s.json();if(u.error)throw new Error(u.error)}throw new Error(`${s.status} ${s.statusText}`)}try{let u=s.body.getReader(),q=new ReadableStream({start:function(L){function j(){return u.read().then(function(w){if(w.done){L.close();return}return i+=w.value.length,n({bytesReceived:i,status:"downloading"}),L.enqueue(w.value),j()})}return j()}});s=new Response(q)}catch(u){}let f=await s.blob();n({bytesReceived:i,status:"downloaded"}),await y(f,e),n({bytesReceived:i,status:"completed"})}catch(s){r!=null&&r.aborted?n({status:"cancelled"}):n({error:s.message,status:"error"})}}function d(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var U=/^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;function b(t){var e=t.toString().match(U);if(e===null)throw new TypeError("Unable to parse function!");return{name:e[1],args:e[2].split(","),body:e[3]}}function N(){}N.prototype=Object.create(null);var T=N;function x(t,e){if(typeof t=="object"){if(typeof e=="string"){let r=e.split(".");return x(t,r)}else if(Array.isArray(e)){let r=t;for(let o=0;o<e.length;o++)r=r[e[o]]=r[e[o]]||new T;return r}}}function v(t,e){if(arguments.length!==2)throw new Error("Incorrect number of arguments passed to the expose function!");if(Array.isArray(e))for(let r of e){let{name:o}=b(r);if(o)v(t,r);else throw new Error("Unable to detect name of function! Name it, or only supply one function and include name in first parameter.")}else{let r,o;if(typeof e=="function"&&(r=b(e).name),typeof t=="string"){let n=t.split(".");r||(r=n[n.length-1],n=n.slice(0,n.length-1)),o=x(window,n)}else if(r&&(typeof t=="object"||typeof t=="function"))o=t;else throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");d(o,r)?console.warn([t,r].join(".")+" is already defined!"):o[r]=e}}async function B(t){try{let e=await fetch(`/api/user/localize/new/${af.article.id}`,{body:JSON.stringify({text:t}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(e.ok)return await e.json()}catch(e){}return t}function h(t,e){var r;if(typeof t=="string"&&t.trim().length===0)return t;if(!(t===void 0||t===""||t===null))if(((r=af==null?void 0:af.article)==null?void 0:r.i18n)!==void 0){if(!d(af.article.i18n,t)){af.article.i18n[t]=t;let o=B(t).then(n=>(af.article.i18n[t]=n,n));if(e)return o}return af.article.i18n[t]}else return t}function O(t,...e){if(!Array.isArray(t)||(t==null?void 0:t.length)||t.length!==e.length+1)throw TypeError("Method 'localize' must be used as a tag function");let r=t.map((n,i)=>i===t.length-1?n:`${n}$${i}`).join(""),o=h(r);return e.forEach((n,i)=>{o=o.replace("$"+i,n)}),o}function H(t){var e;return[((e=af==null?void 0:af.article)==null?void 0:e.id)||"","common",t].join(".")}var A=class{isPersisted(){return!0}getLocalStorageKey(e,r){return r?["common",e].join("."):H(e)}get(e,r,o){let n=this.getLocalStorageKey(e,o),i=localStorage.getItem(n);return i!==null?JSON.parse(i):r}set(e,r,o){localStorage.setItem(this.getLocalStorageKey(e,o),JSON.stringify(r))}remove(e,r){let o=this.getLocalStorageKey(e,r);return localStorage.getItem(o)!==null?(localStorage.removeItem(o),!0):!1}clear(){let e=H("");for(let r in localStorage)r.slice(0,e.length)===e&&localStorage.removeItem(r)}},_=new A;function $(t){return`${t||af.article.id}.${af.userSession.login}`}function J(t,e){if(!(af!=null&&af.userSession))return null;let r=$(e),o=JSON.parse(localStorage.getItem(r)||"{}");return t?o[t]||null:o}function C(t,e,r){if(!(af!=null&&af.userSession))return;let o=$(r),n=JSON.parse(localStorage.getItem(o)||"{}");typeof e<"u"?n[t]=e:n=t,localStorage.setItem(o,JSON.stringify(n))}var Z="2.1.0";return F(X);})();
|
|
30
2
|
//# sourceMappingURL=af.common.legacy.min.js.map
|