Request More Information

We are hiring!

Xtivia, Inc.
2013 North America Liferay Partner of the Year

Join our top-notch team of Enterprise Java and Liferay Portal professionals in our Austin, TX office or work remotely! Please check out our current Dice listings.

Recent Bloggers

Vamshidhar Srikantapuram
Posts: 6
Stars: 0
Date: 7/25/14
Matt Wolinski
Posts: 1
Stars: 0
Date: 7/24/14
Luke Smith
Posts: 14
Stars: 0
Date: 7/17/14
Bob Dietrich
Posts: 7
Stars: 0
Date: 7/1/14
Richard Ngo
Posts: 1
Stars: 0
Date: 6/19/14
Kaushik Nagaraj
Posts: 8
Stars: 0
Date: 5/22/14
Nick Ortman
Posts: 2
Stars: 0
Date: 5/9/14
Ron Peacock
Posts: 4
Stars: 0
Date: 5/9/14
Chris Shaw
Posts: 4
Stars: 0
Date: 5/7/14
Paul Anderson
Posts: 1
Stars: 0
Date: 5/6/14
« Back

Enhancing customizable pages in Liferay Portal

Liferay v6.1 introduced a new end-user customization capability wherein we can create a customizable page in a site that allows an end-user to add or remove portlets on the page or drag and drop portlets in different places on the page. In order to enable customization for a page, just go to Control Panel -> Site pages -> Select the page -> Customization Settings (or navigate to the page in question and select Manage Page in the dockar and choose Customization Settings), check the sections on the page that can be customized, and save the changes. Here's a screenshot of the Customization Settings screen:

Now login as a regular site member (non-admin), open this page, and you will see a new line on the top of the page:

This enables the user to add/remove portlets or drag and drop the portlets to different places on the page like this:

But at the same time, we probably don’t want to allow the end-user to perform certain changes:

  1. Re-configure the portlets on the page using the portlet configuration mode; note that by default, once you enable end-user customizations, Liferay does not enforce the portlet "configuration" permission and allows the end-user to configure all portlets in the customizable area even though the end-user should not be allowed to.
  2. Edit the portlet title for any portlet on the page

To disable the portlet configuration option for common users, we can add two lines of code in the “portlet.vm” file in the theme and update the theme:                      

            #if ($portlet_display.isShowBackIcon())
                <a class="portlet-icon-back" href="$portlet_back_url">#language("return-to-full-page")</a>
            #else
                #if ( ($permissionChecker.isCompanyAdmin() ) )    
                    $theme.iconOptions()
                #end

                $theme.iconMinimize()
                $theme.iconMaximize()
                $theme.iconClose()
            #end

To make portlet titles non-editable to the common users, login as administrator, go to Control Panel -> Site pages -> Select the page -> JavaScript, add the following javascript code on that page:

AUI().ready("aui-base", "event", "liferay-layout", "aui-node", "liferay-service",function(A) {
Liferay.Service.Portal.Role.hasUserRole(
    {
        userId: themeDisplay.getUserId(),
        companyId:themeDisplay.getCompanyId(),
        name: "Administrator",
        inherited: false
        },
        function(message) {
        var exception = message.exception;
        if (!exception) {
            if (message != true) {
                var portlets = Liferay.Layout.getPortlets();
                for(var i = 0; i < portlets.size(); i++) {
                    var portlet = portlets.item(i);
                    var portletNode = A.one('#p_p_id_' + portlet.portletId + "_");
                    var title = portletNode.one('.portlet-title-text');
                    title.swallowEvent('focus');
                    title.swallowEvent('hover');
                    title.swallowEvent('click');
                }
            } else return;
                }
               else return;
        });
});

Now the site member is not able to re-configure the portlets and change the portlet titles on a customizable page unless he/she is a site admin. If you want more granular control on who can edit portlet titles and configure portlets (and not just admins), it is doable but requires a little more work.

Comments
Trackback URL:

Join the discussion! Speak your mind! Be the first.

Request More Information