diff --git a/controllers/public/proposals_discussion_plugin_public_controller.rb b/controllers/public/proposals_discussion_plugin_public_controller.rb new file mode 100644 index 0000000..8e64ae1 --- /dev/null +++ b/controllers/public/proposals_discussion_plugin_public_controller.rb @@ -0,0 +1,35 @@ +class ProposalsDiscussionPluginPublicController < ApplicationController + + needs_profile + + before_filter :set_rand_cookie + + def load_proposals + holder = profile.articles.find(params[:holder_id]) + page = (params[:page] || 1).to_i + + set_seed + proposals = holder.proposals.includes(:parent, :profile).reorder('random()') + proposals = proposals.page(page).per_page(5) + + unless proposals.empty? + render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => proposals, :holder => holder, :next_page => page+1} + else + render :text => '' + end + end + + private + + def set_seed + #XXX postgresql specific + seed_val = profile.connection.quote(cookies[:_noosfero_proposals_discussion_rand_seed]) + profile.connection.execute("select setseed(#{seed_val})") + end + + def set_rand_cookie + return if cookies[:_noosfero_proposals_discussion_rand_seed].present? + cookies[:_noosfero_proposals_discussion_rand_seed] = {value: rand, expires: Time.now + 900} + end + +end diff --git a/public/jquery.jscroll.min.js b/public/jquery.jscroll.min.js new file mode 100644 index 0000000..f39469a --- /dev/null +++ b/public/jquery.jscroll.min.js @@ -0,0 +1,15 @@ +/*! + * jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging - v2.2.4 + * http://jscroll.com/ + * + * Copyright 2011-2013, Philip Klauzinski + * http://klauzinski.com/ + * Dual licensed under the MIT and GPL Version 2 licenses. + * http://jscroll.com/#license + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl-2.0.html + * + * @author Philip Klauzinski + * @requires jQuery v1.4.3+ + */ +(function(b){b.jscroll={defaults:{debug:false,autoTrigger:true,autoTriggerUntil:false,loadingHtml:"Loading...",padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:false}};var a=function(e,g){var o=e.data("jscroll"),n=(typeof g==="function")?{callback:g}:g,p=b.extend({},b.jscroll.defaults,n,o||{}),c=(e.css("overflow-y")==="visible"),l=e.find(p.nextSelector).first(),v=b(window),h=b("body"),q=c?v:e,m=b.trim(l.attr("href")+" "+p.contentSelector);e.data("jscroll",b.extend({},o,{initialized:true,waiting:false,nextHref:m}));r();k();t();function k(){var x=b(p.loadingHtml).filter("img").attr("src");if(x){var w=new Image();w.src=x}}function r(){if(!e.find(".jscroll-inner").length){e.contents().wrapAll('
')}}function d(w){if(p.pagingSelector){var x=w.closest(p.pagingSelector).hide()}else{var x=w.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide();if(!x.length){w.wrap('').parent().hide()}}}function j(){return q.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()}function i(){r();var D=e.find("div.jscroll-inner").first(),B=e.data("jscroll"),C=parseInt(e.css("borderTopWidth")),y=isNaN(C)?0:C,x=parseInt(e.css("paddingTop"))+y,A=c?q.scrollTop():e.offset().top,z=D.length?D.offset().top:0,w=Math.ceil(A-z+q.height()+x);if(!B.waiting&&w+p.padding>=D.outerHeight()){f("info","jScroll:",D.outerHeight()-w,"from bottom. Loading next request...");return u()}}function s(w){w=w||e.data("jscroll");if(!w||!w.nextHref){f("warn","jScroll: nextSelector not found - destroying");j();return false}else{t();return true}}function t(){var w=e.find(p.nextSelector).first();if(p.autoTrigger&&(p.autoTriggerUntil===false||p.autoTriggerUntil>0)){d(w);if(h.height()<=v.height()){i()}q.unbind(".jscroll").bind("scroll.jscroll",function(){return i()});if(p.autoTriggerUntil>0){p.autoTriggerUntil--}}else{q.unbind(".jscroll");w.bind("click.jscroll",function(){d(w);u();return false})}}function u(){var x=e.find("div.jscroll-inner").first(),w=e.data("jscroll");w.waiting=true;x.append('').children(".jscroll-added").last().html('