To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / watchers_controller.rb @ 912:5e80956cc792
History | View | Annotate | Download (2.93 KB)
| 1 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 3 | 0:513646585e45 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 15 | # along with this program; if not, write to the Free Software
|
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 17 | |||
| 18 | class WatchersController < ApplicationController |
||
| 19 | before_filter :find_project
|
||
| 20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] |
||
| 21 | before_filter :authorize, :only => [:new, :destroy] |
||
| 22 | 909:cbb26bc654de | Chris | |
| 23 | 0:513646585e45 | Chris | verify :method => :post, |
| 24 | :only => [ :watch, :unwatch ], |
||
| 25 | :render => { :nothing => true, :status => :method_not_allowed } |
||
| 26 | 909:cbb26bc654de | Chris | |
| 27 | 0:513646585e45 | Chris | def watch |
| 28 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) |
||
| 29 | render_403 |
||
| 30 | else
|
||
| 31 | set_watcher(User.current, true) |
||
| 32 | end
|
||
| 33 | end
|
||
| 34 | 909:cbb26bc654de | Chris | |
| 35 | 0:513646585e45 | Chris | def unwatch |
| 36 | set_watcher(User.current, false) |
||
| 37 | end
|
||
| 38 | 909:cbb26bc654de | Chris | |
| 39 | 0:513646585e45 | Chris | def new |
| 40 | @watcher = Watcher.new(params[:watcher]) |
||
| 41 | @watcher.watchable = @watched |
||
| 42 | @watcher.save if request.post? |
||
| 43 | respond_to do |format|
|
||
| 44 | format.html { redirect_to :back }
|
||
| 45 | format.js do
|
||
| 46 | render :update do |page| |
||
| 47 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
||
| 48 | end
|
||
| 49 | end
|
||
| 50 | end
|
||
| 51 | rescue ::ActionController::RedirectBackError |
||
| 52 | render :text => 'Watcher added.', :layout => true |
||
| 53 | end
|
||
| 54 | 909:cbb26bc654de | Chris | |
| 55 | 0:513646585e45 | Chris | def destroy |
| 56 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? |
||
| 57 | respond_to do |format|
|
||
| 58 | format.html { redirect_to :back }
|
||
| 59 | format.js do
|
||
| 60 | render :update do |page| |
||
| 61 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
||
| 62 | end
|
||
| 63 | end
|
||
| 64 | end
|
||
| 65 | end
|
||
| 66 | 909:cbb26bc654de | Chris | |
| 67 | 0:513646585e45 | Chris | private |
| 68 | def find_project |
||
| 69 | klass = Object.const_get(params[:object_type].camelcase) |
||
| 70 | return false unless klass.respond_to?('watched_by') |
||
| 71 | @watched = klass.find(params[:object_id]) |
||
| 72 | @project = @watched.project |
||
| 73 | rescue
|
||
| 74 | render_404 |
||
| 75 | end
|
||
| 76 | 909:cbb26bc654de | Chris | |
| 77 | 0:513646585e45 | Chris | def set_watcher(user, watching) |
| 78 | @watched.set_watcher(user, watching)
|
||
| 79 | respond_to do |format|
|
||
| 80 | format.html { redirect_to :back }
|
||
| 81 | format.js do
|
||
| 82 | render(:update) do |page| |
||
| 83 | 441:cbce1fd3b1b7 | Chris | c = watcher_css(@watched)
|
| 84 | page.select(".#{c}").each do |item| |
||
| 85 | page.replace_html item, watcher_link(@watched, user)
|
||
| 86 | 0:513646585e45 | Chris | end
|
| 87 | end
|
||
| 88 | end
|
||
| 89 | end
|
||
| 90 | rescue ::ActionController::RedirectBackError |
||
| 91 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
||
| 92 | end
|
||
| 93 | end |