* keyDesc="My Description" 18n-keyDesc
* >
*/
-import {Directive, ElementRef, Input, OnInit} from '@angular/core';
+import {Directive, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
+import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
import {AccessKeyService} from '@eg/share/accesskey/accesskey.service';
@Directive({
// E.g. "navbar"
@Input() keyCtx: string;
+ // Optional; if set, a confirmation dialog will be shown
+ // and the click() action will be performed on confirmation
+ @Input() confirm?: string;
+
+ @ViewChild('confirmDialog', { static: true }) confirmDialog: ConfirmDialogComponent;
+
constructor(
private elm: ElementRef,
private keyService: AccessKeyService
key: keySpec,
desc: this.keyDesc,
ctx: this.keyCtx,
- action: () => this.elm.nativeElement.click()
+ action: () => {
+ // if a confirmation message was specified, show the dialog
+ if (this.confirm && this.confirm.length > 0) {
+ this.confirmDialog.open().subscribe(confirmed => {
+ if (!confirmed) { return; }
+
+ // confirmed? now we do the click()
+ this.elm.nativeElement.click();
+ });
+ }
+ // if no confirmation message was given, just do the click()
+ else
+ this.elm.nativeElement.click();
+ }
});
});
}
<span class="material-icons" aria-hidden="true">transform</span>
<span i18n>Restore Operator</span>
</a>
- <a class="dropdown-item" (click)="logout()">
+ <a class="dropdown-item" (click)="logout()"
+ egAccessKey keyCtx="navbar" i18n-keySpec i18n-keyDesc i18n-confirm
+ keySpec="alt+shift+q" keyDesc="Logout (Quit)" confirm="Log out now?">
<span class="material-icons" aria-hidden="true">lock_outline</span>
<span i18n>Logout</span>
</a>