简体   繁体   中英

Can I inject a client-side behaviour into the Umbraco 7 back-office using Angular?

I'm working with a customised Umbraco installation and I have a situation where I need to run a little extra user interaction when they click the 'Publish' button for the first time with certain types of content. In practice this will be to pop up a box that allows them to use a custom message when sharing the published content to a third-party service.

Although I am well versed in Javascript, I haven't spent a lot of time with Angular and what I have done has been fairly straight down the line.

In this case the editor uses the standard Angular controller built into Umbraco - what would be ideal would be to hook into the scope of that and add an event handler when the form is submitted, but I can't figure out how to access that and I suspect it may not be possible at all.

I have my JavaScript available in the page through a plugin but and I could access the form elements involved directly, but I feel as though that has the potential to be very fragile - particularly vulnerable to Umbraco updates - and it runs against the grain of the back-office in general.

Is there anything made available by Angular or Umbraco which would allow me to do this? If not, what would be the most practical way to insert this behaviour?

As you say doing this kind of thing is going to be prone to breaking during an update. Although using the IContentService events will not allow you to show a modal client side, I would recommend looking at registering an even handler on the IContentService.Saving event during the application startup.

public class ApplicationStartup : ApplicationEventHandler
{
    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication,
        ApplicationContext applicationContext)
    {
        ContentService.Saving += ApplicationEvents.ContentService_Saving;

        base.ApplicationStarting(umbracoApplication, applicationContext);
    }

    internal static void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
    {
        if (e != null && e.SavedEntities.Any())
        {
            foreach (var entity in e.SavedEntities.Where(content=> content.ContentType.Alias == "something"))
            {


            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM