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) %>")}); +} +