在单击“保存”按钮之后和保存更改之前,在内容选项卡中更改节点的未保存属性值。一把umbraco

时间:2012-12-16 01:06:42

标签: umbraco

更新

我想在BackOffice的内容选项卡上获取一个节点的属性值,该值在单击“保存”按钮之后和以编程方式保存更改之前已更改。

该节点可以包含许多属性。单击保存按钮时,我想首先获取节点属性的新更改值。我认为Umbraco应该有API来获取服务器端的那些。

任何想法都会非常感激。

2 个答案:

答案 0 :(得分:1)

您希望连接到IApplicationEventHandler类中的Document.BeforeSave方法。像这样(假设你将bodyText从“apple”改为“orange”):

using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Web;


namespace ClassLibrary1
{
    public class Class1 : IApplicationEventHandler
    {
        public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
        {
            Document.BeforeSave += new Document.SaveEventHandler(Document_BeforeSave);
            Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave);
        }

        void Document_BeforeSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
        {
            // your code goes here!
            sender.getProperty("bodyText").Value // returns apple
        }

        void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
        {
            // your code goes here!
            sender.getProperty("bodyText").Value // returns orange
        }

        public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
        {
            // unused
        }

        public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext)
        {
            // unused
        }

    }
}

我在Umbraco 4.11中进行了测试

干杯

乔纳森

答案 1 :(得分:0)

您可以使用jquery事件处理程序,该处理程序针对要检查更改的umbraco管理员中的字段。此示例将通过查找要监视的umbraco字段的标签然后添加jquery事件处理程序来工作,该事件处理程序将在标签的兄弟字段更改时触发 - 此示例将适用于对“名称”的任何更改'每个节点的'属性'选项卡上的字段。不同的字段类型将以不同的方式保存值,因此$(this).val()通常应该适用于大多数 - 但不是所有字段类型。

将其放入\ umbraco \ editcontent.aspx

的末尾
    <script type="text/javascript">
        $(document).ready(function () {
            $("div.propertyItemheader:contains('Name') + div.propertyItemContent").keyup(function () {
                alert("field changed");
            });

        });
</script>