//used for the listing of UGC data if (!window.ccs.ugc) { ccs.ugc = {}; // package declaration } ccs.ugc.path = '/shared/content/ugc_content/'; ccs.ugc.ugcpath = ccs.contextPath + "/ugc/" + ccs.appName + "/" + ccs.languageCode + "/"; ccs.ugc.List = function() { var self; var oid; var curMaxItems; var curOrder; var curOverrideScheme; // constructor function function constructorFn() { self = this; } // init function called once document is loaded constructorFn.prototype.init = function(objectid) { oid = objectid; } //adds any ccs request vars to the request, like clear cache etc so that the ajax also gets cleared //also passes on any variables statring with ugc_pass_, allowing the calling page to manipulate ugc call constructorFn.prototype.addCCSVars = function () { var additionalPars = ""; var h = location.href; var posQ = h.indexOf("?"); if (posQ > -1) { pars = h.substring(posQ + 1, h.length); var nameVals = pars.split("&"); for (i = 0; i < nameVals.length; i++) { var nameVal = nameVals[i].split("="); if (nameVal.length == 2) { if (nameVal[0].indexOf("ccs_") == 0 || nameVal[0].indexOf("ugc_pass_") == 0 ) { additionalPars += "&" + nameVals[i]; } } } } return additionalPars; } //extract the page name fro the current URL constructorFn.prototype.getPageName = function () { var h = location.href; var posQ = h.indexOf("?"); //trim off parameters if (posQ > -1) { h = h.substring(0, posQ); } posQ = h.lastIndexOf("/"); if (posQ > -1) { h = h.substring(posQ + 1, h.length); } return h; } //paging constructorFn.prototype.showPage = function (page) { if ($("ugcPage_" + oid + "_" + page)) { $("ugcPageContent_" + oid).innerHTML = $("ugcPage_" + oid + "_" + page).value for (i = 1; i <= $("ugcPageSelect_" + oid).options.length; i++) { if ($("ugc_paging_" + oid + "_" + i)) { $("ugc_paging_" + oid + "_" + i).className = "ugc_paging_page_normal"; } } if ($("ugc_paging_" + oid + "_" + page)) { $("ugc_paging_" + oid + "_" + page).className = "ugc_paging_page_highlight"; } //we need to hide/show the next/previous links var iPage = 1 * page; //ensure int if (iPage == 1) { //hide the previous link, we are on the first page $("ugcPageNext_" + oid).style.display = 'block'; } else { $("ugcPageNext_" + oid).style.display = 'none'; } if (iPage == $("ugcPageSelect_" + oid).options.length) { //hide the previous link, we are on the last page $("ugcPagePrevious_" + oid).style.display = 'block'; } else { $("ugcPagePrevious_" + oid).style.display = 'none'; } } else { alert("Invalid page " + page); } } //paging constructorFn.prototype.showPrevious = function (page) { if ($("ugcPageSelect_" + oid).selectedIndex > 0) { $("ugcPageSelect_" + oid).selectedIndex -= 1; self.showPage($("ugcPageSelect_" + oid).selectedIndex + 1); } } //paging constructorFn.prototype.showNext = function (page) { if ($("ugcPageSelect_" + oid).selectedIndex < $("ugcPageSelect_" + oid).options.length) { $("ugcPageSelect_" + oid).selectedIndex += 1; self.showPage($("ugcPageSelect_" + oid).selectedIndex + 1); } } //makes an ajax request to load the html for setting up the UGC constructorFn.prototype.loadList = function (maxItems, order, cc, overrideScheme) { self.showLoader(); if (maxItems != null) { curMaxItems = maxItems; } else { maxItems = curMaxItems; } if (order != null) { curOrder = order; } else { order = curOrder; } if (overrideScheme != null) { curOverrideScheme = overrideScheme; } else { overrideScheme = curOverrideScheme; } ccPar = ""; if (cc) { ccPar= "&ccs_clear_cache=1" } referer_page = self.getPageName(); new Ajax.Request(ccs.ugc.ugcpath + oid + ".html?type=list&max_items=" + maxItems + "&order=" + order + ccPar + self.addCCSVars() + "&referer_page=" + referer_page + "&sn=" + overrideScheme , { method:'get', onSuccess: function(transport) { var listing = transport.responseText; $("ugcList_" + oid).innerHTML = listing; self.hideLoader(); if ($("ugcPageSelect_" + oid)) { self.showPage(1); $("ugcPageSelect_" + oid).selectedIndex = 0; } self.hideVoteControls(); }, onFailure: function(transport) { //the error is not json...its html so we simply plonk it in the display $("ugcList_" + oid).innerHTML = transport.responseText; self.hideLoader(); } }); } //makes an ajax request to load the html for setting up the UGC constructorFn.prototype.hideVoteControls = function () { var voteCookie = getCookie("vids"); if (voteCookie != null) { var votedIds = voteCookie.split("X"); var message = $('votedMessage' + oid).innerHTML; for (var i=0; i < votedIds.length; i++) { if ($('voteControls' + votedIds[i])) { $('voteControls' + votedIds[i]).innerHTML = message; } } } } //makes an ajax request to load the html for setting up the UGC constructorFn.prototype.refreshList = function () { self.loadList(); } //makes an ajax request to load the html for setting up the UGC constructorFn.prototype.refreshListForVote = function () { self.loadList(null, null, true, null); } constructorFn.prototype.showLoader = function () { //hide loader $("ugcListLoader_" + oid).style.visibility = "visible"; $("ugcListLoader_" + oid).style.display = "block"; } constructorFn.prototype.hideLoader = function () { //hide loader $("ugcListLoader_" + oid).style.visibility = "hidden"; $("ugcListLoader_" + oid).style.display = "none"; } return new constructorFn(); }