Copied to clipboard

Flag this post as spam?

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


  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Nov 04, 2016 @ 12:25
    Alex Skrypnyk
    1

    Intercepting save event in the backoffice

    Hello Community,

    What is the right way to intercept save event in the backoffice with AngularJS.

    We have to extend save button functionality and add some callback to start saving event and to saved even, is it possible?

    Thanks,

    Alex

  • ThisIsMeJKB 6 posts 99 karma points
    Nov 04, 2016 @ 12:54
    ThisIsMeJKB
    2

    I, unfortunately, don't have an answer for this but this is something I will need to be able to do myself in the not too distant future.....so I figured I would post so others could see the "demand" for this knowledge, haha.

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Nov 04, 2016 @ 13:45
    Dennis Adolfi
    2

    Hi Alex and ThisIsMeJKB.

    You do this by creating a custom ApplicationEventHandler class.

    Here is an example of how to do this:

    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    public class MyApplicationEvents : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                ContentService.Saving += ContentService_Saving; // rasied before the content has been saved.
                ContentService.Saved += ContentService_Saving; // raised after the content has been saved.
                base.ApplicationStarted(umbracoApplication, applicationContext);
            }
    
            /// <summary>
            /// Event raised when content is saved/saving.
            /// </summary>
            /// <param name="contentService">Can be used for creating/deleting/editing/move other content etc.</param>
            /// <param name="eventArgs">Can be used for showing custom notifications, canceling the save event, and accessing the content beeing saved etc.</param>
            private void ContentService_Saving(IContentService contentService, SaveEventArgs<IContent> eventArgs)
            {
                /* Do custom wizard stuff here.. */
            }
        }
    

    Hope this was useful.

    Take care!

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Nov 04, 2016 @ 13:50
    Dennis Adolfi
    1

    NOTE: You probobly wont have the same method for both the ContentService.Saving and ContentService.Saved event, cuz that would case the same method to be rasied twice every time you save a piece of content. You probobly have two different methods for each event or you might only be needing the Saving or Saved event.

    I just wrote like this in my example so that you would see that its possible to hook in before and after the content saves.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Nov 04, 2016 @ 13:51
    Alex Skrypnyk
    0

    Hi Dennis,

    Thank you very much for your reply, but I wanted more to use it in angular if possible, maybe I had to explaine better, but thanks again for youur answer.

    Thanks,

    Alex

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Nov 04, 2016 @ 13:56
    Dave Woestenborghs
    101

    Hi Alex,

    Matt Brailsford wrote about this on last years 24 days in Umbraco calendar.

    http://24days.in/umbraco/2015/umbraco-7-back-office-tweaks/

    Especially the part about tweaking logic is what you are after.

    Dave

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Nov 04, 2016 @ 13:56
    Dennis Adolfi
    1

    Ah, im sorry.

    Did´nt see any Angular mentions in your original post. :/

    Maybe someone else will be happy for the code example.

    Have a great weekend Alex!

  • ThisIsMeJKB 6 posts 99 karma points
    Nov 04, 2016 @ 14:24
    ThisIsMeJKB
    1

    Your original response is exactly what I was looking for you.

    thanks!

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Nov 04, 2016 @ 15:30
    Alex Skrypnyk
    1

    Very big thank you to Dennis and Dave, you solved 2 topics!!!

    Dave your link is exactly what I need.

    Have a great weekend!

    Thanks,

    Alex

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Nov 05, 2016 @ 09:26
    Dennis Adolfi
    0

    Great! Glad to help!! :)

  • Thomas Higginbotham 4 posts 81 karma points
    Jul 23, 2019 @ 12:57
    Thomas Higginbotham
    0

    The ApplicationEventHandler approach no longer works in Umbraco 8. Instead, you'll need to use composition.

    The Umbraco documentation provides an example of how to listen to ContentService.Saving events.

Please Sign in or register to post replies

Write your reply to:

Draft