首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除Umbraco的通知并显示我自己的通知

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

Stack Overflow用户
提问于 2015-06-05 14:50:57
回答 1查看 973关注 0票数 2

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

代码语言:javascript
复制
angular.module('umbraco').controller('MyController',
function ($scope, notificationsService) {
    notificationsService.success("Exito", "El usuario fue creado exitosamente");          
});

但是,通知总是显示是“成功”事件还是错误事件,并不重要。请帮帮我!

EN

回答 1

Stack Overflow用户

发布于 2015-06-11 10:03:43

如果要为默认消息添加自定义消息,则需要编写处理程序并将其添加到Umbraco启动类中。参见从umbraco论坛添加自定义消息的示例。

代码语言:javascript
复制
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);
    }
}

注意:上面的是用于内容发布消息的,如果您希望它为Media request.RequestUri.AbsolutePath.ToLower() == "/umbraco/backoffice/umbracoapi/media/postsave"工作,那么request.RequestUri.AbsolutePath.ToLower() == "/umbraco/backoffice/umbracoapi/media/postsave"应该替换示例中的请求URI。此外,也可以检查和替换其他标准,而不是发布。

有关详细讨论,请参见乌姆拉科论坛

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30669558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档