@olenbetong/appframe-core 2.7.1 → 2.7.3

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.
@@ -184,6 +184,43 @@ var af;
184
184
  });
185
185
  }
186
186
 
187
+ // src/localStorage.ts
188
+ function getLocalKey(key) {
189
+ return [af?.article?.id || "", "common", key].join(".");
190
+ }
191
+ var LocalStorage = class {
192
+ isPersisted = () => true;
193
+ getLocalStorageKey(key, global) {
194
+ return global ? ["common", key].join(".") : getLocalKey(key);
195
+ }
196
+ get(key, defaultValue, global) {
197
+ const lsKey = this.getLocalStorageKey(key, global);
198
+ const value = localStorage.getItem(lsKey);
199
+ return value !== null ? JSON.parse(value) : defaultValue;
200
+ }
201
+ set(key, value, global) {
202
+ localStorage.setItem(this.getLocalStorageKey(key, global), JSON.stringify(value));
203
+ }
204
+ remove(key, global) {
205
+ const lsKey = this.getLocalStorageKey(key, global);
206
+ if (localStorage.getItem(lsKey) !== null) {
207
+ localStorage.removeItem(lsKey);
208
+ return true;
209
+ } else {
210
+ return false;
211
+ }
212
+ }
213
+ clear() {
214
+ const baseKey = getLocalKey("");
215
+ for (let key in localStorage) {
216
+ if (key.slice(0, baseKey.length) === baseKey) {
217
+ localStorage.removeItem(key);
218
+ }
219
+ }
220
+ }
221
+ };
222
+ var localStorage_default = new LocalStorage();
223
+
187
224
  // src/date.ts
188
225
  function toLocalISODate(date) {
189
226
  return date ? toLocalISODateTime(date).substring(0, 10) : null;
@@ -429,45 +466,6 @@ var af;
429
466
  return localized;
430
467
  }
431
468
 
432
- // src/localStorage.ts
433
- function getLocalKey(key) {
434
- return [af?.article?.id || "", "common", key].join(".");
435
- }
436
- var LocalStorage = class {
437
- isPersisted() {
438
- return true;
439
- }
440
- getLocalStorageKey(key, global) {
441
- return global ? ["common", key].join(".") : getLocalKey(key);
442
- }
443
- get(key, defaultValue, global) {
444
- const lsKey = this.getLocalStorageKey(key, global);
445
- const value = localStorage.getItem(lsKey);
446
- return value !== null ? JSON.parse(value) : defaultValue;
447
- }
448
- set(key, value, global) {
449
- localStorage.setItem(this.getLocalStorageKey(key, global), JSON.stringify(value));
450
- }
451
- remove(key, global) {
452
- const lsKey = this.getLocalStorageKey(key, global);
453
- if (localStorage.getItem(lsKey) !== null) {
454
- localStorage.removeItem(lsKey);
455
- return true;
456
- } else {
457
- return false;
458
- }
459
- }
460
- clear() {
461
- const baseKey = getLocalKey("");
462
- for (let key in localStorage) {
463
- if (key.slice(0, baseKey.length) === baseKey) {
464
- localStorage.removeItem(key);
465
- }
466
- }
467
- }
468
- };
469
- var localStorage_default = new LocalStorage();
470
-
471
469
  // src/logActivity.ts
472
470
  async function logActivity(activity, parameters, timeElapsed = 0) {
473
471
  try {
@@ -547,7 +545,11 @@ var af;
547
545
  dialog.addEventListener("close", resolve, { once: true });
548
546
  });
549
547
  }
