///
import * as ko from "knockout";
import { PopupBase } from "../ui/popupbase";
type PromiseOrVoid = void | Promise;
export class CustomPopup extends PopupBase {
public title: KnockoutObservable;
public messages: KnockoutObservableArray;
public buttons = ko.observableArray([]);
public actions = ko.observableArray<() => PromiseOrVoid>([]);
public deferred: JQueryDeferred;
constructor() {
super();
this.title = ko.observable();
this.messages = ko.observableArray();
}
public shown() {
super.shown();
this.deferred = $.Deferred();
}
public close() {
super.close();
this.deferred.reject();
}
public execute(index: number) {
const action = this.actions()[index];
const result = action();
super.close();
if (result === undefined) {
this.deferred.reject();
} else {
this.deferred.resolve(result);
}
}
}