Confirmation dialog supports checkboxes
This commit is contained in:
parent
4d045682ab
commit
2cfe09a070
@ -31,8 +31,9 @@ import { MatButtonModule } from '@angular/material/button';
|
|||||||
import { MatDialogModule } from '@angular/material/dialog';
|
import { MatDialogModule } from '@angular/material/dialog';
|
||||||
import { CapitalizePipe } from './utils/pipes/capitalize.pipe';
|
import { CapitalizePipe } from './utils/pipes/capitalize.pipe';
|
||||||
import { KeycloakAngularModule } from 'keycloak-angular';
|
import { KeycloakAngularModule } from 'keycloak-angular';
|
||||||
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
|
|
||||||
const matModules = [MatIconModule, MatProgressSpinnerModule, MatButtonModule, MatDialogModule];
|
const matModules = [MatIconModule, MatProgressSpinnerModule, MatButtonModule, MatDialogModule, MatCheckboxModule];
|
||||||
const modules = [
|
const modules = [
|
||||||
TranslateModule,
|
TranslateModule,
|
||||||
IqserIconsModule,
|
IqserIconsModule,
|
||||||
|
|||||||
@ -3,6 +3,13 @@
|
|||||||
{{ config.title }}
|
{{ config.title }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="showToast" class="inline-dialog-toast toast-error">
|
||||||
|
<div [translate]="config.toastMessage"></div>
|
||||||
|
<a (click)="showToast = false" class="toast-close-button">
|
||||||
|
<mat-icon svgIcon="iqser:close"></mat-icon>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="dialog-content">
|
<div class="dialog-content">
|
||||||
<p [class.heading]="isDeleteAction" [innerHTML]="config.question" class="mt-0 mb-8"></p>
|
<p [class.heading]="isDeleteAction" [innerHTML]="config.question" class="mt-0 mb-8"></p>
|
||||||
<p *ngIf="config.details" [innerHTML]="config.details" class="mt-0"></p>
|
<p *ngIf="config.details" [innerHTML]="config.details" class="mt-0"></p>
|
||||||
@ -11,6 +18,15 @@
|
|||||||
<label>{{ inputLabel }}</label>
|
<label>{{ inputLabel }}</label>
|
||||||
<input [(ngModel)]="inputValue" />
|
<input [(ngModel)]="inputValue" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="config.checkboxes.length > 0" class="mt-24 checkboxes-wrapper">
|
||||||
|
<ng-container *ngFor="let checkbox of config.checkboxes">
|
||||||
|
<mat-checkbox [(ngModel)]="checkbox.value" [class.error]="!checkbox.value && showToast" color="primary">
|
||||||
|
{{ checkbox.label | translate: config.translateParams }}
|
||||||
|
</mat-checkbox>
|
||||||
|
<ng-container *ngTemplateOutlet="checkbox.extraContent; context: { data: checkbox.extraContentData }"></ng-container>
|
||||||
|
</ng-container>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dialog-actions">
|
<div class="dialog-actions">
|
||||||
@ -27,19 +43,18 @@
|
|||||||
(click)="confirm(ConfirmOptions.SECOND_CONFIRM)"
|
(click)="confirm(ConfirmOptions.SECOND_CONFIRM)"
|
||||||
*ngIf="config.alternativeConfirmationText"
|
*ngIf="config.alternativeConfirmationText"
|
||||||
[disabled]="config.requireInput && confirmationDoesNotMatch()"
|
[disabled]="config.requireInput && confirmationDoesNotMatch()"
|
||||||
[ngClass]="{'all-caps-label cancel': true}"
|
[ngClass]="{ 'all-caps-label cancel': true }"
|
||||||
color="primary"
|
color="primary"
|
||||||
mat-flat-button
|
mat-flat-button
|
||||||
|
|
||||||
>
|
>
|
||||||
{{ config.alternativeConfirmationText }}
|
{{ config.alternativeConfirmationText }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div *ngIf="config.discardChangesText" (click)="confirm(ConfirmOptions.DISCARD_CHANGES)" class="all-caps-label cancel">
|
<div (click)="confirm(ConfirmOptions.DISCARD_CHANGES)" *ngIf="config.discardChangesText" class="all-caps-label cancel">
|
||||||
{{ config.discardChangesText }}
|
{{ config.discardChangesText }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!config.discardChangesText" (click)="deny()" class="all-caps-label cancel">
|
<div (click)="deny()" *ngIf="!config.discardChangesText" class="all-caps-label cancel">
|
||||||
{{ config.denyText }}
|
{{ config.denyText }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
.warn {
|
.warn {
|
||||||
color: var(--iqser-red-1);
|
color: var(--iqser-red-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.checkboxes-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { ChangeDetectionStrategy, Component, HostListener, Inject } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, HostListener, Inject, TemplateRef } from '@angular/core';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||||
@ -16,6 +16,13 @@ export enum ConfirmOptions {
|
|||||||
DISCARD_CHANGES = 3,
|
DISCARD_CHANGES = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CheckBox {
|
||||||
|
value: boolean;
|
||||||
|
label: string;
|
||||||
|
extraContent?: TemplateRef<unknown>;
|
||||||
|
extraContentData?: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
export class ConfirmationDialogInput {
|
export class ConfirmationDialogInput {
|
||||||
title?: string;
|
title?: string;
|
||||||
titleColor?: TitleColor;
|
titleColor?: TitleColor;
|
||||||
@ -28,6 +35,8 @@ export class ConfirmationDialogInput {
|
|||||||
disableConfirm?: boolean;
|
disableConfirm?: boolean;
|
||||||
denyText?: string;
|
denyText?: string;
|
||||||
translateParams?: Record<string, unknown>;
|
translateParams?: Record<string, unknown>;
|
||||||
|
checkboxes?: CheckBox[];
|
||||||
|
toastMessage?: string;
|
||||||
|
|
||||||
constructor(options?: ConfirmationDialogInput) {
|
constructor(options?: ConfirmationDialogInput) {
|
||||||
this.title = options?.title || _('common.confirmation-dialog.title');
|
this.title = options?.title || _('common.confirmation-dialog.title');
|
||||||
@ -41,6 +50,8 @@ export class ConfirmationDialogInput {
|
|||||||
this.disableConfirm = options?.disableConfirm || false;
|
this.disableConfirm = options?.disableConfirm || false;
|
||||||
this.denyText = options?.denyText || _('common.confirmation-dialog.deny');
|
this.denyText = options?.denyText || _('common.confirmation-dialog.deny');
|
||||||
this.translateParams = options?.translateParams || {};
|
this.translateParams = options?.translateParams || {};
|
||||||
|
this.checkboxes = options?.checkboxes || [];
|
||||||
|
this.toastMessage = options?.toastMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +63,7 @@ export class ConfirmationDialogInput {
|
|||||||
export class ConfirmationDialogComponent {
|
export class ConfirmationDialogComponent {
|
||||||
config: ConfirmationDialogInput;
|
config: ConfirmationDialogInput;
|
||||||
inputValue = '';
|
inputValue = '';
|
||||||
|
showToast = false;
|
||||||
readonly inputLabel: string;
|
readonly inputLabel: string;
|
||||||
readonly ConfirmOptions = ConfirmOptions;
|
readonly ConfirmOptions = ConfirmOptions;
|
||||||
|
|
||||||
@ -62,9 +74,11 @@ export class ConfirmationDialogComponent {
|
|||||||
) {
|
) {
|
||||||
this.config = _confirmationDialogInput ?? new ConfirmationDialogInput();
|
this.config = _confirmationDialogInput ?? new ConfirmationDialogInput();
|
||||||
this.translate(this.config);
|
this.translate(this.config);
|
||||||
this.inputLabel = `${this._translateService.instant('confirmation-dialog.input-label')} '${
|
this.inputLabel = `${this._translateService.instant('confirmation-dialog.input-label')} '${this.config.confirmationText || ''}'`;
|
||||||
this.config.confirmationText || ''
|
}
|
||||||
}'`;
|
|
||||||
|
get uncheckedBoxes(): boolean {
|
||||||
|
return !!this.config.checkboxes?.some(c => !c.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isDeleteAction(): boolean {
|
get isDeleteAction(): boolean {
|
||||||
@ -87,7 +101,11 @@ export class ConfirmationDialogComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
confirm(option: ConfirmOptions): void {
|
confirm(option: ConfirmOptions): void {
|
||||||
this._dialogRef.close(option);
|
if (this.uncheckedBoxes) {
|
||||||
|
this.showToast = true;
|
||||||
|
} else {
|
||||||
|
this._dialogRef.close(option);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
translate(obj: ConfirmationDialogInput): void {
|
translate(obj: ConfirmationDialogInput): void {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user