【问题标题】:Remove Umbraco's notifications and show my own notifications删除 Umbraco 的通知并显示我自己的通知
【发布时间】:2015-06-05 14:50:57
【问题描述】:

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

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

但是无论是“成功”事件还是错误事件,通知总是显示。 请帮帮我!

【问题讨论】:

  • 不确定你的语言是什么,但你可以在 Umbraco 中安装/激活一堆语言并将它们设置为编辑器的默认语言。您确定您的语言不可用吗?
  • 我想使用我的自定义消息,而不仅仅是我的语言。例如:Digite no mas de 20 caracteres。 @JannikAnker

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


【解决方案1】:

您正在为您创建的自定义部分工作的方式,如果您想为默认消息添加自定义消息,您需要编写处理程序并将其添加到 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。并且也可以检查和替换其他标准,而不是 Publish。

详细讨论见umbraco forum

【讨论】:

    猜你喜欢
    • 2020-03-25
    • 2023-03-15
    • 2019-08-21
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    相关资源
    最近更新 更多