Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced confirm and confirmDelete functions in the Angular overlay service #6526

Merged
merged 2 commits into from
Oct 29, 2019

Conversation

abjerner
Copy link
Contributor

@abjerner abjerner commented Oct 1, 2019

Implementing #6507

Based on Bjarne's PR for a confirm overlay, this PR adds the confirm and confirmDelete methods to the Angular overlay service.

The confirm function has some default settings:

  • Specify the HTML view from Bjarne's PR
  • Set closeButtonLabelKey to general_cancel
  • Set submitButtonLabelKey to general_confirm
  • Add a default close callback which just closes the overlay

It looks like this:

image

The confirmDelete functions does what confirm does, but then also:

  • Set submitButtonStyle to danger
  • Set submitButtonLabelKey to contentTypeEditor_yesDelete

It looks like this:

image

I haven't updated the code in Bjarne's PR, but:

const overlay = {
    view: "confirm",
    title: data[0],
    content: confirmationMessage,
    confirmMessage: "This will delete the account.",
    confirmMessageStyle: "danger",
    closeButtonLabel: data[1],
    submitButtonLabel: data[2],
    submitButtonStyle: "danger",
    close: function () {
        vm.deleteNotLoggedInUserButtonState = "danger";
        overlayService.close();
    },
    submit: function () {
        //performDelete();
        overlayService.close();
    }
};
overlayService.open(overlay);

could now be shortened to:

const overlay = {
    title: data[0],
    content: confirmationMessage,
    confirmMessage: "This will delete the account.",
    confirmMessageStyle: "danger",
    close: function () {
        vm.deleteNotLoggedInUserButtonState = "danger";
        overlayService.close();
    },
    submit: function () {
        //performDelete();
        overlayService.close();
    }
};
overlayService.confirmDelete(overlay);

@bjarnef
Copy link
Contributor

bjarnef commented Oct 1, 2019

I wonder if it would be better just with a single confirm function and specify the type using a property in the dialog/overlay object?

E.g.:

const overlay = {
    title: data[0],
    content: confirmationMessage,
    confirmType: "delete",
    confirmMessage: "This will delete the account.",
    close: function () {
        vm.deleteNotLoggedInUserButtonState = "danger";
        overlayService.close();
    },
    submit: function () {
        //performDelete();
        overlayService.close();
    }
};
overlayService.confirm(overlay);

confirmMessageStyle could be default set to danger for confirmType: "delete".

It would then just use the same function, but adjust the layout of the confirm like the existing properties like confirmMessageStyle.

@nul800sebastiaan
Copy link
Member

Thanks @abjerner - we'll have a look soon!

@abjerner
Copy link
Contributor Author

I've now updated the PR according to Bjarne's suggestions. This means that the confirmDelete function is gone, and the confirm function now has an extra confirmType option.

Usage is as following:

Default confirm dialog (no explicit type):

$scope.default = function () {
    overlayService.confirm({
        title: "Hest",
        content: "Please confirm me.",
        confirmMessage: "Click the green \"Confirm\" button below to confirm this dialog.",
        //confirmMessageStyle: "danger",
        close: function () {
            overlayService.close();
        },
        submit: function () {
            overlayService.close();
        }
    });
};

Delete dialog:

$scope.danger = function () {
    overlayService.confirm({
        title: "Hest",
        content: "Please delete me.",
        confirmType: "delete",
        confirmMessage: "This will delete the account.",
        //confirmMessageStyle: "danger",
        close: function () {
            overlayService.close();
        },
        submit: function () {
            overlayService.close();
        }
    });
};

As also suggested by Bjarne, when confirmType is set to delete, some of the other options are automatically populated if they haven't been specified by the user:

switch (overlay.confirmType) {

    case "delete":
        if (!overlay.confirmMessageStyle) overlay.confirmMessageStyle = "danger";
        if (!overlay.submitButtonStyle) overlay.submitButtonStyle = "danger";
        if (!overlay.submitButtonLabelKey) overlay.submitButtonLabelKey = "contentTypeEditor_yesDelete";
        break;
    
    default:
        if (!overlay.submitButtonLabelKey) overlay.submitButtonLabelKey = "general_confirm";

}

@nul800sebastiaan nul800sebastiaan merged commit bfdbc4c into umbraco:v8/dev Oct 29, 2019
@nul800sebastiaan
Copy link
Member

Wonderful, thanks @abjerner !

@nul800sebastiaan
Copy link
Member

Now.. who's going to update the code for #5487 @abjerner @bjarnef ? 😁

@abjerner abjerner deleted the abjerner/overlay-confirm branch October 30, 2019 20:44
@abjerner
Copy link
Contributor Author

@nul800sebastiaan I can have a look at it tomorrow 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants