From f0bc0b2e9374c9517533f0f7ed9def4345e0259e Mon Sep 17 00:00:00 2001 From: z9hang Date: Sat, 21 Mar 2015 10:20:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=85=B3=E6=B3=A8=E3=80=81?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=85=B3=E6=B3=A8=E3=80=81=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E3=80=81=E5=8F=96=E6=B6=88=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=BF=94=E5=9B=9Ejs=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/watchers_helper.rb | 14 ++++++++------ app/views/applied_project/_set_applied.js.erb | 11 ++++++++++- app/views/watchers/_set_watcher.js.erb | 11 ++++++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index ed92f7cab..b1ebf17f2 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -293,14 +293,15 @@ module WatchersHelper return '' unless user && user.logged? objects = Array.wrap(objects) watched = objects.any? {|object| object.watched_by?(user)} - @watch_flag = objects.first.instance_of?(Project) - text = @watch_flag ? + @watch_flag = objects.first.instance_of?(Project) + id = watcher_css(objects) + text = @watch_flag ? (watched ? l(:button_unfollow) : l(:label_button_following)) : (watched ? l(:button_unwatch) : l(:label_button_following)) url = watch_path(:object_type => objects.first.class.to_s.underscore, :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)) - method = watched ? 'delete' : 'post' - link_to text, url, :remote => true, :method => method, - :class => "project_watch_new" + method = watched ? 'delete' : 'post' + link_to text, url, :remote => true, :method => method, + :class => "project_watch_new" ,:id=>id end #申请加入项目 @@ -312,12 +313,13 @@ module WatchersHelper if applied appliedid = applied.id end + id = applied_css(project) url = appliedproject_path( :id=>appliedid, :user_id => user.id, :project_id => project.id) method = applied ? 'delete' : 'post' - link_to text, url, :remote => true, :method => method , :class => "project_watch_new" + link_to text, url, :remote => true, :method => method , :class => "project_watch_new",:id => id end end diff --git a/app/views/applied_project/_set_applied.js.erb b/app/views/applied_project/_set_applied.js.erb index 7403b963b..33d862d1c 100644 --- a/app/views/applied_project/_set_applied.js.erb +++ b/app/views/applied_project/_set_applied.js.erb @@ -1,5 +1,14 @@ <% selector = ".#{applied_css(@project)}" %> -$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript applied_link(@project, User.current) %>")}); +<% id_selector = "#{applied_css(@project)}" %> +if($("<%= selector %>").get(0) == undefined) +{ + $("#<%= id_selector %>").each(function(){$(this).replaceWith("<%= escape_javascript join_in_project_link(@project, User.current) %>")}); +} +else +{ + $("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript applied_link(@project, User.current) %>")}); +} + if (window.Messenger) { Messenger.options = { extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right', diff --git a/app/views/watchers/_set_watcher.js.erb b/app/views/watchers/_set_watcher.js.erb index e5cdc4f3e..92fcbd489 100644 --- a/app/views/watchers/_set_watcher.js.erb +++ b/app/views/watchers/_set_watcher.js.erb @@ -1,2 +1,11 @@ <% selector = ".#{watcher_css(watched)}" %> -$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")}); +<% id_selector = "#{watcher_css(watched)}" %> +if($("<%= selector %>").get(0) == undefined) +{ + $("#<%= id_selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link_for_project(watched, user) %>")}); +} +else +{ + $("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")}); +} +