AEM 6 SP 2- Classic UI Create Page and Open in Scaffolding View

Goal


Extend the Classic UI create page dialog to create & open in scaffolding view. A similar post on extending the dialog to provide create & view is here

Demo | Package Install




Solution


1) Login to CRXDE Lite, create folder (nt:folder) /apps/create-page-open-scaffolding-view

2) Create clientlib (type cq:ClientLibraryFolder/apps/create-page-open-scaffolding-view/clientlib and set a property categories of String type to cq.widgets

3) Create file ( type nt:file ) /apps/create-page-open-scaffolding-view/clientlib/js.txt, add the following

                         open.js

4) Create file ( type nt:file ) /apps/create-page-open-scaffolding-view/clientlib/open.js, add the following code

(function(){
    var cqCreatePageDialog = CQ.wcm.Page.getCreatePageDialog;

    CQ.wcm.Page.getCreatePageDialog = function(parentPath){
        var dialog = cqCreatePageDialog(parentPath);

        var panel = dialog.findBy(function(comp){
            return comp["jcr:primaryType"] == "cq:Panel";
        }, dialog);

        if(!panel || panel.length == 0){
            return;
        }

        dialog.buttons.splice(0,0,new CQ.Ext.Button( {
                text: "Scaffolding View",
                width: 140,
                tooltip: 'Create page and open in scaffolding view',
                handler: function(button){
                    dialog.ok(button, function(form, resp){
                        try{
                            var text = resp.response.responseText;
                            var loc = text.substring(text.indexOf("\"", text.indexOf("href=")) + 1);

                            loc = "/cf#" + loc.substr(0, loc.indexOf("\"")) + ".scaffolding.html";
                            window.location = loc;
                        }catch(err){
                            console.log("page create and scaffolding view - error parsing html response");
                        }
                    });
                }}
        ));

        return dialog;
    }
})();

No comments:

Post a Comment