Serenity: How it's possible to call a custom confirmation BEFORE default confirmation?

Created on 1 Dec 2017  路  5Comments  路  Source: serenity-is/Serenity

Hi, Volkan Ceylan and all Serenity community!
I continue to learn great Serenity framework. Here I find an example of CancellableBulkAction. It looks as at screenshot

example

But, it's possible a case, when we need some custom check before final confirmation. To implement that feature, I added to CancellableBulkActionGrid.ts such code:

protected getButtons() {
            return [{
                title: 'Perform Bulk Action on Selected Orders',
                cssClass: 'send-button',
                onClick: () => {
                    if (!this.onViewSubmit()) {
                        return;
                    }

                    this.showCustomWarning("Warning").done(() => {
                        // they pressed OK
                        alert("Yes");
                    }).fail(() => {
                        // the pressed Cancel
                        alert("No");
                    });

                    var action = new OrderBulkAction();
                    action.done = () => this.rowSelection.resetCheckedAndRefresh();
                    action.execute(this.rowSelection.getSelectedKeys());
                }
            }];
        }
private showCustomWarning(title: string): JQueryPromise<Object> {
            var def = $.Deferred();

            $('<div class="ui-dialog ui-corner-all ui-widget ui-widget-content ui-front s-MessageDialog s-WarningDialog ui-dialog-buttons ui-draggable">' +
                '<div class="ui-dialog-content ui-widget-content">' +
                '<div class="message">Do you want to continue?' +
                '</div></div></div>').dialog({
                modal: true,
                title: title,
                buttons: {
                    Yes: function () {
                        def.resolve();
                        $(this).dialog("close");
                    },
                    No: function () {
                        def.reject();
                        $(this).dialog("close");
                    }
                }
            });

            return def.promise();
        }

But I catch unexpected behavior, see at screenshot:

needed

So, the default confirm window appears firstly and has greater priority than my custom confirm window, and I can't operate my own confirm window until the default confirm window is open. But I need, that my window appears firstly and only after clicking Yes or No the default window comes on.

Please, give me an advise, what should I do to implement this idea?

Most helpful comment

?
image

All 5 comments

image
image
image

?
image

Nice presentation @Zahar661 :)

@Zahar661 , great job!
Thank U very much)

Also it's possible such code:

protected getButtons() {
            return [{
                title: 'Perform Bulk Action on Selected Orders',
                cssClass: 'send-button',
                onClick: () => {
                    if (!this.onViewSubmit()) {
                        return;
                    }

                    Q.confirm(
                        "Do you want to continue?",
                        () => {
                            //Q.notifySuccess("Allright!");
                            var action = new OrderBulkAction();
                            action.done = () => this.rowSelection.resetCheckedAndRefresh();
                            action.execute(this.rowSelection.getSelectedKeys());
                        },
                        {
                            onNo: () => {
                                //Q.notifyInfo("You clicked NO. Why?");
                            },
                            onCancel: () => {
                                //Q.notifyError("You clicked X. Operation is cancelled. Will try again?");
                            },
                            title: "Some Custom Confirmation Title"
                        });
                }
            }];
        }

Perfect +1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stixoffire picture stixoffire  路  3Comments

dkontod picture dkontod  路  3Comments

ga5tan picture ga5tan  路  3Comments

StefanTheiner picture StefanTheiner  路  3Comments

dudeman972 picture dudeman972  路  3Comments