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,7 +39,7 @@ | ||
39 | (blur)="key.isFocused = false; inputChanged(source, key)"> | 39 | (blur)="key.isFocused = false; inputChanged(source, key)"> |
40 | <mat-icon *ngIf="key.settings.icon" matPrefix>{{key.settings.icon}}</mat-icon> | 40 | <mat-icon *ngIf="key.settings.icon" matPrefix>{{key.settings.icon}}</mat-icon> |
41 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> | 41 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> |
42 | - {{key.settings.requiredErrorMessage}} | 42 | + {{ getErrorMessageText(key.settings.requiredErrorMessage, '') }} |
43 | </mat-error> | 43 | </mat-error> |
44 | </mat-form-field> | 44 | </mat-form-field> |
45 | </div> | 45 | </div> |
@@ -59,52 +59,54 @@ | @@ -59,52 +59,54 @@ | ||
59 | (blur)="key.isFocused = false; inputChanged(source, key)"> | 59 | (blur)="key.isFocused = false; inputChanged(source, key)"> |
60 | <mat-icon *ngIf="key.settings.icon" matPrefix>{{key.settings.icon}}</mat-icon> | 60 | <mat-icon *ngIf="key.settings.icon" matPrefix>{{key.settings.icon}}</mat-icon> |
61 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> | 61 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')"> |
62 | - {{key.settings.requiredErrorMessage}} | 62 | + {{ getErrorMessageText(key.settings.requiredErrorMessage, '') }} |
63 | </mat-error> | 63 | </mat-error> |
64 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('min')"> | 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 | </mat-error> | 68 | </mat-error> |
67 | <mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('max')"> | 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 | </mat-error> | 73 | </mat-error> |
70 | </mat-form-field> | 74 | </mat-form-field> |
71 | </div> | 75 | </div> |
72 | <div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanCheckbox'"> | 76 | <div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanCheckbox'"> |
73 | <mat-checkbox formControlName="{{key.formId}}" | 77 | <mat-checkbox formControlName="{{key.formId}}" |
74 | (change)="inputChanged(source, key)"> | 78 | (change)="inputChanged(source, key)"> |
75 | - {{key.label}} | 79 | + <span class="label-wrapper">{{key.label}}</span> |
76 | </mat-checkbox> | 80 | </mat-checkbox> |
77 | </div> | 81 | </div> |
78 | <div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanSwitch'"> | 82 | <div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanSwitch'"> |
79 | <mat-slide-toggle formControlName="{{key.formId}}" | 83 | <mat-slide-toggle formControlName="{{key.formId}}" |
80 | (change)="inputChanged(source, key)"> | 84 | (change)="inputChanged(source, key)"> |
81 | - {{key.label}} | 85 | + <span class="label-wrapper">{{key.label}}</span> |
82 | </mat-slide-toggle> | 86 | </mat-slide-toggle> |
83 | </div> | 87 | </div> |
84 | <div class="input-field mat-block date-time-input" *ngIf="(key.settings.dataKeyValueType === 'dateTime') || | 88 | <div class="input-field mat-block date-time-input" *ngIf="(key.settings.dataKeyValueType === 'dateTime') || |
85 | (key.settings.dataKeyValueType === 'date') || | 89 | (key.settings.dataKeyValueType === 'date') || |
86 | (key.settings.dataKeyValueType === 'time')" fxLayout="column"> | 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 | </div> | 110 | </div> |
109 | </div> | 111 | </div> |
110 | </div> | 112 | </div> |
@@ -114,12 +116,12 @@ | @@ -114,12 +116,12 @@ | ||
114 | <button mat-button color="primary" type="button" | 116 | <button mat-button color="primary" type="button" |
115 | (click)="discardAll()" style="max-height: 50px; margin-right:20px;" | 117 | (click)="discardAll()" style="max-height: 50px; margin-right:20px;" |
116 | [disabled]="!multipleInputFormGroup.dirty"> | 118 | [disabled]="!multipleInputFormGroup.dirty"> |
117 | - {{ 'action.undo' | translate }} | 119 | + {{ settings.resetButtonLabel }} |
118 | </button> | 120 | </button> |
119 | <button mat-button mat-raised-button color="primary" type="submit" | 121 | <button mat-button mat-raised-button color="primary" type="submit" |
120 | style="max-height: 50px; margin-right:20px;" | 122 | style="max-height: 50px; margin-right:20px;" |
121 | [disabled]="!multipleInputFormGroup.dirty || multipleInputFormGroup.invalid"> | 123 | [disabled]="!multipleInputFormGroup.dirty || multipleInputFormGroup.invalid"> |
122 | - {{ 'action.save' | translate }} | 124 | + {{ settings.saveButtonLabel }} |
123 | </button> | 125 | </button> |
124 | </div> | 126 | </div> |
125 | </div> | 127 | </div> |
@@ -44,7 +44,13 @@ | @@ -44,7 +44,13 @@ | ||
44 | display: block; | 44 | display: block; |
45 | margin-top: 20px; | 45 | margin-top: 20px; |
46 | margin-bottom: 16px; | 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 | .date-time-input { | 56 | .date-time-input { |
@@ -56,20 +62,6 @@ | @@ -56,20 +62,6 @@ | ||
56 | 62 | ||
57 | .vertical-alignment { | 63 | .vertical-alignment { |
58 | flex-direction: column; | 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,6 +47,8 @@ interface MultipleInputWidgetSettings { | ||
47 | widgetTitle: string; | 47 | widgetTitle: string; |
48 | showActionButtons: boolean; | 48 | showActionButtons: boolean; |
49 | updateAllValues: boolean; | 49 | updateAllValues: boolean; |
50 | + saveButtonLabel: string; | ||
51 | + resetButtonLabel: string; | ||
50 | showResultMessage: boolean; | 52 | showResultMessage: boolean; |
51 | showGroupTitle: boolean; | 53 | showGroupTitle: boolean; |
52 | groupTitle: string; | 54 | groupTitle: string; |
@@ -67,27 +69,19 @@ interface MultipleInputWidgetDataKeySettings { | @@ -67,27 +69,19 @@ interface MultipleInputWidgetDataKeySettings { | ||
67 | maxValue?: number; | 69 | maxValue?: number; |
68 | requiredErrorMessage?: string; | 70 | requiredErrorMessage?: string; |
69 | invalidDateErrorMessage?: string; | 71 | invalidDateErrorMessage?: string; |
70 | - minErrorMessage?: string; | ||
71 | - maxErrorMessage?: string; | 72 | + minValueErrorMessage?: string; |
73 | + maxValueErrorMessage?: string; | ||
72 | icon: string; | 74 | icon: string; |
73 | inputTypeNumber?: boolean; | 75 | inputTypeNumber?: boolean; |
74 | readOnly?: boolean; | 76 | readOnly?: boolean; |
75 | disabledOnCondition?: boolean; | 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 | interface MultipleInputWidgetDataKey extends DataKey { | 80 | interface MultipleInputWidgetDataKey extends DataKey { |
86 | formId?: string; | 81 | formId?: string; |
87 | settings: MultipleInputWidgetDataKeySettings; | 82 | settings: MultipleInputWidgetDataKeySettings; |
88 | isFocused: boolean; | 83 | isFocused: boolean; |
89 | value?: any; | 84 | value?: any; |
90 | - errorMessages?: MultipleInputWidgetDataKeyErrorMessages; | ||
91 | } | 85 | } |
92 | 86 | ||
93 | interface MultipleInputWidgetSource { | 87 | interface MultipleInputWidgetSource { |
@@ -170,6 +164,17 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | @@ -170,6 +164,17 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | ||
170 | 164 | ||
171 | this.settings.groupTitle = this.settings.groupTitle || '${entityName}'; | 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 | // For backward compatibility | 178 | // For backward compatibility |
174 | if (isUndefined(this.settings.showActionButtons)) { | 179 | if (isUndefined(this.settings.showActionButtons)) { |
175 | this.settings.showActionButtons = true; | 180 | this.settings.showActionButtons = true; |
@@ -338,25 +343,40 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | @@ -338,25 +343,40 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | ||
338 | 343 | ||
339 | private updateWidgetDisplaying() { | 344 | private updateWidgetDisplaying() { |
340 | this.changeAlignment = (this.ctx.$container && this.ctx.$container[0].offsetWidth < 620); | 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 | public onDataUpdated() { | 348 | public onDataUpdated() { |
345 | - this.ngZone.run(() => { | 349 | + // this.ngZone.run(() => { |
346 | this.updateWidgetData(this.subscription.data); | 350 | this.updateWidgetData(this.subscription.data); |
347 | this.ctx.detectChanges(); | 351 | this.ctx.detectChanges(); |
348 | - }); | 352 | + // }); |
349 | } | 353 | } |
350 | 354 | ||
351 | private resize() { | 355 | private resize() { |
352 | - this.ngZone.run(() => { | 356 | + // this.ngZone.run(() => { |
353 | this.updateWidgetDisplaying(); | 357 | this.updateWidgetDisplaying(); |
354 | this.ctx.detectChanges(); | 358 | this.ctx.detectChanges(); |
355 | - }); | 359 | + // }); |
356 | } | 360 | } |
357 | 361 | ||
358 | public getGroupTitle(datasource: Datasource): string { | 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 | public visibleKeys(source: MultipleInputWidgetSource): MultipleInputWidgetDataKey[] { | 382 | public visibleKeys(source: MultipleInputWidgetSource): MultipleInputWidgetDataKey[] { |
@@ -480,8 +500,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | @@ -480,8 +500,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | ||
480 | if (tasks.length) { | 500 | if (tasks.length) { |
481 | forkJoin(tasks).subscribe( | 501 | forkJoin(tasks).subscribe( |
482 | () => { | 502 | () => { |
483 | - // this.multipleInputFormGroup.reset(undefined, {emitEvent: false}); | ||
484 | this.multipleInputFormGroup.markAsPristine(); | 503 | this.multipleInputFormGroup.markAsPristine(); |
504 | + this.ctx.detectChanges(); | ||
485 | if (this.settings.showResultMessage) { | 505 | if (this.settings.showResultMessage) { |
486 | this.ctx.showSuccessToast(this.translate.instant('widgets.input-widgets.update-successful'), | 506 | this.ctx.showSuccessToast(this.translate.instant('widgets.input-widgets.update-successful'), |
487 | 1000, 'bottom', 'left', this.toastTargetId); | 507 | 1000, 'bottom', 'left', this.toastTargetId); |
@@ -494,8 +514,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | @@ -494,8 +514,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni | ||
494 | } | 514 | } |
495 | }); | 515 | }); |
496 | } else { | 516 | } else { |
497 | - // this.multipleInputFormGroup.reset(undefined, {emitEvent: false}); | ||
498 | this.multipleInputFormGroup.markAsPristine(); | 517 | this.multipleInputFormGroup.markAsPristine(); |
518 | + this.ctx.detectChanges(); | ||
499 | } | 519 | } |
500 | } | 520 | } |
501 | 521 |