From b6783206384248621877cf23f61b98a0aed55f6e Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 21 Mar 2012 16:25:30 +0600 Subject: [PATCH] [refs #265] add ajax to older messages --- app/assets/javascripts/application.js | 14 ++++++++++++++ app/controllers/activity_feeds_controller.rb | 6 +++++- app/views/activity_feeds/_list.html.haml | 6 ++++++ app/views/activity_feeds/index.html.haml | 7 +------ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 app/views/activity_feeds/_list.html.haml diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6a5cf1762..d8dd4c4fe 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -35,4 +35,18 @@ $(document).ready(function() { $('div.information > div.profile > a').live('click', function(e) { e.preventDefault(); }); + + $('.more_activities').live('click', function(){ + var button = $(this); + $.ajax({ + type: 'GET', + url: button.attr("href"), + success: function(data){ + button.fadeOut('slow').after(data); + button.remove(); + } + }); + return false; + }); + }); diff --git a/app/controllers/activity_feeds_controller.rb b/app/controllers/activity_feeds_controller.rb index ff03a16e4..ccdf38127 100644 --- a/app/controllers/activity_feeds_controller.rb +++ b/app/controllers/activity_feeds_controller.rb @@ -5,7 +5,11 @@ class ActivityFeedsController < ApplicationController @filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all @activity_feeds = current_user.activity_feeds @activity_feeds = @activity_feeds.where(:kind => "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all - @activity_feeds = @activity_feeds.paginate :page => params[:page] + if request.format == '*/*' + render '_list', :layout => false + else + render 'index' + end end end diff --git a/app/views/activity_feeds/_list.html.haml b/app/views/activity_feeds/_list.html.haml new file mode 100644 index 000000000..165686397 --- /dev/null +++ b/app/views/activity_feeds/_list.html.haml @@ -0,0 +1,6 @@ +- @activity_feeds.each do |activity_feed| + .activity + = render_activity_feed(activity_feed) +- if @activity_feeds.next_page + %a{:href => activity_feeds_path({:filter => @filter, :page => @activity_feeds.next_page}), :class => 'more_activities'} + .messages.messages-last=t('layout.activity_feed.load_messages') \ No newline at end of file diff --git a/app/views/activity_feeds/index.html.haml b/app/views/activity_feeds/index.html.haml index 9fdf04cca..022a2c985 100644 --- a/app/views/activity_feeds/index.html.haml +++ b/app/views/activity_feeds/index.html.haml @@ -1,10 +1,5 @@ %h3.fix= t("layout.activity_feed.header") -- @activity_feeds.each do |activity_feed| - .activity - = render_activity_feed(activity_feed) -- if @activity_feeds.next_page - %a{:href => activity_feeds_path({:filter => @filter, :page => @activity_feeds.next_page})} - .messages.messages-last=t('layout.activity_feed.load_messages') +=render 'list' - content_for :sidebar, render('sidebar') - content_for :feed_tabs, render('feed_tabs')