Liferay.com

Tuesday, April 8, 2014

Alloy vs jQuery comparison links

Thursday, April 3, 2014

JSON object parameter passing

I came across a scenario where I need to use Liferay's JSON API for display certain no of documents under each folder depending upon configuration/preferences selected/set.

I need to display certain # of records order by modified date descending order

I didn't find a one workable example when I googled for certain time, here comes the savior - liferay documentation helped me in this regard to say frankly

https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/json-web-services

Here is the code snippet I used

        var groupId = '<%= themeDisplay.getLayout().getGroupId() %>';
        var folderNames = ["Folder 1", "Folder 2", "Folder 3"]; //The names of the folders you wish to pull from and display;
        var auth = "<%= AuthTokenUtil.getToken(request) %>"; //url to the file that prints out the p_auth token

        function ajax(url, func, type) {
            result = '';
            jQuery.ajax({
                type: 'GET',
                url: url,
                func: func,
                dataType: type,
                async: false,
                success: function (data) {
                    result = data;
                }
            });
            return result;
        }

        jQuery(document).ready(function () {
            var html = '';
            var quickHitshtml = '';
            var whitePapershtml = '';
            var noOfDocsToDisplay = '<%= noOfMarketCommentaryDocs %>'; // reading value from preferences
            jQuery.each(folders, function (i, item) {
                if (jQuery.inArray(item.name, folderNames) > -1) {
                    var files = ajax("/api/jsonws/dlapp/get-file-entries/repository-id/" + groupId + "/folder-id/" + item.folderId + "/start/0/end/" + noOfDocsToDisplay + "/+obc:com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelModifiedDateComparator?p_auth=" + auth + "&callback=?", 'files', 'jsonp');
                }
            });
        });

please add relavent imports & porltet/theme should be loaded with jQuery

Liferay AUI 2.0 modules