如何在某些Umbraco事件上显示UI通知?

问题描述 投票:4回答:2

代码是自我解释的:

public class TooLateValidator : IApplicationStartupHandler
    {
        public TooLateValidator()
        {
            ContentService.Saving += ContentService_Saving;
        }

        private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
        {
            if(DateTime.Now.Hour > 21){

                e.Cancel = true;

                //validation message: "it's too late for that"
                // how do I throw this message to UI??

            }
        }
    }

我正在使用Umbraco 6。

umbraco umbraco6
2个回答
1
投票

根据评论,这是一个模糊的问题,有许多可能的解决方案。很难看到你需要什么,但我会尝试理解。

Umbraco 6的一个突出缺点是语音气泡会显示自定义信息,但Umbraco自己会立即覆盖它们,但你现在可以轻松地做到这一点(感谢我的朋友Ali为代码source并在v6中为我工作) .1.6)。

using System.Web;
using System.Web.UI;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.UI;
using Umbraco.Web.UI.Pages;

public class UmbracoEvents : ApplicationEventHandler
{
    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        //Events
        ContentService.Created += Content_Created;
        ContentService.Saving += Content_Saving;
    }

    private void Content_Saving(IContentService sender, SaveEventArgs<IContent> e)
    {
        // 1 JavaScript 
        HttpContext.Current.Response.Write("<script>alert('Saved!');</script>");                        
        e.Cancel = true;

    }

    private void Content_Created(IContentService sender, NewEventArgs<IContent> e)
    {
        // 2 Umbraco speech bubble

        var clientTool = new ClientTools((Page)HttpContext.Current.CurrentHandler);
        clientTool.ShowSpeechBubble(SpeechBubbleIcon.Success, "Warning", "It is to late to do that!");
    }
}

0
投票

试试这个

 //validation message: "it's too late for that"
 // how do I throw this message to UI??

 e.Messages.Add(new EventMessage("validation message", "it's too late for that", EventMessageType.Error));
© www.soinside.com 2019 - 2024. All rights reserved.