【问题标题】:AEM6 - How can I edit a component in place without a dialog?AEM6 - 如何在没有对话框的情况下就地编辑组件?
【发布时间】:2016-12-18 07:10:54
【问题描述】:

我一直在尝试编辑 Table 组件(无需打开对话框),例如:添加新行或列。

该组件的对话框已正确配置,因此您可以从那里选择列数和行数,但为了改善用户体验,我在表格旁边添加了一个按钮,该按钮仅在编辑模式下可见以添加新行从 clientlib.edit javascript 以编程方式。但不知道实际持久化数据的方法是什么(保存更改)。

任何可以带我走上正确道路的想法将不胜感激!

【问题讨论】:

    标签: adobe aem aem-6


    【解决方案1】:

    一种可能的解决方案是基于 3 个组件 -

    1. 表格容器组件(只允许添加行组件,或者您可以允许拖放以使事情变得更简单)
    2. 行组件(另一个简单的容器组件)遵循行特定样式(允许添加列组件,使用组件编辑栏引入自定义“+”号允许添加列组件)
    3. 带有parsys的列组件(包含文本组件,使用基于模板的实现来实现,参考博客here

    要实现“+”号功能和持久性,请执行以下操作 -

    创建一个cq:ClientLibraryFolder并指定它的属性categories="cq.authoring.dialog",在这个客户端库中添加JS为-

    /* global Granite, $ */
    $(document).on('cq-page-info-loaded', function() {
        'use strict';
    
        // initialisation for Mysite
        window.mysite = window.mysite || {};
        window.mysite.app = window.mysite.app || {};
        window.mysite.app.auth = window.mysite.app.auth || {};
    
        (function(window, ns, undefined) {
            /**
             * Adds a child component of a specified type to a parent editable component.
             * (event handler for clicking the 'add' button in the edit interface on the sections or questions component)
             *
             * @param {Granite.author.Editable}     parentEditable      The editable parent component
             * @param {string}                      componentName       Name of the child component to add e.g. 'mysite-app/ui/components/content/link'
             * @param {boolean}                     componentTemplate   If true, call the low level interface directly. If false, call higher level Granite.author.edit methods.
             */
            var createChildComponent = function(parentEditable, componentName, componentTemplate) {
                return (
                    new ns.persistence.PostRequest()
                        .prepareCreateParagraph({
                            resourceType: componentName,
                            parentPath: parentEditable.path,
                            relativePosition: 'last',
                            templatePath: componentTemplate
                        })
                        .send()
                ).done(function() {
                    parentEditable.refresh();
                });
            };
    
            window.mysite.app.auth.component = (function() {
                return {
                    tablerow: {
                        add: function(editable) {
                            createChildComponent(editable, '/apps/mysite-app/ui/components/<path to row component>', false);
                        }
                    },
                    rowcell: {
                        add: function(editable) {
                            createChildComponent(editable, '/apps/mysite-app/ui/components/<path to column cell>', false);
                        }
                    }
                };
            })();
        })(window, Granite.author);
    
    });
    

    接下来是在editConfig 中为各个组件设置actionConfigs,并将其指向上述脚本的处理程序。

    <?xml version="1.0" encoding="UTF-8"?>
    <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
        cq:actions="[edit,delete]"
        jcr:primaryType="cq:EditConfig">
        <cq:actionConfigs jcr:primaryType="nt:unstructured">
            <addCell
                jcr:primaryType="nt:unstructured"
                handler="mysite.app.auth.component.rowcell.add"
                icon="coral-Icon--add"
                text="Add column to table row"/>
        </cq:actionConfigs>
    </jcr:root>
    

    在您的组件编辑栏上,您将开始看到“+”号,允许您添加已配置的组件并保留其节点。

    如果您需要更多详细信息,请参阅here 以将自定义操作添加到编辑栏。


    如果您不想遵循这种方法,第一个脚本具有允许您持久化组件节点的逻辑,您可以重用它并将其嵌入到您自己的实现中。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-14
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    相关资源
    最近更新 更多