[英]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. 我正在使用定制的Umbraco安装,并且遇到一种情况,当他们第一次单击带有某些类型内容的“发布”按钮时,我需要运行一些额外的用户交互。 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. 尽管我精通Java语言,但是我并没有花很多时间在Angular上,而我所做的事情一直很简单。
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. 在这种情况下,编辑器使用Umbraco内置的标准Angular控制器-理想的情况是挂接到表单的范围并在提交表单时添加事件处理程序,但我不知道如何访问该表单,我怀疑这根本不可能。
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. 我可以通过插件在页面上使用我的JavaScript,但是我可以直接访问涉及的表单元素,但是我觉得这很有可能会变得非常脆弱-特别是受Umbraco更新的影响-并且它与后台一般。
Is there anything made available by Angular or Umbraco which would allow me to do this? Angular或Umbraco是否提供任何可以让我做到这一点的东西? 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. 尽管使用IContentService
事件将不允许您显示模式客户端,但我还是建议您在应用程序启动过程中在IContentService.Saving
事件上注册一个偶数处理程序。
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"))
{
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.