删除Umbraco的通知并显示我自己的通知

时间:2015-06-05 14:50:57

标签: asp.net angularjs content-management-system umbraco umbraco7

我是Umbraco的新手,我想删除所有Umbraco通知,并以我的语言显示我自己的通知。 我正在尝试使用此代码添加我的通知:

angular.module('umbraco').controller('MyController',
function ($scope, notificationsService) {
    notificationsService.success("Exito", "El usuario fue creado exitosamente");          
});

但是通知总是显示无关紧要,如果是成功"事件或错误事件。 请帮帮我!

1 个答案:

答案 0 :(得分:2)

您正在使用的方式适用于您创建的自定义部分,如果要为默认消息添加自定义消息,则需要编写处理程序并将其添加到Umbraco启动类。请参阅从umbraco论坛添加自定义消息的示例。

using Umbraco.Core;
public class CustomNotificationsRegistration : IApplicationEventHandler
{
    public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication,
        ApplicationContext applicationContext)
    { }

    public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication,
        ApplicationContext applicationContext)
    {
        System.Web.Http.GlobalConfiguration.Configuration.MessageHandlers.Add(new WebApiHandler());
    }

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication,
        ApplicationContext applicationContext)
    {
    }
}

using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Umbraco.Core.Logging;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.UI;
public class WebApiHandler : System.Net.Http.DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        if (request.RequestUri.AbsolutePath.ToLower() == "/umbraco/backoffice/umbracoapi/content/postsave")
        {
            return base.SendAsync(request, cancellationToken)
                .ContinueWith(task =>
                {
                    var response = task.Result;
                    try
                    {
                        var data = response.Content;
                        var content = ((ObjectContent)(data)).Value as ContentItemDisplay;

                        //perform any checking (if needed) to ensure you have the right request
                        //for us the cancellation of publish  was only on one content type so we could narrow that down here 
                        if (content.ContentTypeAlias.Equals("[My content type alias]"))
                        {
                            if (content.Notifications.Count > 0)
                            {
                                foreach (var notification in content.Notifications)
                                {
                                    if (notification.Header.Equals("Content Published"))
                                    {
                                        //change the default notification to our custom message
                                        notification.Header = "[Custom Header Message]";
                                        notification.Message = "[Custom Message]";
                                        notification.NotificationType = SpeechBubbleIcon.Sucess;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //log the error
                    }
                    return response;
                });
        }

        return base.SendAsync(request, cancellationToken);
    }
}

注意:上面是内容发布消息,如果您希望它适用于媒体request.RequestUri.AbsolutePath.ToLower() == "/umbraco/backoffice/umbracoapi/media/postsave",则应从示例中替换请求URI。而且,也可以检查和替换发布其他标准,而不是发布。

有关详细讨论,请参阅 umbraco forum