diff --git a/app/controllers/forum/forum_topics_controller.rb b/app/controllers/forum/forum_topics_controller.rb index b959f18..8429d86 100644 --- a/app/controllers/forum/forum_topics_controller.rb +++ b/app/controllers/forum/forum_topics_controller.rb @@ -4,6 +4,24 @@ class Forum::ForumTopicsController < ApplicationController before_filter :auth_fuser + def follow + @topic = ForumTopic.find(params[:id]) + + @follow_topic = FollowedTopic.where(:forum_user_id => current_fuser.id, :forum_topic_id => @topic.id).first + if @follow_topic + @follow_topic.destroy + else + FollowedTopic.create(:forum_user_id => current_fuser.id, :forum_topic_id => @topic.id) + + end + respond_to do |format| + format.html {redirect_to :back} + format.js {render :layout => false} + end + + + end + def index @forum_topics = ForumTopic.all end diff --git a/app/views/forum/forum_topics/_follow.haml b/app/views/forum/forum_topics/_follow.haml new file mode 100644 index 0000000..f69cd8e --- /dev/null +++ b/app/views/forum/forum_topics/_follow.haml @@ -0,0 +1,5 @@ +%span#topic_follow{:id => forum_topic.id} + -if FollowedTopic.where(:forum_user_id => current_fuser.id, :forum_topic_id => forum_topic.id).count > 0 + =link_to i(:"star", :icon => false), follow_forum_forum_topic_path(forum_topic), :remote => true, :style => "color:#ffcc17;" + -else + =link_to i(:"star-o", :icon => false), follow_forum_forum_topic_path(forum_topic), :remote => true, :style => "color:#dddddd;" \ No newline at end of file diff --git a/app/views/forum/forum_topics/_forum_topic.haml b/app/views/forum/forum_topics/_forum_topic.haml index 4286bb2..bb5ae82 100644 --- a/app/views/forum/forum_topics/_forum_topic.haml +++ b/app/views/forum/forum_topics/_forum_topic.haml @@ -1,4 +1,4 @@ -%tr.topic +%tr.topic#topic{:id => forum_topic.id} %td=link_to forum_topic.title, [:forum, forum_topic] %td{:style => "width:160px;"}=forum_topic.category.title if forum_topic.category %td{:style => "width:100px;"}=forum_topic.forum_messages.count - 1 @@ -15,6 +15,8 @@ %br il y a =distance_of_time_in_words Time.now, forum_topic.forum_messages.order("created_at ASC").last.created_at + %td{:style => "width:20px;"} + =render :partial => "forum/forum_topics/follow", :locals => {:forum_topic => forum_topic} -if moderator? %td diff --git a/app/views/forum/forum_topics/follow.js.erb b/app/views/forum/forum_topics/follow.js.erb new file mode 100644 index 0000000..4f8da02 --- /dev/null +++ b/app/views/forum/forum_topics/follow.js.erb @@ -0,0 +1,3 @@ + +$("#topic_follow_<%= @topic.id %>").replaceWith("<%= escape_javascript(render(:partial => "forum/forum_topics/follow", :locals => {:forum_topic => @topic})) %>"); + diff --git a/app/views/forum/forum_topics/index.haml b/app/views/forum/forum_topics/index.haml index c6fe737..cc7036c 100644 --- a/app/views/forum/forum_topics/index.haml +++ b/app/views/forum/forum_topics/index.haml @@ -8,6 +8,7 @@ %th Réponses %th Lancé %th Activité + -if moderator? %th{:style => "width:50px;"} =render @forum_topics diff --git a/app/views/forum/forum_topics/show.haml b/app/views/forum/forum_topics/show.haml index f611150..7559b1a 100644 --- a/app/views/forum/forum_topics/show.haml +++ b/app/views/forum/forum_topics/show.haml @@ -1,7 +1,9 @@ =link_to "ajouter un message", new_forum_forum_message_path(:topic_id => @topic.id), :class => "btn btn-primary", :style => "margin:1em 0em;float:right" -%h1= @topic.title +%h1 + =render :partial => "forum/forum_topics/follow", :locals => {:forum_topic => @topic} + = @topic.title %br %br =render @topic.forum_messages.order("created_at ASC") diff --git a/config/routes.rb b/config/routes.rb index 5ed5932..c5511ea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,7 +69,11 @@ Survey::Application.routes.draw do namespace :forum do root :to => "forum_topics#index", :id => 1 - resources :forum_topics + resources :forum_topics do + member do + get :follow + end + end resources :forum_messages resources :forums resources :forum_categories