follow functions
This commit is contained in:
parent
2fd70c706b
commit
4dc1709436
@ -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
|
||||
|
5
app/views/forum/forum_topics/_follow.haml
Normal file
5
app/views/forum/forum_topics/_follow.haml
Normal file
@ -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;"
|
@ -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
|
||||
|
3
app/views/forum/forum_topics/follow.js.erb
Normal file
3
app/views/forum/forum_topics/follow.js.erb
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
$("#topic_follow_<%= @topic.id %>").replaceWith("<%= escape_javascript(render(:partial => "forum/forum_topics/follow", :locals => {:forum_topic => @topic})) %>");
|
||||
|
@ -8,6 +8,7 @@
|
||||
%th Réponses
|
||||
%th Lancé
|
||||
%th Activité
|
||||
|
||||
-if moderator?
|
||||
%th{:style => "width:50px;"}
|
||||
=render @forum_topics
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user