@progressive-development/pd-contact 0.1.68 → 0.5.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/index.js +10 -0
- package/dist/locales/be.js +20 -0
- package/dist/locales/de.js +20 -0
- package/dist/locales/en.js +20 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-checkbox.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-form-container.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-form-row.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-hover-box.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-input.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/pd-radio-group.js +2 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdBaseInputElement.js +86 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdBaseUi.js +33 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdBaseUiInput.js +229 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdCheckbox.js +230 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdFormContainer.js +167 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdFormRow.js +92 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdHoverBox.js +108 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdInput.js +79 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/PdRadioGroup.js +72 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/shared-input-field-styles.js +152 -0
- package/dist/node_modules/@progressive-development/pd-forms/src/shared-input-styles.js +64 -0
- package/dist/node_modules/@progressive-development/pd-icon/pd-icon.js +4 -0
- package/dist/node_modules/@progressive-development/pd-icon/src/PdIcon.js +595 -0
- package/dist/node_modules/lit-html/directive.js +27 -0
- package/dist/node_modules/lit-html/directives/class-map.js +36 -0
- package/dist/node_modules/lit-html/lit-html.js +242 -0
- package/dist/pd-contact.js +2 -0
- package/dist/src/PdContact.js +616 -0
- package/package.json +46 -22
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/server.mjs +0 -8
- package/demo/index.html +0 -29
- package/index.js +0 -1
- package/pd-contact.js +0 -3
- package/src/PdContact.js +0 -618
- package/stories/index.stories.js +0 -78
- package/test/pd-contact.test.js +0 -32
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import { LitElement, css, html } from "lit";
|
|
2
|
+
import { msg } from "@lit/localize";
|
|
3
|
+
import { PDFontStyles } from "@progressive-development/pd-shared-styles";
|
|
4
|
+
import "../node_modules/@progressive-development/pd-icon/pd-icon.js";
|
|
5
|
+
import "../node_modules/@progressive-development/pd-forms/pd-checkbox.js";
|
|
6
|
+
import "../node_modules/@progressive-development/pd-forms/pd-form-container.js";
|
|
7
|
+
import "../node_modules/@progressive-development/pd-forms/pd-form-row.js";
|
|
8
|
+
import "../node_modules/@progressive-development/pd-forms/pd-input.js";
|
|
9
|
+
import "../node_modules/@progressive-development/pd-forms/pd-radio-group.js";
|
|
10
|
+
/**
|
|
11
|
+
* @license
|
|
12
|
+
* Copyright (c) 2021 PD Progressive Development UG. All rights reserved.
|
|
13
|
+
*/
|
|
14
|
+
const countryPrefixes = {
|
|
15
|
+
de: "+49",
|
|
16
|
+
// Deutschland
|
|
17
|
+
be: "+32",
|
|
18
|
+
// Belgien
|
|
19
|
+
nl: "+31",
|
|
20
|
+
// Niederland
|
|
21
|
+
fr: "+33",
|
|
22
|
+
// Frankreich
|
|
23
|
+
es: "+34"
|
|
24
|
+
// Spanien
|
|
25
|
+
};
|
|
26
|
+
function transformPhone(phone, country) {
|
|
27
|
+
if (!phone || typeof phone !== "string") {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
const countryPrefix = countryPrefixes[country];
|
|
31
|
+
if (!countryPrefix) {
|
|
32
|
+
throw new Error(`Unbekanntes Land: ${country}`);
|
|
33
|
+
}
|
|
34
|
+
const cleanedPhone = phone.replace(/\s+/g, "").replace(/[^0-9+]/g, "");
|
|
35
|
+
if (cleanedPhone.startsWith("+")) {
|
|
36
|
+
return cleanedPhone;
|
|
37
|
+
}
|
|
38
|
+
if (cleanedPhone.startsWith("0")) {
|
|
39
|
+
return countryPrefix + cleanedPhone.slice(1);
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
const C_TYPE = "type";
|
|
44
|
+
const C_COMPANY = "companyName";
|
|
45
|
+
const C_BTWNR = "vatNr";
|
|
46
|
+
const C_FIRSTNAME = "firstName";
|
|
47
|
+
const C_LASTNAME = "lastName";
|
|
48
|
+
const C_STREET = "street";
|
|
49
|
+
const C_CITY = "city";
|
|
50
|
+
const C_ADDITIONAL = "additionalHint";
|
|
51
|
+
const C_PHONE1 = "phone1";
|
|
52
|
+
const C_EMAIL = "email";
|
|
53
|
+
class PdContact extends LitElement {
|
|
54
|
+
static get styles() {
|
|
55
|
+
return [
|
|
56
|
+
PDFontStyles,
|
|
57
|
+
css`
|
|
58
|
+
:host {
|
|
59
|
+
display: block;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.contact {
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
address {
|
|
68
|
+
color: var(--pd-contact-address-col, var(--pd-default-font-content-col));
|
|
69
|
+
line-height: 1.8;
|
|
70
|
+
font-style: normal;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
dl {
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
dt {
|
|
79
|
+
font-weight: bold;
|
|
80
|
+
padding-top: 10px;
|
|
81
|
+
color: var(--pd-contact-address-title-col, var(--pd-default-font-title-col));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
dd {
|
|
85
|
+
font-weight: 400;
|
|
86
|
+
font-size: 1em;
|
|
87
|
+
margin: 0;
|
|
88
|
+
padding: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
dd.larger {
|
|
92
|
+
padding-top: 3px;
|
|
93
|
+
padding-bottom: 5px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.contact-form {
|
|
97
|
+
--row-padding-top: 10px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.link-icon {
|
|
101
|
+
--pd-icon-bg-col-active: #859900;
|
|
102
|
+
--pd-icon-bg-col-hover: #859900;
|
|
103
|
+
--pd-icon-size: 14px;
|
|
104
|
+
--pd-icon-stroke-col-active: white;
|
|
105
|
+
--pd-icon-col-active: white;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.link-item {
|
|
109
|
+
display: flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
text-decoration: none;
|
|
112
|
+
color: var(--pd-default-font-link-col, inherit);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.link-item:hover {
|
|
116
|
+
color: var(--pd-default-font-link-col-hover, #451A46) ;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
`
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
static get properties() {
|
|
123
|
+
return {
|
|
124
|
+
addressTitle: { type: String },
|
|
125
|
+
addressRef: { type: String },
|
|
126
|
+
/**
|
|
127
|
+
* show (true) or not (false) tel number as link
|
|
128
|
+
*/
|
|
129
|
+
phoneMailLink: { type: Boolean },
|
|
130
|
+
/**
|
|
131
|
+
* summary (true) or view (false) contact data
|
|
132
|
+
*/
|
|
133
|
+
summary: { type: Boolean },
|
|
134
|
+
/**
|
|
135
|
+
* List with required contact fields, if not set use default (previous existing values to be consitent during update)
|
|
136
|
+
*/
|
|
137
|
+
requiredFields: { type: Array },
|
|
138
|
+
/**
|
|
139
|
+
* List with showing input fields, if not set show all
|
|
140
|
+
*/
|
|
141
|
+
inputFields: { type: Array },
|
|
142
|
+
contact: { type: Object },
|
|
143
|
+
match: { type: Object },
|
|
144
|
+
/**
|
|
145
|
+
* address type, business (true) or private (false), refactor, ist state internal? => _business, state:true
|
|
146
|
+
*/
|
|
147
|
+
_business: { type: Boolean, state: true },
|
|
148
|
+
_errorMap: { type: Object }
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
constructor() {
|
|
152
|
+
super();
|
|
153
|
+
this.addressTitle = msg("Adresse", { id: "pd.contact.address.title" });
|
|
154
|
+
this.requiredFields = [];
|
|
155
|
+
this.inputFields = [];
|
|
156
|
+
this.summary = false;
|
|
157
|
+
this.match = {};
|
|
158
|
+
this._business = false;
|
|
159
|
+
this._errorMap = /* @__PURE__ */ new Map();
|
|
160
|
+
}
|
|
161
|
+
update(changedProperties) {
|
|
162
|
+
if (changedProperties.has("contact") && this.contact) {
|
|
163
|
+
this._business = this.contact.business;
|
|
164
|
+
}
|
|
165
|
+
super.update(changedProperties);
|
|
166
|
+
}
|
|
167
|
+
connectedCallback() {
|
|
168
|
+
super.connectedCallback();
|
|
169
|
+
this.addEventListener("validate-form", this._validateForm);
|
|
170
|
+
}
|
|
171
|
+
disconnectedCallback() {
|
|
172
|
+
super.connectedCallback();
|
|
173
|
+
this.removeEventListener("validate-form", this._validateForm);
|
|
174
|
+
}
|
|
175
|
+
firstUpdated() {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
this.addEventListener("key-pressed", (e) => {
|
|
178
|
+
this._errorMap.set(e.detail.name, "");
|
|
179
|
+
super.requestUpdate();
|
|
180
|
+
});
|
|
181
|
+
if (this.contact) {
|
|
182
|
+
const detail = {
|
|
183
|
+
errorMap: /* @__PURE__ */ new Map()
|
|
184
|
+
};
|
|
185
|
+
(_b = (_a = this.shadowRoot) == null ? void 0 : _a.getElementById("contactContainerId")) == null ? void 0 : _b.dispatchEvent(
|
|
186
|
+
new CustomEvent("validate-form", { detail })
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
render() {
|
|
191
|
+
return html`
|
|
192
|
+
<div class="contact">
|
|
193
|
+
${this.summary ? this._renderViewContact() : this._renderEditContact()}
|
|
194
|
+
</div>
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
_renderEditContact() {
|
|
198
|
+
return html`
|
|
199
|
+
<pd-form-container id="contactContainerId" requiredFieldInfo>
|
|
200
|
+
|
|
201
|
+
${this.inputFields.length === 0 || this._showInput(C_TYPE) ? html`
|
|
202
|
+
<pd-form-row id="testFormId">
|
|
203
|
+
<pd-radio-group
|
|
204
|
+
class="quarter3"
|
|
205
|
+
label="${msg("Typ", { id: "pd.contact.label.type" })}"
|
|
206
|
+
required
|
|
207
|
+
value="${this._getRadioValue()}"
|
|
208
|
+
@field-change="${this._switchAddressType}"
|
|
209
|
+
style="--group-gap: 20px;"
|
|
210
|
+
>
|
|
211
|
+
<pd-checkbox value="${this.contact ? !this.contact.business : true}" valueName="private"
|
|
212
|
+
>${msg("Privatperson", { id: "pd.contact.check.private" })}</pd-checkbox
|
|
213
|
+
>
|
|
214
|
+
<pd-checkbox valueName="business" value="${this.contact ? this.contact.business : false}">${msg("Unternehmen", { id: "pd.contact.check.company" })}</pd-checkbox>
|
|
215
|
+
</pd-radio-group>
|
|
216
|
+
</pd-form-row>
|
|
217
|
+
` : ""}
|
|
218
|
+
|
|
219
|
+
${this._business ? html`
|
|
220
|
+
${this.inputFields.length === 0 || this._showInput(C_COMPANY) ? html`
|
|
221
|
+
<pd-form-row class="contact-form">
|
|
222
|
+
<pd-input
|
|
223
|
+
id="compNameId"
|
|
224
|
+
class="quarter3"
|
|
225
|
+
label="${msg("Name des Unternehmen", { id: "pd.contact.label.company" })}"
|
|
226
|
+
?required="${this._isRequired(C_COMPANY)}"
|
|
227
|
+
value="${this.contact ? this.contact.companyName : ""}"
|
|
228
|
+
valueName="companyName"
|
|
229
|
+
autoCompleteName="organization"
|
|
230
|
+
></pd-input>
|
|
231
|
+
</pd-form-row>
|
|
232
|
+
` : ""}
|
|
233
|
+
${this.inputFields.length === 0 || this._showInput(C_BTWNR) ? html`
|
|
234
|
+
<pd-form-row class="contact-form">
|
|
235
|
+
<pd-input
|
|
236
|
+
id="vatId"
|
|
237
|
+
class="quarter3"
|
|
238
|
+
label="${msg("USt-IdNr.", { id: "pd.contact.label.btw" })}"
|
|
239
|
+
?required="${this._isRequired(C_BTWNR)}"
|
|
240
|
+
field-type="vat"
|
|
241
|
+
valueName="vatNr"
|
|
242
|
+
value="${this.contact ? this.contact.vatNr : ""}"
|
|
243
|
+
autoCompleteName="vat"
|
|
244
|
+
></pd-input>
|
|
245
|
+
</pd-form-row>
|
|
246
|
+
` : ""}
|
|
247
|
+
` : html`
|
|
248
|
+
${this.inputFields.length === 0 || this._showInput(C_FIRSTNAME) ? html`
|
|
249
|
+
<pd-form-row class="contact-form">
|
|
250
|
+
<pd-input
|
|
251
|
+
id="firstNameId"
|
|
252
|
+
class="quarter3"
|
|
253
|
+
label="${msg("Vorname", { id: "pd.contact.label.firstName" })}"
|
|
254
|
+
valueName="firstName"
|
|
255
|
+
value="${this.contact ? this.contact.firstName : ""}"
|
|
256
|
+
autoCompleteName="given-name"
|
|
257
|
+
?required="${this._isRequired(C_FIRSTNAME)}"
|
|
258
|
+
></pd-input>
|
|
259
|
+
</pd-form-row>
|
|
260
|
+
` : ""}
|
|
261
|
+
${this.inputFields.length === 0 || this._showInput(C_LASTNAME) ? html`
|
|
262
|
+
<pd-form-row class="contact-form">
|
|
263
|
+
<pd-input
|
|
264
|
+
id="lastNameId"
|
|
265
|
+
class="quarter3"
|
|
266
|
+
label="${msg("Nachname", { id: "pd.contact.label.lastName" })}"
|
|
267
|
+
valueName="lastName"
|
|
268
|
+
value="${this.contact ? this.contact.lastName : ""}"
|
|
269
|
+
autoCompleteName="family-name"
|
|
270
|
+
?required="${this._isRequired(C_LASTNAME)}"
|
|
271
|
+
></pd-input>
|
|
272
|
+
</pd-form-row>
|
|
273
|
+
` : ""}
|
|
274
|
+
`}
|
|
275
|
+
${this.inputFields.length === 0 || this._showInput(C_STREET) ? html`
|
|
276
|
+
<pd-form-row class="contact-form">
|
|
277
|
+
<pd-input
|
|
278
|
+
id="streetId"
|
|
279
|
+
class="quarter2"
|
|
280
|
+
label="${msg("Strasse", { id: "pd.contact.label.street" })}"
|
|
281
|
+
valueName="street"
|
|
282
|
+
value="${this.contact ? this.contact.street : ""}"
|
|
283
|
+
autoCompleteName="street-address"
|
|
284
|
+
?required="${this._isRequired(C_STREET)}"
|
|
285
|
+
></pd-input>
|
|
286
|
+
<pd-input
|
|
287
|
+
id="streetNrId"
|
|
288
|
+
class="quarter1"
|
|
289
|
+
label="${msg("Nr.", { id: "pd.contact.label.streetNr" })}"
|
|
290
|
+
valueName="streetNr"
|
|
291
|
+
value="${this.contact ? this.contact.streetNr : ""}"
|
|
292
|
+
?required="${this._isRequired("streetNr")}"
|
|
293
|
+
></pd-input>
|
|
294
|
+
</pd-form-row>
|
|
295
|
+
` : ""}
|
|
296
|
+
${this.inputFields.length === 0 || this._showInput(C_CITY) ? html`
|
|
297
|
+
<pd-form-row class="contact-form">
|
|
298
|
+
${this.match && this.match.zip ? html`
|
|
299
|
+
<pd-input
|
|
300
|
+
readonly
|
|
301
|
+
id="zipId"
|
|
302
|
+
class="quarter1"
|
|
303
|
+
label="${msg("PLZ", { id: "pd.contact.label.zip" })}"
|
|
304
|
+
valueName="zip"
|
|
305
|
+
value="${this.match ? this.match.zip || "" : ""}"
|
|
306
|
+
></pd-input>
|
|
307
|
+
` : html`
|
|
308
|
+
<pd-input
|
|
309
|
+
id="zipId"
|
|
310
|
+
class="quarter1"
|
|
311
|
+
label="${msg("PLZ", { id: "pd.contact.label.zip" })}"
|
|
312
|
+
field-type="number"
|
|
313
|
+
valueName="zip"
|
|
314
|
+
value="${this.contact ? this.contact.zip : ""}"
|
|
315
|
+
autoCompleteName="postal-code"
|
|
316
|
+
?required="${this._isRequired("zip")}"
|
|
317
|
+
></pd-input>
|
|
318
|
+
`}
|
|
319
|
+
<pd-input
|
|
320
|
+
id="cityId"
|
|
321
|
+
class="quarter2"
|
|
322
|
+
label="${msg("Ort", { id: "pd.contact.label.city" })}"
|
|
323
|
+
valueName="city"
|
|
324
|
+
value="${this.contact ? this.contact.city : ""}"
|
|
325
|
+
autoCompleteName="locality"
|
|
326
|
+
?required="${this._isRequired(C_CITY)}"
|
|
327
|
+
></pd-input>
|
|
328
|
+
</pd-form-row>
|
|
329
|
+
` : ""}
|
|
330
|
+
${this.inputFields.length === 0 || this._showInput(C_ADDITIONAL) ? html`
|
|
331
|
+
<pd-form-row class="contact-form">
|
|
332
|
+
<pd-input
|
|
333
|
+
class="quarter3"
|
|
334
|
+
id="additionalHintId"
|
|
335
|
+
label="${msg("Addresszusatz", { id: "pd.contact.label.additional" })}"
|
|
336
|
+
value="${this.contact ? this.contact.additionalHint : ""}"
|
|
337
|
+
></pd-input>
|
|
338
|
+
</pd-form-row>
|
|
339
|
+
` : ""}
|
|
340
|
+
${this.inputFields.length === 0 || this._showInput(C_PHONE1) ? html`
|
|
341
|
+
<pd-form-row class="contact-form">
|
|
342
|
+
<pd-input
|
|
343
|
+
id="phoneId"
|
|
344
|
+
class="quarter3"
|
|
345
|
+
label="${msg("Telefon", { id: "pd.contact.label.phone" })}"
|
|
346
|
+
name="phone"
|
|
347
|
+
valueName="phone1"
|
|
348
|
+
value="${this.contact ? this.contact.phone1 : ""}"
|
|
349
|
+
field-type="phone"
|
|
350
|
+
autoCompleteName="tel"
|
|
351
|
+
?required="${this._isRequired(C_PHONE1)}"
|
|
352
|
+
></pd-input>
|
|
353
|
+
</pd-form-row>
|
|
354
|
+
` : ""}
|
|
355
|
+
${this.inputFields.length === 0 || this._showInput(C_EMAIL) ? html`
|
|
356
|
+
<pd-form-row class="contact-form">
|
|
357
|
+
<pd-input
|
|
358
|
+
id="mailId"
|
|
359
|
+
class="quarter3"
|
|
360
|
+
label="${msg("E-mail", { id: "pd.contact.label.email" })}"
|
|
361
|
+
field-type="mail"
|
|
362
|
+
valueName="email"
|
|
363
|
+
value="${this.contact ? this.contact.email : ""}"
|
|
364
|
+
autoCompleteName="email"
|
|
365
|
+
?required="${this._isRequired(C_EMAIL)}"
|
|
366
|
+
></pd-input>
|
|
367
|
+
</pd-form-row>
|
|
368
|
+
` : ""}
|
|
369
|
+
</pd-form-container>
|
|
370
|
+
`;
|
|
371
|
+
}
|
|
372
|
+
_getRadioValue() {
|
|
373
|
+
if (this.contact) {
|
|
374
|
+
return this.contact.business ? "business" : "private";
|
|
375
|
+
}
|
|
376
|
+
return "private";
|
|
377
|
+
}
|
|
378
|
+
_renderViewContact() {
|
|
379
|
+
if (!this.contact) {
|
|
380
|
+
return html`<p>Contact undefined</p>`;
|
|
381
|
+
}
|
|
382
|
+
const trPhoneNr = transformPhone(this.contact.phone1, this.contact.country || "be");
|
|
383
|
+
return html`
|
|
384
|
+
<address>
|
|
385
|
+
<dl>
|
|
386
|
+
<dt>${this.addressTitle}</dt>
|
|
387
|
+
${this.contact ? html`
|
|
388
|
+
<dd>${this.contact.companyName}</dd>
|
|
389
|
+
<dd>${this.contact.vatNr}</dd>
|
|
390
|
+
<dd>${this._getFullName()}</dd>
|
|
391
|
+
<dd>${this._getFullStreet()}</dd>
|
|
392
|
+
<dd>${this._getFullLocation()}</dd>
|
|
393
|
+
${this.contact.additionalHint ? html`<dd>${this.contact.additionalHint}</dd>` : ""}
|
|
394
|
+
<dd>${this.contact.country}</dd>
|
|
395
|
+
|
|
396
|
+
${this.contact.phone1 ? html`
|
|
397
|
+
<dd class="larger">${this.phoneMailLink && trPhoneNr ? html`
|
|
398
|
+
<a href="${`tel:${trPhoneNr}`}"
|
|
399
|
+
aria-label="${`Phone call: ${this.contact.phone1}`}"
|
|
400
|
+
class="link-item">
|
|
401
|
+
<span style="margin-right: 8px;">${this.contact.phone1}</span>
|
|
402
|
+
<pd-icon activeIcon icon="phoneIcon" class="round link-icon"></pd-icon>
|
|
403
|
+
</a>
|
|
404
|
+
` : this.contact.phone1}</dd>
|
|
405
|
+
` : ""}
|
|
406
|
+
|
|
407
|
+
${this.contact.email ? html`
|
|
408
|
+
<dd class="larger">${this.phoneMailLink ? html`
|
|
409
|
+
<a href="${`mailto:${this.contact.email}`}"
|
|
410
|
+
aria-label="${`Send mail: ${this.contact.email}`}"
|
|
411
|
+
class="link-item">
|
|
412
|
+
<span style="margin-right: 8px;">${this.contact.email}</span>
|
|
413
|
+
<pd-icon activeIcon icon="mailIcon" class="round link-icon"></pd-icon>
|
|
414
|
+
</a>
|
|
415
|
+
` : this.contact.email}</dd>
|
|
416
|
+
` : ""}
|
|
417
|
+
|
|
418
|
+
${this.contact.btw ? html`<dt>BTW</dt>
|
|
419
|
+
<dd>${this.contact.btw}</dd>` : ""}
|
|
420
|
+
${this.contact.kbc ? html`<dt>Bankgegevens</dt>
|
|
421
|
+
<dd>${this.contact.kbc}</dd>
|
|
422
|
+
<dd>${this.contact.bank}</dd>` : ""}
|
|
423
|
+
` : html`${this.addressRef || "--"}`}
|
|
424
|
+
</dl>
|
|
425
|
+
</address>
|
|
426
|
+
`;
|
|
427
|
+
}
|
|
428
|
+
_switchAddressType(e) {
|
|
429
|
+
this._business = e.detail.name === "business";
|
|
430
|
+
}
|
|
431
|
+
_isRequired(field) {
|
|
432
|
+
return this.requiredFields && this.requiredFields.length > 0 ? this.requiredFields.includes(field) : false;
|
|
433
|
+
}
|
|
434
|
+
_showInput(field) {
|
|
435
|
+
return this.inputFields && this.inputFields.length > 0 ? this.inputFields.includes(field) : false;
|
|
436
|
+
}
|
|
437
|
+
/*
|
|
438
|
+
validateInput() {
|
|
439
|
+
const matchForValidate = this.match || {};
|
|
440
|
+
|
|
441
|
+
const companyName = this.business
|
|
442
|
+
? this.shadowRoot.getElementById('compNameId').value
|
|
443
|
+
: undefined;
|
|
444
|
+
const vatNr = this.business
|
|
445
|
+
? this.shadowRoot.getElementById('vatId').value
|
|
446
|
+
: undefined;
|
|
447
|
+
const firstName = this.business
|
|
448
|
+
? undefined
|
|
449
|
+
: this.shadowRoot.getElementById('firstNameId').value;
|
|
450
|
+
const lastName = this.business
|
|
451
|
+
? undefined
|
|
452
|
+
: this.shadowRoot.getElementById('lastNameId').value;
|
|
453
|
+
const street = this.shadowRoot.getElementById('streetId').value;
|
|
454
|
+
const streetNr = this.shadowRoot.getElementById('streetNrId').value;
|
|
455
|
+
const additionalHint =
|
|
456
|
+
this.shadowRoot.getElementById('additionalHintId').value;
|
|
457
|
+
const zip = this.shadowRoot.getElementById('zipId').value;
|
|
458
|
+
const city = this.shadowRoot.getElementById('cityId').value;
|
|
459
|
+
const phone1 = this.shadowRoot.getElementById('phoneId').value;
|
|
460
|
+
const email = this.shadowRoot.getElementById('mailId').value;
|
|
461
|
+
|
|
462
|
+
const newErrorMap = new Map();
|
|
463
|
+
|
|
464
|
+
const reqFieldFunc = (field, key, type, mustMatch) => {
|
|
465
|
+
if (!field || field === '') {
|
|
466
|
+
newErrorMap.set(
|
|
467
|
+
key,
|
|
468
|
+
type !== 'phone'
|
|
469
|
+
? 'Vul dit veld in.'
|
|
470
|
+
: 'Vul dit veld in. Gebruik +32 494 667085.'
|
|
471
|
+
);
|
|
472
|
+
} else if (mustMatch && field !== mustMatch) {
|
|
473
|
+
newErrorMap.set(key, `Not match ${mustMatch}`);
|
|
474
|
+
} else {
|
|
475
|
+
switch (type) {
|
|
476
|
+
case 'vat':
|
|
477
|
+
// eslint-disable-next-line no-restricted-globals
|
|
478
|
+
if (!newErrorMap.has(key) && !PdContact._vatIsValid(field)) {
|
|
479
|
+
newErrorMap.set(key, 'Formaat BE0123456789 vereist');
|
|
480
|
+
}
|
|
481
|
+
break;
|
|
482
|
+
case 'number':
|
|
483
|
+
// eslint-disable-next-line no-restricted-globals
|
|
484
|
+
if (!newErrorMap.has(key) && isNaN(field)) {
|
|
485
|
+
newErrorMap.set(key, 'Alleen nummers toegestaan');
|
|
486
|
+
}
|
|
487
|
+
break;
|
|
488
|
+
case 'mail':
|
|
489
|
+
if (!newErrorMap.has(key) && !PdContact._mailIsValid(field)) {
|
|
490
|
+
newErrorMap.set(key, 'Ongeldig e-mailadres');
|
|
491
|
+
}
|
|
492
|
+
break;
|
|
493
|
+
case 'phone':
|
|
494
|
+
if (!newErrorMap.has(key) && !PdContact._phoneIsValid(field)) {
|
|
495
|
+
newErrorMap.set(
|
|
496
|
+
key,
|
|
497
|
+
'Ongeldig telefoonnummer, gebruik +32 494 667085.'
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
default:
|
|
502
|
+
console.warn('Undefined field: ', type);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
if (this.business) {
|
|
508
|
+
reqFieldFunc(companyName, 'companyName');
|
|
509
|
+
reqFieldFunc(vatNr, 'vatNr', 'vat');
|
|
510
|
+
} else {
|
|
511
|
+
reqFieldFunc(firstName, 'firstName');
|
|
512
|
+
reqFieldFunc(lastName, 'lastName');
|
|
513
|
+
}
|
|
514
|
+
reqFieldFunc(street, 'street');
|
|
515
|
+
reqFieldFunc(streetNr, 'streetNr');
|
|
516
|
+
reqFieldFunc(zip, 'zip', 'number', matchForValidate.zip);
|
|
517
|
+
reqFieldFunc(city, 'city');
|
|
518
|
+
reqFieldFunc(phone1, 'phone1', 'phone');
|
|
519
|
+
reqFieldFunc(email, 'email', 'mail');
|
|
520
|
+
this._errorMap = newErrorMap;
|
|
521
|
+
|
|
522
|
+
return new Promise((resolve, reject) => {
|
|
523
|
+
if (newErrorMap.size > 0) {
|
|
524
|
+
reject();
|
|
525
|
+
} else {
|
|
526
|
+
this.contact = {
|
|
527
|
+
business: this.business,
|
|
528
|
+
companyName,
|
|
529
|
+
vatNr,
|
|
530
|
+
firstName,
|
|
531
|
+
lastName,
|
|
532
|
+
street,
|
|
533
|
+
streetNr,
|
|
534
|
+
additionalHint,
|
|
535
|
+
zip,
|
|
536
|
+
city,
|
|
537
|
+
phone1,
|
|
538
|
+
email,
|
|
539
|
+
};
|
|
540
|
+
resolve(this.contact);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
*/
|
|
545
|
+
_validateForm(e) {
|
|
546
|
+
if (e.detail && !e.detail.singleElement) {
|
|
547
|
+
this.shadowRoot.getElementById("contactContainerId").dispatchEvent(
|
|
548
|
+
new CustomEvent("validate-form", {
|
|
549
|
+
detail: e.detail
|
|
550
|
+
})
|
|
551
|
+
);
|
|
552
|
+
if (e.detail.errorMap.size === 0 && e.detail.formData) {
|
|
553
|
+
e.detail.formData[this.id] = this._setFormData();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
_setFormData() {
|
|
558
|
+
const companyName = this._business ? this.shadowRoot.getElementById("compNameId").value : void 0;
|
|
559
|
+
const vatNr = this._business ? this.shadowRoot.getElementById("vatId").value : void 0;
|
|
560
|
+
const firstName = this._business ? void 0 : this.shadowRoot.getElementById("firstNameId").value;
|
|
561
|
+
const lastName = this._business ? void 0 : this.shadowRoot.getElementById("lastNameId").value;
|
|
562
|
+
const street = this.shadowRoot.getElementById("streetId").value;
|
|
563
|
+
const streetNr = this.shadowRoot.getElementById("streetNrId").value;
|
|
564
|
+
const additionalHint = this.shadowRoot.getElementById("additionalHintId").value;
|
|
565
|
+
const zip = this.shadowRoot.getElementById("zipId").value;
|
|
566
|
+
const city = this.shadowRoot.getElementById("cityId").value;
|
|
567
|
+
const phone1 = this.shadowRoot.getElementById("phoneId").value;
|
|
568
|
+
const email = this.shadowRoot.getElementById("mailId").value;
|
|
569
|
+
return {
|
|
570
|
+
business: this._business,
|
|
571
|
+
companyName,
|
|
572
|
+
vatNr,
|
|
573
|
+
firstName,
|
|
574
|
+
lastName,
|
|
575
|
+
street,
|
|
576
|
+
streetNr,
|
|
577
|
+
additionalHint,
|
|
578
|
+
zip,
|
|
579
|
+
city,
|
|
580
|
+
phone1,
|
|
581
|
+
email
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
_getFullName() {
|
|
585
|
+
return PdContact._getFullVal(this.contact.firstName, this.contact.lastName);
|
|
586
|
+
}
|
|
587
|
+
_getFullStreet() {
|
|
588
|
+
return PdContact._getFullVal(this.contact.street, this.contact.streetNr);
|
|
589
|
+
}
|
|
590
|
+
_getFullLocation() {
|
|
591
|
+
return PdContact._getFullVal(this.contact.zip, this.contact.city);
|
|
592
|
+
}
|
|
593
|
+
static _getFullVal(val1, val2, elseStr) {
|
|
594
|
+
let fullVal = "";
|
|
595
|
+
if (val1) {
|
|
596
|
+
fullVal += val1;
|
|
597
|
+
}
|
|
598
|
+
if (val2) {
|
|
599
|
+
fullVal += ` ${val2}`;
|
|
600
|
+
}
|
|
601
|
+
return fullVal.length === 0 ? elseStr : fullVal;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
export {
|
|
605
|
+
C_ADDITIONAL,
|
|
606
|
+
C_BTWNR,
|
|
607
|
+
C_CITY,
|
|
608
|
+
C_COMPANY,
|
|
609
|
+
C_EMAIL,
|
|
610
|
+
C_FIRSTNAME,
|
|
611
|
+
C_LASTNAME,
|
|
612
|
+
C_PHONE1,
|
|
613
|
+
C_STREET,
|
|
614
|
+
C_TYPE,
|
|
615
|
+
PdContact
|
|
616
|
+
};
|