Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jørgen Bakke Eriksen 44 posts 95 karma points
    Dec 20, 2016 @ 16:08
    Jørgen Bakke Eriksen
    0

    Intercept Save event and show confirmation dialog

    Hi.

    I've found several threads regarding some of the stuff I need to do but I haven't quite managed to get the whole picture and a strategy for making this work. Ergo this post.

    What I need to do:

    1. Intercept Save Event
    2. Do a check on ContentType of node beeing saved
    3. If ContentType in question: Display a confirmation dialog "Are you sure you wan't to save this..."
    4. If user confirms: just save, if not: cancel saving
    5. If NOT ContentType in Question, save content as normal

    Bullet 1. and 2. I have managed to get working by creating a ContentEventHandler extending ApplicationEventHandler:

    public class ContentEventHandler : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //register the event listener:
            ContentService.Saving += ContentService_Saving;
        }
        private void ContentService_Saving(IContentService sender, SaveEventArgs

    Bullet 3. I'm not sure how I should go about achieving. I've read some posts stating that you could register a javascript with the Page, and others stating that you can use the DialogService, showing Angular code. However I have a feeling that one should create a custom view and "register" this with the save event somehow similar to what one does when f.ex creating a custom MenuItem:

    var i = new MenuItem("someMenuItem", "Some Menu Item");
    i.AdditionalData.Add("actionView", "/App_Plugins/MyPlugin/someMenuItem.html");
    e.Menu.Items.Add(i);
    

    Bullet 4 I guess is dependent on the solution of bullet 3..

    As for bullet 5 I have managed to call the SaveAndPublishWithStatus() method. But is this actually necessary? Because by saving the content, my custom save event is triggered a second time. I guess I could put something on Session saying that we are now saving "manually", but I need some way of just skipping my code and going directly to the base. Would wrapping all of my event code make the original save function beeing called?

    Maybe I'm missing something here...

  • Jørgen Bakke Eriksen 44 posts 95 karma points
    Dec 21, 2016 @ 09:01
    Jørgen Bakke Eriksen
    0

    I have found Matt Brailsford's post on Tweaking Umbraco 7 Back Office.

    The Tweaking Views section describes how you can register an alternative edit GUI by using http interceptors.

    This would make me able to override what happens when you click the Save and Publish button.

    I was hoping there was a way which didn't involve modifying core files but probably there isn't.

Please Sign in or register to post replies

Write your reply to:

Draft