AUI().ready( function(A) {
    courseListPortlet.fetchCourses();
});

Liferay.Portlet.ready( function(portletId, node) {

});

Liferay.on( 'allPortletsReady', function() {

});

var courseListPortlet = {};
courseListPortlet.fetchCourses = function() {
    AUI().use('aui-io', function(A) {
        var courseFetcher = function(config) {
            var node = config.host;
            var infomsg = node.getAttribute('data-infomsg');

            var msgNode = A.Node.create('<div></div>');
            msgNode.addClass('portlet-msg-info');
            msgNode.text(infomsg);

            msgNode.setStyles({
                marginBottom :'10em'
            });
            node.appendChild(msgNode);

            var resourceURL = node.getAttribute('data-resourceurl');
            node.plug(A.Plugin.IO, {
                uri: resourceURL,
                method: 'GET',
                headers: {
                    'Content-Type': 'text/html; charset=utf-8'
                }
            });
        }
        courseFetcher.NS = "coursefetcher";
        var ajaxList = A.one('#course-list-portlet-ajax-list');
        if (ajaxList) {
        	ajaxList.plug(courseFetcher);
        }
    });
};
