Thursday, June 30, 2016

AEM6 | Customize create page wizard

To customize OOTB create page wizard you should perform following step(s) depending on the type of customization you are looking for-

1. Customize the template fields shown in wizard step-2

First, you need to override the cq:dialog of page component to configure what fields should be shown in create page wizard. In this dialog set the following property to true which you want to display in page create wizard-


cq:showOnCreate
Boolean
true



2. Customize the template selection step in wizard step-1

You need to write a clientlib file with following code to handle the template selection step-

This example explains how to auto select the template if only one template is available for selection-
$(document).on("foundation-contentloaded", function(e) {
    if (($(".foundation-collection-item").length==1) && ($(".foundation-collection-item.selected").length == 0)) {
        $('.foundation-collection-item').click();
        $(':button.coral-Wizard-nextButton').click(); 
    }
});

Category of the clientlibs can be any of this depending on your requirement- 
app.myproject.createpagewizard, cq.gui.siteadmin.admin.publishwizard, dam.gui.admin.publishassetwizard

In order to attach this new clientlibs to create page wizard, you need to overlay the wizard's head component and add your custom category i.e. "app.myproject.createpagewizard" as shown in below diagram-



3. Customize the confirmation Step-3

Once you have submitted the create page form, there comes a popup window for confirmation, if you want to modify the form submit behavior then you can do following customization-

(function(window, document, Granite, $) {
    "use strict";
    var ui = $(window).adaptTo("foundation-ui");

    function createPage(wizard) {
        $.ajax({
            type: wizard.prop("method"),
            url: wizard.prop("action"),
            contentType: wizard.prop("enctype"),
            data: wizard.serialize()
        }).done(function(html) {
            var $html = $(html);
            var edit = $html.find("a.cq-siteadmin-admin-createpage-edit");
            window.location = edit.prop("href");
        }).fail(function(xhr, error, errorThrown) {
            if (error === "error") {
                var $html = $(xhr.responseText);
                if ($html.find(".foundation-form-response-status-code").length > 0) {
                    var title = $html.find(".foundation-form-response-title").next().html();
                    var message = $html.find(".foundation-form-response-description").next().html();
                    ui.alert(title, message, "error");
                    return;
                }
            }
            ui.alert(error, errorThrown, "error");
        });
    }

    function submit(wizard) {
        var flag = true;
        if (flag == true && (wizard.prop("template").value.indexOf("/apps/myproject/templates/testTemplate") >= 0)) {
            $.ajax({
                url: "/bin/someservletpath/submit",
                method: "GET",
                data: {
                    url: wizard.prop("parentPath").value,
                    pageTemplate: wizard.prop("template").value
                },
                dataType: "html"
            }).done(function(res) {
                wizard.prop("parentPath").value = res;
                createPage(wizard);
            }).fail(function(res) {
                ui.alert(res, "error");
            });
        } else {
            createPage(wizard);
        }
    }

    $(document).on("submit", ".cq-siteadmin-admin-createpage", function(e) {
        e.preventDefault();
        submit($(this));
    });

})(window, document, Granite, Granite.$);

As mentioned in #2 above the category of clientlibs should be "app.myproject.createpagewizard" and associated to create page wizard via head component overlaying.

4 comments:

  1. HiVivek,

    I have a need set components in sidekick according to our component list. By default AEM supports alphabetical order to show components and this list needs to be changed.

    Thanks.

    ReplyDelete
  2. HiVivek,

    I have a need set components in sidekick according to our component list. By default AEM supports alphabetical order to show components and this list needs to be changed.

    Thanks.

    ReplyDelete
    Replies
    1. Here you can see line #442 in file- /libs/cq/ui/widgets/source/widgets/wcm/ComponentList.js

      Function cs.sort("ASC", function(a, b) is doing the sorting. You need to override this in order to change the OOTB.

      Delete
  3. Hi Neeraj,

    I remember there is one js - sidekick.js (Path- /libs/cq/ui/widgets/source/widgets/wcm/Sidekick.js)which has rendering script for sidekick. Look at that, it will give you idea on how to overwrite the component list rendering.

    Thanks,
    Vivek

    ReplyDelete

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...