550
- async function openAlertDialog({ buttons, content, className }) {
548
+ var alertDialogPromiseMap = /* @__PURE__ */ new Map();
549
+ async function openAlertDialog({ buttons, content, className, id, title }) {
550
+ if (id && alertDialogPromiseMap.has(id)) {
551
+ return await alertDialogPromiseMap.get(id);
552
+ }
551
553
  let $template = document.querySelector("#AlertDialogTemplate");
552
554
  if (!$template)
553
555
  throw Error("No alert dialog template found");
@@ -557,7 +559,12 @@ var af;
557
559
  if (!$dialog || !$content || !$menu)
558
560
  throw Error("Invalid alert dialog template");
559
561
  if (className) {
560
- $dialog.classList.add(className);
562
+ className.split(/\s+/).forEach((className2) => $dialog?.classList.add(className2));
563
+ }
564
+ if (title) {
565
+ let $header = document.createElement("header");
566
+ $header.append(title);
567
+ $content.parentNode?.insertBefore($header, $content);
561
568
  }
562
569
  $content.appendChild(typeof content === "string" ? document.createTextNode(content) : content);
563
570
  for (let { label, value, primary } of buttons) {
@@ -573,39 +580,48 @@ var af;
573
580
  }
574
581
  document.body.appendChild($dialog);
575
582
  $dialog.showModal();
576
- await waitForDialog($dialog);
577
- let result = $dialog.returnValue || "cancel";
578
- document.body.removeChild($dialog);
579
- return result;
583
+ let dialogPromise = waitForDialog($dialog).then(() => {
584
+ if (id && alertDialogPromiseMap.has(id)) {
585
+ alertDialogPromiseMap.delete(id);
586
+ }
587
+ }).then(() => {
588
+ let result = $dialog?.returnValue || "cancel";
589
+ if ($dialog)
590
+ document.body.removeChild($dialog);
591
+ return result;
592
+ });
593
+ if (id) {
594
+ alertDialogPromiseMap.set(id, dialogPromise);
595
+ }
596
+ return await dialogPromise;
580
597
  }
581
598
  var ConfirmButtons = /* @__PURE__ */ ((ConfirmButtons2) => {
582
599
  ConfirmButtons2[ConfirmButtons2["YesNo"] = 0] = "YesNo";
583
600
  ConfirmButtons2[ConfirmButtons2["OkCancel"] = 1] = "OkCancel";
584
601
  return ConfirmButtons2;
585
602
  })(ConfirmButtons || {});
586
- async function confirm(prompt, button = 0 /* YesNo */) {
587
- let buttons = [
603
+ async function confirm(prompt, options = {}) {
604
+ let { buttons: optionButtons = 0 /* YesNo */, title } = options;
605
+ let buttons = optionButtons === 1 /* OkCancel */ ? [
606
+ { label: getLocalizedString("OK"), value: "yes", primary: true },
607
+ { label: getLocalizedString("Cancel"), value: "no" }
608
+ ] : [
588
609
  { label: getLocalizedString("Yes"), value: "yes", primary: true },
589
610
  { label: getLocalizedString("No"), value: "no" }
590
611
  ];
591
- if (button == 1 /* OkCancel */) {
592
- buttons = [
593
- { label: getLocalizedString("OK"), value: "yes", primary: true },
594
- { label: getLocalizedString("Cancel"), value: "no" }
595
- ];
596
- }
597
- let result = await openAlertDialog({ content: prompt, buttons, className: "alert-dialog-confirm" });
612
+ let result = await openAlertDialog({ content: prompt, buttons, className: "alert-dialog-confirm", title });
598
613
  return result === "yes";
599
614
  }
600
- async function alert(prompt) {
615
+ async function alert(prompt, options = {}) {
601
616
  await openAlertDialog({
602
617
  content: prompt,
603
618
  className: "alert-dialog-alert",
604
- buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }]
619
+ buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }],
620
+ ...options
605
621
  });
606
622
  }
607
623
 
608
624
  // src/index.ts
609
- var version = "2.7.1";
625
+ var version = "2.7.3";
610
626
  return __toCommonJS(src_exports);
611
627
  })();
@@ -206,6 +206,46 @@ af.common = (() => {
206
206
  });
207
207
  }
208
208
 
209
+ // src/localStorage.ts
210
+ function getLocalKey(key) {
211
+ var _a2;
212
+ return [((_a2 = af == null ? void 0 : af.article) == null ? void 0 : _a2.id) || "", "common", key].join(".");
213
+ }
214
+ var LocalStorage = class {
215
+ constructor() {
216
+ __publicField(this, "isPersisted", () => true);
217
+ }
218
+ getLocalStorageKey(key, global) {
219
+ return global ? ["common", key].join(".") : getLocalKey(key);
220
+ }
221
+ get(key, defaultValue, global) {
222
+ const lsKey = this.getLocalStorageKey(key, global);
223
+ const value = localStorage.getItem(lsKey);
224
+ return value !== null ? JSON.parse(value) : defaultValue;
225
+ }
226
+ set(key, value, global) {
227
+ localStorage.setItem(this.getLocalStorageKey(key, global), JSON.stringify(value));
228
+ }
229
+ remove(key, global) {
230
+ const lsKey = this.getLocalStorageKey(key, global);
231
+ if (localStorage.getItem(lsKey) !== null) {
232
+ localStorage.removeItem(lsKey);
233
+ return true;
234
+ } else {
235
+ return false;
236
+ }
237
+ }
238
+ clear() {
239
+ const baseKey = getLocalKey("");
240
+ for (let key in localStorage) {
241
+ if (key.slice(0, baseKey.length) === baseKey) {
242
+ localStorage.removeItem(key);
243
+ }
244
+ }
245
+ }
246
+ };
247
+ var localStorage_default = new LocalStorage();
248
+
209
249
  // src/date.ts
