@quandis/qbo4.ui-bridge 4.0.1-CI-20240919-212538

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/src/qbo-ssn.ts ADDED
@@ -0,0 +1,132 @@
1
+ import { html, TemplateResult } from 'lit';
2
+ import { customElement, property } from 'lit/decorators.js';
3
+ import { IApiService } from '@quandis/qbo4.ui';
4
+ import { services } from '@quandis/qbo4.configuration';
5
+ import { RestApiService } from '@quandis/qbo4.ui';
6
+ import { QboFormElement } from '@quandis/qbo4.ui';
7
+
8
+ type TemplateFunction = (component: any) => TemplateResult;
9
+ const ssnMap: Map<string, TemplateFunction> = new Map();
10
+ ssnMap.set('defaultLayout', (component: QboSSN) => {
11
+ return html`<div slot="content" class="${component.slotClass}">
12
+ <input type="text" ?disabled=${component.disabled} class="${component.inputClass}" name="${component.inputName}" value="${component.data?.['USSSN']}"/>
13
+ <span @click="${component.toggleSSN}" class="${component.spanClass}" title="${component.titleShowText}"><i class="${component.imageClassShow}"></i></span>
14
+ </div>`;
15
+ });
16
+
17
+ @customElement('qbo-ssn')
18
+ export class QboSSN extends QboFormElement {
19
+
20
+ @property({ type: String })
21
+ apiEndpoint = 'qbo';
22
+
23
+ @property({ type: Boolean })
24
+ disabled = true;
25
+
26
+ @property({ type: Boolean })
27
+ editMode = false;
28
+
29
+ @property({ type: String })
30
+ event: String | null = 'click';
31
+
32
+ @property({ type: String })
33
+ imageClassShow: String | null = 'qbo-icon-eye';
34
+
35
+ @property({ type: String })
36
+ imageClassHide: String | null = 'qbo-icon-eye-slash';
37
+
38
+ @property({ type: String })
39
+ inputClass: String | null = 'qbo-sm';
40
+
41
+ @property({ type: String })
42
+ inputName: String | null = 'USSSN';
43
+
44
+ @property({ type: String })
45
+ selectorImage: String | null = 'i';
46
+
47
+ @property({ type: String })
48
+ selectorInput: String | null = 'input';
49
+
50
+ @property({ type: String })
51
+ selectorSpan: String | null = 'span';
52
+
53
+ @property({ type: Boolean })
54
+ show = false;
55
+
56
+ @property({ type: String })
57
+ slotClass: String | null = 'qbo-input-group';
58
+
59
+ @property({ type: String })
60
+ spanClass: String | null = 'qbo-input-group-text qbo-pointer';
61
+
62
+ @property({ type: String })
63
+ titleMaskText: String | null = 'Mask';
64
+
65
+ @property({ type: String })
66
+ titleShowText: String | null = 'Show';
67
+
68
+ @property()
69
+ type: string | null = 'defaultLayout';
70
+
71
+ @property({ type: String })
72
+ url: String | null = 'contact/UnmaskSSN';
73
+
74
+ @property({ type: Boolean })
75
+ renderInHost = true;
76
+
77
+ createRenderRoot() {
78
+ return this.renderInHost ? this : super.createRenderRoot();
79
+ }
80
+
81
+ async toggleSSN() {
82
+ this.show = !this.show;
83
+
84
+ if (this.show) {
85
+ const service: IApiService = services.container.isRegistered(this.apiEndpoint)
86
+ ? services.container.resolve<IApiService>(this.apiEndpoint) : new RestApiService(this.apiEndpoint);
87
+ const json = await service.fetch(`${this.url}`, { ID: `${this.data?.['ContactID']}` });
88
+
89
+ this.renderRoot.querySelectorAll(`${this.selectorInput}`).forEach(input => {
90
+ if (input instanceof HTMLInputElement
91
+ && json?.ContactCollection?.length > 0
92
+ && json.ContactCollection[0].USSSN != null
93
+ && json.ContactCollection[0].USSSN.length == 9) {
94
+
95
+ const ssn = json.ContactCollection[0].USSSN;
96
+ input.value = `${ssn.substring(0, 3)}-${ssn.substring(3, 5)}-${ssn.substring(5, 9)}`;
97
+ if (this.editMode) input.disabled = false;
98
+
99
+ this.renderRoot.querySelectorAll(`${this.selectorSpan}`).forEach(span => {
100
+ span.setAttribute('title', `${this.titleMaskText}`);
101
+ });
102
+
103
+ this.renderRoot.querySelectorAll(`${this.selectorImage}`).forEach(i => {
104
+ i.className = `${this.imageClassHide}`;
105
+ });
106
+ }
107
+ else {
108
+ this.show = !this.show;
109
+ }
110
+ });
111
+ } else {
112
+ this.renderRoot.querySelectorAll(`${this.selectorInput}`).forEach(input => {
113
+ if (input instanceof HTMLInputElement) {
114
+ input.value = `${this.data?.['USSSN']}`;
115
+ if (this.editMode) input.disabled = true;
116
+ }
117
+
118
+ this.renderRoot.querySelectorAll(`${this.selectorSpan}`).forEach(span => {
119
+ span.setAttribute('title', `${this.titleShowText}`);
120
+ });
121
+
122
+ this.renderRoot.querySelectorAll(`${this.selectorImage}`).forEach(i => {
123
+ i.className = `${this.imageClassShow}`;
124
+ });
125
+ });
126
+ }
127
+ }
128
+
129
+ render() {
130
+ return html`<slot>${ssnMap.has(this.type!) ? ssnMap.get(this.type!)!(this) : null}</slot>`;
131
+ }
132
+ }
@@ -0,0 +1,3 @@
1
+ export declare const bootstrap: import("lit").CSSResult;
2
+ export declare const bootstrapicons: import("lit").CSSResult;
3
+ export declare const qboui: import("lit").CSSResult;