@quandis/qbo4.ui 4.0.1-CI-20240514-221344 → 4.0.1-CI-20240515-215721

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