210
250
  function toLocalISODate(date) {
211
251
  return date ? toLocalISODateTime(date).substring(0, 10) : null;
@@ -453,46 +493,6 @@ af.common = (() => {
453
493
  return localized;
454
494
  }
455
495
 
456
- // src/localStorage.ts
457
- function getLocalKey(key) {
458
- var _a2;
459
- return [((_a2 = af == null ? void 0 : af.article) == null ? void 0 : _a2.id) || "", "common", key].join(".");
460
- }
461
- var LocalStorage = class {
462
- isPersisted() {
463
- return true;
464
- }
465
- getLocalStorageKey(key, global) {
466
- return global ? ["common", key].join(".") : getLocalKey(key);
467
- }
468
- get(key, defaultValue, global) {
469
- const lsKey = this.getLocalStorageKey(key, global);
470
- const value = localStorage.getItem(lsKey);
471
- return value !== null ? JSON.parse(value) : defaultValue;
472
- }
473
- set(key, value, global) {
474
- localStorage.setItem(this.getLocalStorageKey(key, global), JSON.stringify(value));
475
- }
476
- remove(key, global) {
477
- const lsKey = this.getLocalStorageKey(key, global);
478
- if (localStorage.getItem(lsKey) !== null) {
479
- localStorage.removeItem(lsKey);
480
- return true;
481
- } else {
482
- return false;
483
- }
484
- }
485
- clear() {
486
- const baseKey = getLocalKey("");
487
- for (let key in localStorage) {
488
- if (key.slice(0, baseKey.length) === baseKey) {
489
- localStorage.removeItem(key);
490
- }
491
- }
492
- }
493
- };
494
- var localStorage_default = new LocalStorage();
495
-
496
496
  // src/logActivity.ts
497
497
  async function logActivity(activity, parameters, timeElapsed = 0) {
498
498
  var _a2;
@@ -573,8 +573,12 @@ af.common = (() => {
573
573
  dialog.addEventListener("close", resolve, { once: true });
574
574
  });
575
575
  }
576
- async function openAlertDialog({ buttons, content, className }) {
577
- var _a2;
576
+ var alertDialogPromiseMap = /* @__PURE__ */ new Map();
577
+ async function openAlertDialog({ buttons, content, className, id, title }) {
578
+ var _a2, _b;
579
+ if (id && alertDialogPromiseMap.has(id)) {
580
+ return await alertDialogPromiseMap.get(id);
581
+ }
578
582
  let $template = document.querySelector("#AlertDialogTemplate");
579
583
  if (!$template)
580
584
  throw Error("No alert dialog template found");
@@ -584,7 +588,12 @@ af.common = (() => {
584
588
  if (!$dialog || !$content || !$menu)
585
589
  throw Error("Invalid alert dialog template");
586
590
  if (className) {
587
- $dialog.classList.add(className);
591
+ className.split(/\s+/).forEach((className2) => $dialog == null ? void 0 : $dialog.classList.add(className2));
592
+ }
593
+ if (title) {
594
+ let $header = document.createElement("header");
595
+ $header.append(title);
596
+ (_b = $content.parentNode) == null ? void 0 : _b.insertBefore($header, $content);
588
597
  }
589
598
  $content.appendChild(typeof content === "string" ? document.createTextNode(content) : content);
590
599
  for (let { label, value, primary } of buttons) {
@@ -600,39 +609,47 @@ af.common = (() => {
600
609
  }
601
610
  document.body.appendChild($dialog);
602
611
  $dialog.showModal();
603
- await waitForDialog($dialog);
604
- let result = $dialog.returnValue || "cancel";
605
- document.body.removeChild($dialog);
606
- return result;
612
+ let dialogPromise = waitForDialog($dialog).then(() => {
613
+ if (id && alertDialogPromiseMap.has(id)) {
614
+ alertDialogPromiseMap.delete(id);
615
+ }
616
+ }).then(() => {
617
+ let result = ($dialog == null ? void 0 : $dialog.returnValue) || "cancel";
618
+ if ($dialog)
619
+ document.body.removeChild($dialog);
620
+ return result;
621
+ });
622
+ if (id) {
623
+ alertDialogPromiseMap.set(id, dialogPromise);
624
+ }
625
+ return await dialogPromise;
607
626
  }
608
627
  var ConfirmButtons = /* @__PURE__ */ ((ConfirmButtons2) => {
609
628
  ConfirmButtons2[ConfirmButtons2["YesNo"] = 0] = "YesNo";
610
629
  ConfirmButtons2[ConfirmButtons2["OkCancel"] = 1] = "OkCancel";
611
630
  return ConfirmButtons2;
612
631
  })(ConfirmButtons || {});
613
- async function confirm(prompt, button = 0 /* YesNo */) {
614
- let buttons = [
632
+ async function confirm(prompt, options = {}) {
633
+ let { buttons: optionButtons = 0 /* YesNo */, title } = options;
634
+ let buttons = optionButtons === 1 /* OkCancel */ ? [
635
+ { label: getLocalizedString("OK"), value: "yes", primary: true },
636
+ { label: getLocalizedString("Cancel"), value: "no" }
637
+ ] : [
615
638
  { label: getLocalizedString("Yes"), value: "yes", primary: true },
616
639
  { label: getLocalizedString("No"), value: "no" }
617
640
  ];
618
- if (button == 1 /* OkCancel */) {
619
- buttons = [
620
- { label: getLocalizedString("OK"), value: "yes", primary: true },
621
- { label: getLocalizedString("Cancel"), value: "no" }
622
- ];
623
- }
624
- let result = await openAlertDialog({ content: prompt, buttons, className: "alert-dialog-confirm" });
641
+ let result = await openAlertDialog({ content: prompt, buttons, className: "alert-dialog-confirm", title });
625
642
  return result === "yes";
626
643
  }
627
- async function alert(prompt) {
628
- await openAlertDialog({
644
+ async function alert(prompt, options = {}) {
645
+ await openAlertDialog(__spreadValues({
629
646
  content: prompt,
630
647
  className: "alert-dialog-alert",
631
648
  buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }]
632
- });
649
+ }, options));
633
650
  }
634
651
 
635
652
  // src/index.ts
636
- var version = "2.7.1";
653
+ var version = "2.7.3";
637
654
  return __toCommonJS(src_exports);
638
655
  })();
@@ -1,4 +1,4 @@
1
- var af=af||{};af.common=(()=>{var b=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var D=(e,t,n)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))U.call(t,n)&&D(e,n,t[n]);if(H)for(var n of H(t))ee.call(t,n)&&D(e,n,t[n]);return e};var te=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Q(t))!U.call(e,r)&&r!==n&&b(e,r,{get:()=>t[r],enumerable:!(o=G(t,r))||o.enumerable});return e};var re=e=>ne(b({},"__esModule",{value:!0}),e);var a=(e,t,n)=>(D(e,typeof t!="symbol"?t+"":t,n),n);var ce={};te(ce,{ConfirmButtons:()=>O,SessionHandler:()=>m,UserSession:()=>w,alert:()=>W,confirm:()=>Y,downloadBlob:()=>v,downloadRequest:()=>P,expose:()=>E,getLocalizedString:()=>u,getSettings:()=>Z,getUserImage:()=>j,has:()=>y,invariant:()=>c,localStorage:()=>K,localize:()=>F,logActivity:()=>$,mitt:()=>S,openAlertDialog:()=>A,saveSettings:()=>X,startActivity:()=>J,toLocalISODate:()=>M,toLocalISODateTime:()=>I,version:()=>se,waitForDialog:()=>N});function S(e){return{all:e=e||new Map,on:function(t,n){var o=e.get(t);o?o.push(n):e.set(t,[n])},off:function(t,n){var o=e.get(t);o&&(n?o.splice(o.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var o=e.get(t);o&&o.slice().map(function(r){r(n)}),(o=e.get("*"))&&o.slice().map(function(r){r(t,n)})}}}var m=class{constructor(){a(this,"eventHandler",S())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,n){try{let o=new Promise(i=>{let s=()=>{this.eventHandler.off("onAuthenticated",s),t==null||t(),i()};this.eventHandler.on("onAuthenticated",s)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await o;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let i="/login?ReturnUrl=%2fapi/sessionexpired/remove";n!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):i="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.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(r),r.showModal(),await o,r.remove()}}catch(o){window.location.href=`/login?ReturnUrl=${encodeURIComponent(window.location.pathname)}${encodeURIComponent(window.location.search)}`}}attachEvent(t,n){return this.eventHandler.on(t,n)}detachEvent(t,n){return this.eventHandler.off(t,n)}};var w=class extends m{constructor(n){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,n)}};var q;(q=window.window)==null||q.addEventListener("error",e=>{var t,n,o,r,i,s,l;try{let f={error:(o=(n=(t=e.error)==null?void 0:t.message)!=null?n:e.message)!=null?o:null,file:e.filename,line:(r=e.lineno)!=null?r:0,column:(i=e.colno)!=null?i:0,stack:(l=(s=e.error)==null?void 0:s.stack)!=null?l: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 M(e){return e?I(e).substring(0,10):null}function p(e){return String(e).padStart(2,"0")}function I(e){return e?`${e.getFullYear()}-${p(e.getMonth()+1)}-${p(e.getDate())}T${p(e.getHours())}:${p(e.getMinutes())}:${p(e.getSeconds())}.${p(e.getMilliseconds())}`:null}function v(e,t){return new Promise(function(n,o){try{let r=URL.createObjectURL(e),i=document.body,s=document.createElement("a");s.setAttribute("download",t),s.href=r,i.append(s),s.click(),i.removeChild(s),setTimeout(function(){URL.revokeObjectURL(r),n()},250)}catch(r){o(r)}})}function c(e,t){if(e)return;let n=typeof t=="function"?t():t;throw new Error(n!=null?n:"Invariant failed")}async function P(e,{fileName:t,signal:n,onProgress:o}){var s;function r(l){typeof o=="function"&&o(C({},l))}let i=0;r({status:"requested"});try{let l=await fetch(e);if(!l.ok||!l.body){if((s=l.headers.get("content-type"))!=null&&s.includes("application/json")){let g=await l.json();c(!g.error,g.error)}throw new Error(`${l.status} ${l.statusText}`)}try{let g=l.body.getReader(),L=new ReadableStream({start:function(h){function x(){return g.read().then(function(d){if(d.done){h.close();return}return i+=d.value.length,r({bytesReceived:i,status:"downloading"}),h.enqueue(d.value),x()})}return x()}});l=new Response(L)}catch(g){}let f=await l.blob();r({bytesReceived:i,status:"downloaded"}),await v(f,t),r({bytesReceived:i,status:"completed"})}catch(l){n!=null&&n.aborted?r({status:"cancelled"}):r({error:l.message,status:"error"})}}function y(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var oe=/^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 z(e){var t=e.toString().match(oe);return c(t,"Unable to parse function!"),{name:t[1],args:t[2].split(","),body:t[3]}}function _(){}_.prototype=Object.create(null);var k=_;function T(e,t){if(typeof e=="object"){if(typeof t=="string"){let n=t.split(".");return T(e,n)}else if(Array.isArray(t)){let n=e;for(let o=0;o<t.length;o++)n=n[t[o]]=n[t[o]]||new k;return n}}}function E(e,t,n={}){if(Array.isArray(t))for(let o of t){let{name:r}=z(o);c(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),E(e,o)}else{let o,r;if(typeof t=="function"&&(o=z(t).name),typeof e=="string"){let i=e.split(".");o||(o=i[i.length-1],i=i.slice(0,i.length-1)),r=T(window,i)}else o&&(typeof e=="object"||typeof e=="function")?r=e:c(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");y(r,o)&&(n==null?void 0:n.overwrite)!==!0?console.warn([e,o].join(".")+" is already defined!"):r[o]=t}}var ie={xs:64,sm:128,md:256,lg:512,xl:void 0};function j(e,t,n,o="xs"){if(e&&typeof e=="object")return j(e.primKey,e.login,e.hash,e.size);if(!e||!n)return"";let r=ie[o];return`/api/data/blob/EmployeesLookup/${e}/Image/${encodeURIComponent(t!=null?t:"")}${t?".":""}${encodeURIComponent(n)}.jpg${r?`?width=${r}`:""}`}async function ae(e){try{let t=await fetch(`/api/user/localize/new/${af.article.id}`,{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function u(e,t){var n;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((n=af==null?void 0:af.article)==null?void 0:n.i18n)!==void 0){if(!y(af.article.i18n,e)){af.article.i18n[e]=e;let o=ae(e).then(r=>(af.article.i18n[e]=r,r));if(t)return o}return af.article.i18n[e]}else return e}function F(e,...t){c(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let n=e.map((r,i)=>i===e.length-1?r:`${r}$${i}`).join(""),o=u(n);return t.forEach((r,i)=>{o=o.replace("$"+i,r)}),o}function B(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var R=class{isPersisted(){return!0}getLocalStorageKey(t,n){return n?["common",t].join("."):B(t)}get(t,n,o){let r=this.getLocalStorageKey(t,o),i=localStorage.getItem(r);return i!==null?JSON.parse(i):n}set(t,n,o){localStorage.setItem(this.getLocalStorageKey(t,o),JSON.stringify(n))}remove(t,n){let o=this.getLocalStorageKey(t,n);return localStorage.getItem(o)!==null?(localStorage.removeItem(o),!0):!1}clear(){let t=B("");for(let n in localStorage)n.slice(0,t.length)===t&&localStorage.removeItem(n)}},K=new R;async function $(e,t,n=0){var o;try{let r=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:af.article.id,timeElapsed:n,action:e,parameters:t}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!r.ok)if((o=r.headers.get("Content-Type"))!=null&&o.includes("application/json")){let i=await r.json();console.error(i.error)}else console.error(`${r.status} ${r.statusText}`)}catch(r){}}function J(e,t){let n=performance.now();return()=>$(e,t,performance.now()-n)}function V(e){return`${e||af.article.id}.${af.userSession.login}`}function Z(e,t){if(!(af!=null&&af.userSession))return null;let n=V(t),o=JSON.parse(localStorage.getItem(n)||"{}");return e?o[e]||null:o}function X(e,t,n){if(!(af!=null&&af.userSession))return;let o=V(n),r=JSON.parse(localStorage.getItem(o)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(o,JSON.stringify(r))}var le=`
1
+ var af=af||{};af.common=(()=>{var v=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames,U=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var E=(e,t,r)=>t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,A=(e,t)=>{for(var r in t||(t={}))M.call(t,r)&&E(e,r,t[r]);if(U)for(var r of U(t))oe.call(t,r)&&E(e,r,t[r]);return e};var ie=(e,t)=>{for(var r in t)v(e,r,{get:t[r],enumerable:!0})},ae=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ne(t))!M.call(e,o)&&o!==r&&v(e,o,{get:()=>t[o],enumerable:!(n=re(t,o))||n.enumerable});return e};var le=e=>ae(v({},"__esModule",{value:!0}),e);var l=(e,t,r)=>(E(e,typeof t!="symbol"?t+"":t,r),r);var pe={};ie(pe,{ConfirmButtons:()=>P,SessionHandler:()=>g,UserSession:()=>D,alert:()=>Q,confirm:()=>G,downloadBlob:()=>I,downloadRequest:()=>F,expose:()=>R,getLocalizedString:()=>f,getSettings:()=>Y,getUserImage:()=>$,has:()=>y,invariant:()=>u,localStorage:()=>k,localize:()=>V,logActivity:()=>C,mitt:()=>L,openAlertDialog:()=>z,saveSettings:()=>W,startActivity:()=>Z,toLocalISODate:()=>B,toLocalISODateTime:()=>O,version:()=>de,waitForDialog:()=>H});function L(e){return{all:e=e||new Map,on:function(t,r){var n=e.get(t);n?n.push(r):e.set(t,[r])},off:function(t,r){var n=e.get(t);n&&(r?n.splice(n.indexOf(r)>>>0,1):e.set(t,[]))},emit:function(t,r){var n=e.get(t);n&&n.slice().map(function(o){o(r)}),(n=e.get("*"))&&n.slice().map(function(o){o(t,r)})}}}var g=class{constructor(){l(this,"eventHandler",L())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,r){try{let n=new Promise(i=>{let a=()=>{this.eventHandler.off("onAuthenticated",a),t==null||t(),i()};this.eventHandler.on("onAuthenticated",a)}),o=document.querySelector("dialog.session-expired-dialog");if(o)await n;else{o=document.createElement("dialog"),o.className="session-expired-dialog",o.style.display="flex",o.style.padding="0",o.style.left="50%",o.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",o.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(o),o.showModal(),await n,o.remove()}}catch(n){window.location.href=`/login?ReturnUrl=${encodeURIComponent(window.location.pathname)}${encodeURIComponent(window.location.search)}`}}attachEvent(t,r){return this.eventHandler.on(t,r)}detachEvent(t,r){return this.eventHandler.off(t,r)}};var D=class extends g{constructor(r){super();l(this,"amDesignator","a.m.");l(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);l(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);l(this,"decimalSeparator",".");l(this,"domain","OB");l(this,"email");l(this,"formats");l(this,"groupSeparator",null);l(this,"integratedSecurity",!1);l(this,"isDeveloper",!1);l(this,"login","");l(this,"loginType");l(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);l(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);l(this,"name");l(this,"pmDesignator","p.m.");l(this,"shortDateFormat","dd.MM.yyyy");l(this,"culture","en-GB");l(this,"uiculture","en-GB");this.formats={},Object.assign(this,r)}};var q;(q=window.window)==null||q.addEventListener("error",e=>{var t,r,n,o,i,a,s;try{let p={error:(n=(r=(t=e.error)==null?void 0:t.message)!=null?r:e.message)!=null?n:null,file:e.filename,line:(o=e.lineno)!=null?o:0,column:(i=e.colno)!=null?i:0,stack:(s=(a=e.error)==null?void 0:a.stack)!=null?s:null};fetch("/data/Logger/LogError",{body:JSON.stringify(p),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"})}catch(p){}});function _(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var T=class{constructor(){l(this,"isPersisted",()=>!0)}getLocalStorageKey(t,r){return r?["common",t].join("."):_(t)}get(t,r,n){let o=this.getLocalStorageKey(t,n),i=localStorage.getItem(o);return i!==null?JSON.parse(i):r}set(t,r,n){localStorage.setItem(this.getLocalStorageKey(t,n),JSON.stringify(r))}remove(t,r){let n=this.getLocalStorageKey(t,r);return localStorage.getItem(n)!==null?(localStorage.removeItem(n),!0):!1}clear(){let t=_("");for(let r in localStorage)r.slice(0,t.length)===t&&localStorage.removeItem(r)}},k=new T;function B(e){return e?O(e).substring(0,10):null}function m(e){return String(e).padStart(2,"0")}function O(e){return e?`${e.getFullYear()}-${m(e.getMonth()+1)}-${m(e.getDate())}T${m(e.getHours())}:${m(e.getMinutes())}:${m(e.getSeconds())}.${m(e.getMilliseconds())}`:null}function I(e,t){return new Promise(function(r,n){try{let o=URL.createObjectURL(e),i=document.body,a=document.createElement("a");a.setAttribute("download",t),a.href=o,i.append(a),a.click(),i.removeChild(a),setTimeout(function(){URL.revokeObjectURL(o),r()},250)}catch(o){n(o)}})}function u(e,t){if(e)return;let r=typeof t=="function"?t():t;throw new Error(r!=null?r:"Invariant failed")}async function F(e,{fileName:t,signal:r,onProgress:n}){var a;function o(s){typeof n=="function"&&n(A({},s))}let i=0;o({status:"requested"});try{let s=await fetch(e);if(!s.ok||!s.body){if((a=s.headers.get("content-type"))!=null&&a.includes("application/json")){let d=await s.json();u(!d.error,d.error)}throw new Error(`${s.status} ${s.statusText}`)}try{let d=s.body.getReader(),w=new ReadableStream({start:function(h){function c(){return d.read().then(function(x){if(x.done){h.close();return}return i+=x.value.length,o({bytesReceived:i,status:"downloading"}),h.enqueue(x.value),c()})}return c()}});s=new Response(w)}catch(d){}let p=await s.blob();o({bytesReceived:i,status:"downloaded"}),await I(p,t),o({bytesReceived:i,status:"completed"})}catch(s){r!=null&&r.aborted?o({status:"cancelled"}):o({error:s.message,status:"error"})}}function y(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var se=/^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 j(e){var t=e.toString().match(se);return u(t,"Unable to parse function!"),{name:t[1],args:t[2].split(","),body:t[3]}}function K(){}K.prototype=Object.create(null);var J=K;function N(e,t){if(typeof e=="object"){if(typeof t=="string"){let r=t.split(".");return N(e,r)}else if(Array.isArray(t)){let r=e;for(let n=0;n<t.length;n++)r=r[t[n]]=r[t[n]]||new J;return r}}}function R(e,t,r={}){if(Array.isArray(t))for(let n of t){let{name:o}=j(n);u(o,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),R(e,n)}else{let n,o;if(typeof t=="function"&&(n=j(t).name),typeof e=="string"){let i=e.split(".");n||(n=i[i.length-1],i=i.slice(0,i.length-1)),o=N(window,i)}else n&&(typeof e=="object"||typeof e=="function")?o=e:u(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");y(o,n)&&(r==null?void 0:r.overwrite)!==!0?console.warn([e,n].join(".")+" is already defined!"):o[n]=t}}var ce={xs:64,sm:128,md:256,lg:512,xl:void 0};function $(e,t,r,n="xs"){if(e&&typeof e=="object")return $(e.primKey,e.login,e.hash,e.size);if(!e||!r)return"";let o=ce[n];return`/api/data/blob/EmployeesLookup/${e}/Image/${encodeURIComponent(t!=null?t:"")}${t?".":""}${encodeURIComponent(r)}.jpg${o?`?width=${o}`:""}`}async function ue(e){try{let t=await fetch(`/api/user/localize/new/${af.article.id}`,{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function f(e,t){var r;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((r=af==null?void 0:af.article)==null?void 0:r.i18n)!==void 0){if(!y(af.article.i18n,e)){af.article.i18n[e]=e;let n=ue(e).then(o=>(af.article.i18n[e]=o,o));if(t)return n}return af.article.i18n[e]}else return e}function V(e,...t){u(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let r=e.map((o,i)=>i===e.length-1?o:`${o}$${i}`).join(""),n=f(r);return t.forEach((o,i)=>{n=n.replace("$"+i,o)}),n}async function C(e,t,r=0){var n;try{let o=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:af.article.id,timeElapsed:r,action:e,parameters:t}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!o.ok)if((n=o.headers.get("Content-Type"))!=null&&n.includes("application/json")){let i=await o.json();console.error(i.error)}else console.error(`${o.status} ${o.statusText}`)}catch(o){}}function Z(e,t){let r=performance.now();return()=>C(e,t,performance.now()-r)}function X(e){return`${e||af.article.id}.${af.userSession.login}`}function Y(e,t){if(!(af!=null&&af.userSession))return null;let r=X(t),n=JSON.parse(localStorage.getItem(r)||"{}");return e?n[e]||null:n}function W(e,t,r){if(!(af!=null&&af.userSession))return;let n=X(r),o=JSON.parse(localStorage.getItem(n)||"{}");typeof t<"u"?o[e]=t:o=e,localStorage.setItem(n,JSON.stringify(o))}var fe=`
2
2
  <dialog class="alert-dialog">
3
3
  <form method="dialog">
4
4
  <article></article>
@@ -7,5 +7,5 @@ var af=af||{};af.common=(()=>{var b=Object.defineProperty;var G=Object.getOwnPro
7
7
  </footer>
8
8
  </form>
9
9
  </dialog>
10
- `;if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=le,document.body.append(e)}function N(e){return new Promise(t=>{e.addEventListener("close",t,{once:!0})})}async function A({buttons:e,content:t,className:n}){var f;let o=document.querySelector("#AlertDialogTemplate");if(!o)throw Error("No alert dialog template found");let r=(f=o.content.firstElementChild)==null?void 0:f.cloneNode(!0),i=r==null?void 0:r.querySelector("article"),s=r==null?void 0:r.querySelector("footer menu");if(!r||!i||!s)throw Error("Invalid alert dialog template");n&&r.classList.add(n),i.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:g,value:L,primary:h}of e){let x=document.createElement("li"),d=document.createElement("button");d.value=L,h&&d.classList.add("primary"),d.textContent=g,x.appendChild(d),s.appendChild(d)}document.body.appendChild(r),r.showModal(),await N(r);let l=r.returnValue||"cancel";return document.body.removeChild(r),l}var O=(n=>(n[n.YesNo=0]="YesNo",n[n.OkCancel=1]="OkCancel",n))(O||{});async function Y(e,t=0){let n=[{label:u("Yes"),value:"yes",primary:!0},{label:u("No"),value:"no"}];return t==1&&(n=[{label:u("OK"),value:"yes",primary:!0},{label:u("Cancel"),value:"no"}]),await A({content:e,buttons:n,className:"alert-dialog-confirm"})==="yes"}async function W(e){await A({content:e,className:"alert-dialog-alert",buttons:[{label:u("OK"),value:"ok",primary:!0}]})}var se="2.7.1";return re(ce);})();
10
+ `;if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=fe,document.body.append(e)}function H(e){return new Promise(t=>{e.addEventListener("close",t,{once:!0})})}var S=new Map;async function z({buttons:e,content:t,className:r,id:n,title:o}){var w,h;if(n&&S.has(n))return await S.get(n);let i=document.querySelector("#AlertDialogTemplate");if(!i)throw Error("No alert dialog template found");let a=(w=i.content.firstElementChild)==null?void 0:w.cloneNode(!0),s=a==null?void 0:a.querySelector("article"),p=a==null?void 0:a.querySelector("footer menu");if(!a||!s||!p)throw Error("Invalid alert dialog template");if(r&&r.split(/\s+/).forEach(c=>a==null?void 0:a.classList.add(c)),o){let c=document.createElement("header");c.append(o),(h=s.parentNode)==null||h.insertBefore(c,s)}s.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:c,value:x,primary:ee}of e){let te=document.createElement("li"),b=document.createElement("button");b.value=x,ee&&b.classList.add("primary"),b.textContent=c,te.appendChild(b),p.appendChild(b)}document.body.appendChild(a),a.showModal();let d=H(a).then(()=>{n&&S.has(n)&&S.delete(n)}).then(()=>{let c=(a==null?void 0:a.returnValue)||"cancel";return a&&document.body.removeChild(a),c});return n&&S.set(n,d),await d}var P=(r=>(r[r.YesNo=0]="YesNo",r[r.OkCancel=1]="OkCancel",r))(P||{});async function G(e,t={}){let{buttons:r=0,title:n}=t,o=r===1?[{label:f("OK"),value:"yes",primary:!0},{label:f("Cancel"),value:"no"}]:[{label:f("Yes"),value:"yes",primary:!0},{label:f("No"),value:"no"}];return await z({content:e,buttons:o,className:"alert-dialog-confirm",title:n})==="yes"}async function Q(e,t={}){await z(A({content:e,className:"alert-dialog-alert",buttons:[{label:f("OK"),value:"ok",primary:!0}]},t))}var de="2.7.3";return le(pe);})();
11
11
  //# sourceMappingURL=af.common.legacy.min.js.map