include MessagesHelper
helper :sort
include SortHelper
+ helper :watchers
+ include WatchersHelper
def index
@boards = @project.boards
include IfpdfHelper
helper :issue_relations
include IssueRelationsHelper
+ helper :watchers
+ include WatchersHelper
def show
@status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
before_filter :require_login, :find_project, :check_project_privacy
def add
- @issue.add_watcher(logged_in_user)
- redirect_to :controller => 'issues', :action => 'show', :id => @issue
+ user = logged_in_user
+ @watched.add_watcher(user)
+ respond_to do |format|
+ format.html { render :text => 'Watcher added.', :layout => true }
+ format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
+ end
end
def remove
- @issue.remove_watcher(logged_in_user)
- redirect_to :controller => 'issues', :action => 'show', :id => @issue
+ user = logged_in_user
+ @watched.remove_watcher(user)
+ respond_to do |format|
+ format.html { render :text => 'Watcher removed.', :layout => true }
+ format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
+ end
end
private
-
def find_project
- @issue = Issue.find(params[:issue_id])
- @project = @issue.project
+ klass = Object.const_get(params[:object_type].camelcase)
+ return false unless klass.respond_to?('watched_by')
+ @watched = klass.find(params[:object_id])
+ @project = @watched.project
+ rescue
+ render_404
end
end
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module WatchersHelper
+ def watcher_tag(object, user)
+ content_tag("span", watcher_link(object, user), :id => 'watcher')
+ end
+
+ def watcher_link(object, user)
+ return '' unless user && object.respond_to?('watched_by?')
+ watched = object.watched_by?(user)
+ url = {:controller => 'watchers',
+ :action => (watched ? 'remove' : 'add'),
+ :object_type => object.class.to_s.underscore,
+ :object_id => object.id}
+ link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
+ {:url => url},
+ :href => url_for(url),
+ :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
+
+ end
end
has_many :messages, :dependent => :delete_all, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
acts_as_list :scope => :project_id
+ acts_as_watchable
validates_presence_of :name, :description
validates_length_of :name, :maximum => 30
<div class="contextual">
<%= link_to l(:label_message_new), {:controller => 'messages', :action => 'new', :board_id => @board}, :class => "icon icon-add" %>
+<%= watcher_tag(@board, @logged_in_user) %>
</div>
<h2><%=h @board.name %></h2>
<div class="contextual">
<%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit' %>
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %>
-<% if @logged_in_user %>
- <% if @issue.watched_by?(@logged_in_user) %>
-<%= link_to l(:button_unwatch), {:controller => 'watchers', :action => 'remove', :issue_id => @issue}, :class => 'icon icon-fav' %>
- <% else %>
-<%= link_to l(:button_watch), {:controller => 'watchers', :action => 'add', :issue_id => @issue}, :class => 'icon icon-fav-off' %>
- <% end %>
-<% end %>
+<%= watcher_tag(@issue, @logged_in_user) %>
<%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %>
<%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
</div>