Commit ed2920eddc365383a50eb3ed087929d12b398609
1 parent
bb06f5eb
Remove form reset when saving, add translatable error messages
Showing
3 changed files
with
76 additions
and
62 deletions
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | (blur)="key.isFocused = false; inputChanged(source, key)"> |
40 | 40 | <mat-icon *ngIf="key.settings.icon" matPrefix>{{key.settings.icon}}</mat-icon> |
41 | 41 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> |
42 | - {{key.settings.requiredErrorMessage}} | |
42 | + {{ getErrorMessageText(key.settings.requiredErrorMessage, '') }} | |
43 | 43 | </mat-error> |
44 | 44 | </mat-form-field> |
45 | 45 | </div> |
... | ... | @@ -59,52 +59,54 @@ |
59 | 59 | (blur)="key.isFocused = false; inputChanged(source, key)"> |
60 | 60 | <mat-icon *ngIf="key.settings.icon" matPrefix>{{key.settings.icon}}</mat-icon> |
61 | 61 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> |
62 | - {{key.settings.requiredErrorMessage}} | |
62 | + {{ getErrorMessageText(key.settings.requiredErrorMessage, '') }} | |
63 | 63 | </mat-error> |
64 | 64 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('min')"> |
65 | - {{ 'widgets.input-widgets.min-value-error' | translate:{value: key.settings.minValue} }} | |
65 | + {{ getErrorMessageText(key.settings.minValueErrorMessage, | |
66 | + 'widgets.input-widgets.min-value-error', | |
67 | + {value: key.settings.minValue}) }} | |
66 | 68 | </mat-error> |
67 | 69 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('max')"> |
68 | - {{ 'widgets.input-widgets.max-value-error' | translate:{value: key.settings.maxValue} }} | |
70 | + {{ getErrorMessageText(key.settings.maxValueErrorMessage, | |
71 | + 'widgets.input-widgets.max-value-error', | |
72 | + {value: key.settings.maxValue}) }} | |
69 | 73 | </mat-error> |
70 | 74 | </mat-form-field> |
71 | 75 | </div> |
72 | 76 | <div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanCheckbox'"> |
73 | 77 | <mat-checkbox formControlName="{{key.formId}}" |
74 | 78 | (change)="inputChanged(source, key)"> |
75 | - {{key.label}} | |
79 | + <span class="label-wrapper">{{key.label}}</span> | |
76 | 80 | </mat-checkbox> |
77 | 81 | </div> |
78 | 82 | <div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanSwitch'"> |
79 | 83 | <mat-slide-toggle formControlName="{{key.formId}}" |
80 | 84 | (change)="inputChanged(source, key)"> |
81 | - {{key.label}} | |
85 | + <span class="label-wrapper">{{key.label}}</span> | |
82 | 86 | </mat-slide-toggle> |
83 | 87 | </div> |
84 | 88 | <div class="input-field mat-block date-time-input" *ngIf="(key.settings.dataKeyValueType === 'dateTime') || |
85 | 89 | (key.settings.dataKeyValueType === 'date') || |
86 | 90 | (key.settings.dataKeyValueType === 'time')" fxLayout="column"> |
87 | - <div fxLayout="row" [ngClass]="{'vertically-aligned': smallWidthContainer}" fxLayoutGap="16px"> | |
88 | - <mat-form-field> | |
89 | - <mat-placeholder>{{key.label}}</mat-placeholder> | |
90 | - <mat-datetimepicker-toggle [for]="datePicker" matPrefix></mat-datetimepicker-toggle> | |
91 | - <mat-datetimepicker #datePicker type="{{datePickerType(key.settings.dataKeyValueType)}}" | |
92 | - openOnFocus="true"></mat-datetimepicker> | |
93 | - <input matInput formControlName="{{key.formId}}" | |
94 | - [required]="key.settings.required" | |
95 | - [readonly]="key.settings.isEditable === 'readonly'" | |
96 | - [matDatetimepicker]="datePicker" | |
97 | - (focus)="key.isFocused = true;" | |
98 | - (blur)="key.isFocused = false;" | |
99 | - (dateChange)="inputChanged(source, key)"> | |
100 | - <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> | |
101 | - {{key.settings.requiredErrorMessage}} | |
102 | - </mat-error> | |
103 | - <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('matDatepickerParse')"> | |
104 | - {{ 'widgets.input-widgets.invalid-date' | translate }} | |
105 | - </mat-error> | |
106 | - </mat-form-field> | |
107 | - </div> | |
91 | + <mat-form-field> | |
92 | + <mat-placeholder>{{key.label}}</mat-placeholder> | |
93 | + <mat-datetimepicker-toggle [for]="datePicker" matPrefix></mat-datetimepicker-toggle> | |
94 | + <mat-datetimepicker #datePicker type="{{datePickerType(key.settings.dataKeyValueType)}}" | |
95 | + openOnFocus="true"></mat-datetimepicker> | |
96 | + <input matInput formControlName="{{key.formId}}" | |
97 | + [required]="key.settings.required" | |
98 | + [readonly]="key.settings.isEditable === 'readonly'" | |
99 | + [matDatetimepicker]="datePicker" | |
100 | + (focus)="key.isFocused = true;" | |
101 | + (blur)="key.isFocused = false;" | |
102 | + (dateChange)="inputChanged(source, key)"> | |
103 | + <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> | |
104 | + {{ getErrorMessageText(key.settings.requiredErrorMessage, '') }} | |
105 | + </mat-error> | |
106 | + <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('matDatepickerParse')"> | |
107 | + {{ getErrorMessageText(key.settings.invalidDateErrorMessage, 'widgets.input-widgets.invalid-date') }} | |
108 | + </mat-error> | |
109 | + </mat-form-field> | |
108 | 110 | </div> |
109 | 111 | </div> |
110 | 112 | </div> |
... | ... | @@ -114,12 +116,12 @@ |
114 | 116 | <button mat-button color="primary" type="button" |
115 | 117 | (click)="discardAll()" style="max-height: 50px; margin-right:20px;" |
116 | 118 | [disabled]="!multipleInputFormGroup.dirty"> |
117 | - {{ 'action.undo' | translate }} | |
119 | + {{ settings.resetButtonLabel }} | |
118 | 120 | </button> |
119 | 121 | <button mat-button mat-raised-button color="primary" type="submit" |
120 | 122 | style="max-height: 50px; margin-right:20px;" |
121 | 123 | [disabled]="!multipleInputFormGroup.dirty || multipleInputFormGroup.invalid"> |
122 | - {{ 'action.save' | translate }} | |
124 | + {{ settings.saveButtonLabel }} | |
123 | 125 | </button> |
124 | 126 | </div> |
125 | 127 | </div> | ... | ... |
... | ... | @@ -44,7 +44,13 @@ |
44 | 44 | display: block; |
45 | 45 | margin-top: 20px; |
46 | 46 | margin-bottom: 16px; |
47 | - white-space: normal; | |
47 | + .label-wrapper { | |
48 | + white-space: normal; | |
49 | + } | |
50 | + } | |
51 | + | |
52 | + mat-slide-toggle { | |
53 | + height: auto; | |
48 | 54 | } |
49 | 55 | |
50 | 56 | .date-time-input { |
... | ... | @@ -56,20 +62,6 @@ |
56 | 62 | |
57 | 63 | .vertical-alignment { |
58 | 64 | flex-direction: column; |
59 | - | |
60 | - mat-checkbox, | |
61 | - mat-slide-toggle { | |
62 | - margin-top: 18px; | |
63 | - } | |
64 | - | |
65 | - mat-slide-toggle { | |
66 | - display: flex; | |
67 | - justify-content: space-between; | |
68 | - } | |
69 | - } | |
70 | - | |
71 | - .vertically-aligned { | |
72 | - flex-direction: column; | |
73 | 65 | } |
74 | 66 | } |
75 | 67 | } | ... | ... |
... | ... | @@ -47,6 +47,8 @@ interface MultipleInputWidgetSettings { |
47 | 47 | widgetTitle: string; |
48 | 48 | showActionButtons: boolean; |
49 | 49 | updateAllValues: boolean; |
50 | + saveButtonLabel: string; | |
51 | + resetButtonLabel: string; | |
50 | 52 | showResultMessage: boolean; |
51 | 53 | showGroupTitle: boolean; |
52 | 54 | groupTitle: string; |
... | ... | @@ -67,27 +69,19 @@ interface MultipleInputWidgetDataKeySettings { |
67 | 69 | maxValue?: number; |
68 | 70 | requiredErrorMessage?: string; |
69 | 71 | invalidDateErrorMessage?: string; |
70 | - minErrorMessage?: string; | |
71 | - maxErrorMessage?: string; | |
72 | + minValueErrorMessage?: string; | |
73 | + maxValueErrorMessage?: string; | |
72 | 74 | icon: string; |
73 | 75 | inputTypeNumber?: boolean; |
74 | 76 | readOnly?: boolean; |
75 | 77 | disabledOnCondition?: boolean; |
76 | 78 | } |
77 | 79 | |
78 | -interface MultipleInputWidgetDataKeyErrorMessages { | |
79 | - requiredErrorMessage?: string; | |
80 | - invalidDateErrorMessage?: string; | |
81 | - minErrorMessage?: string; | |
82 | - maxErrorMessage?: string; | |
83 | -} | |
84 | - | |
85 | 80 | interface MultipleInputWidgetDataKey extends DataKey { |
86 | 81 | formId?: string; |
87 | 82 | settings: MultipleInputWidgetDataKeySettings; |
88 | 83 | isFocused: boolean; |
89 | 84 | value?: any; |
90 | - errorMessages?: MultipleInputWidgetDataKeyErrorMessages; | |
91 | 85 | } |
92 | 86 | |
93 | 87 | interface MultipleInputWidgetSource { |
... | ... | @@ -170,6 +164,17 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
170 | 164 | |
171 | 165 | this.settings.groupTitle = this.settings.groupTitle || '${entityName}'; |
172 | 166 | |
167 | + if (this.settings.saveButtonLabel && this.settings.saveButtonLabel.length) { | |
168 | + this.settings.saveButtonLabel = this.utils.customTranslation(this.settings.saveButtonLabel, this.settings.saveButtonLabel); | |
169 | + } else { | |
170 | + this.settings.saveButtonLabel = this.translate.instant('action.save'); | |
171 | + } | |
172 | + if (this.settings.resetButtonLabel && this.settings.resetButtonLabel.length) { | |
173 | + this.settings.resetButtonLabel = this.utils.customTranslation(this.settings.resetButtonLabel, this.settings.resetButtonLabel); | |
174 | + } else { | |
175 | + this.settings.resetButtonLabel = this.translate.instant('action.undo'); | |
176 | + } | |
177 | + | |
173 | 178 | // For backward compatibility |
174 | 179 | if (isUndefined(this.settings.showActionButtons)) { |
175 | 180 | this.settings.showActionButtons = true; |
... | ... | @@ -338,25 +343,40 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
338 | 343 | |
339 | 344 | private updateWidgetDisplaying() { |
340 | 345 | this.changeAlignment = (this.ctx.$container && this.ctx.$container[0].offsetWidth < 620); |
341 | - this.smallWidthContainer = (this.ctx.$container && this.ctx.$container[0].offsetWidth < 420); | |
342 | 346 | } |
343 | 347 | |
344 | 348 | public onDataUpdated() { |
345 | - this.ngZone.run(() => { | |
349 | + // this.ngZone.run(() => { | |
346 | 350 | this.updateWidgetData(this.subscription.data); |
347 | 351 | this.ctx.detectChanges(); |
348 | - }); | |
352 | + // }); | |
349 | 353 | } |
350 | 354 | |
351 | 355 | private resize() { |
352 | - this.ngZone.run(() => { | |
356 | + // this.ngZone.run(() => { | |
353 | 357 | this.updateWidgetDisplaying(); |
354 | 358 | this.ctx.detectChanges(); |
355 | - }); | |
359 | + // }); | |
356 | 360 | } |
357 | 361 | |
358 | 362 | public getGroupTitle(datasource: Datasource): string { |
359 | - return createLabelFromDatasource(datasource, this.settings.groupTitle); | |
363 | + const groupTitle = createLabelFromDatasource(datasource, this.settings.groupTitle); | |
364 | + return this.utils.customTranslation(groupTitle, groupTitle); | |
365 | + } | |
366 | + | |
367 | + public getErrorMessageText(errorMessage, defaultMessage, messageValues?): string { | |
368 | + let messageText; | |
369 | + if (errorMessage && errorMessage.length) { | |
370 | + messageText = this.utils.customTranslation(errorMessage, errorMessage); | |
371 | + } else if (defaultMessage && defaultMessage.length) { | |
372 | + if (!messageValues) { | |
373 | + messageValues = {}; | |
374 | + } | |
375 | + messageText = this.translate.instant(defaultMessage, messageValues); | |
376 | + } else { | |
377 | + messageText = ''; | |
378 | + } | |
379 | + return messageText; | |
360 | 380 | } |
361 | 381 | |
362 | 382 | public visibleKeys(source: MultipleInputWidgetSource): MultipleInputWidgetDataKey[] { |
... | ... | @@ -480,8 +500,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
480 | 500 | if (tasks.length) { |
481 | 501 | forkJoin(tasks).subscribe( |
482 | 502 | () => { |
483 | - // this.multipleInputFormGroup.reset(undefined, {emitEvent: false}); | |
484 | 503 | this.multipleInputFormGroup.markAsPristine(); |
504 | + this.ctx.detectChanges(); | |
485 | 505 | if (this.settings.showResultMessage) { |
486 | 506 | this.ctx.showSuccessToast(this.translate.instant('widgets.input-widgets.update-successful'), |
487 | 507 | 1000, 'bottom', 'left', this.toastTargetId); |
... | ... | @@ -494,8 +514,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni |
494 | 514 | } |
495 | 515 | }); |
496 | 516 | } else { |
497 | - // this.multipleInputFormGroup.reset(undefined, {emitEvent: false}); | |
498 | 517 | this.multipleInputFormGroup.markAsPristine(); |
518 | + this.ctx.detectChanges(); | |
499 | 519 | } |
500 | 520 | } |
501 | 521 | ... | ... |