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 / issue_relations_controller.rb @ 968:6b978669cdac
History | View | Annotate | Download (3.18 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 3 |
#
|
| 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 |
#
|
| 9 |
# 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 |
#
|
| 14 |
# 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 IssueRelationsController < ApplicationController |
| 19 |
before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] |
| 20 |
before_filter :find_relation, :except => [:index, :create] |
| 21 |
|
| 22 |
accept_api_auth :index, :show, :create, :destroy |
| 23 |
|
| 24 |
def index |
| 25 |
@relations = @issue.relations |
| 26 |
|
| 27 |
respond_to do |format|
|
| 28 |
format.html { render :nothing => true }
|
| 29 |
format.api |
| 30 |
end
|
| 31 |
end
|
| 32 |
|
| 33 |
def show |
| 34 |
raise Unauthorized unless @relation.visible? |
| 35 |
|
| 36 |
respond_to do |format|
|
| 37 |
format.html { render :nothing => true }
|
| 38 |
format.api |
| 39 |
end
|
| 40 |
end
|
| 41 |
|
| 42 |
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
| 43 |
def create |
| 44 |
@relation = IssueRelation.new(params[:relation]) |
| 45 |
@relation.issue_from = @issue |
| 46 |
if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) |
| 47 |
@relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
| 48 |
end
|
| 49 |
saved = @relation.save
|
| 50 |
|
| 51 |
respond_to do |format|
|
| 52 |
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
| 53 |
format.js do
|
| 54 |
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
| 55 |
render :update do |page| |
| 56 |
page.replace_html "relations", :partial => 'issues/relations' |
| 57 |
if @relation.errors.empty? |
| 58 |
page << "$('relation_delay').value = ''"
|
| 59 |
page << "$('relation_issue_to_id').value = ''"
|
| 60 |
end
|
| 61 |
end
|
| 62 |
end
|
| 63 |
format.api {
|
| 64 |
if saved
|
| 65 |
render :action => 'show', :status => :created, :location => relation_url(@relation) |
| 66 |
else
|
| 67 |
render_validation_errors(@relation)
|
| 68 |
end
|
| 69 |
} |
| 70 |
end
|
| 71 |
end
|
| 72 |
|
| 73 |
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } |
| 74 |
def destroy |
| 75 |
raise Unauthorized unless @relation.deletable? |
| 76 |
@relation.destroy
|
| 77 |
|
| 78 |
respond_to do |format|
|
| 79 |
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue }
|
| 80 |
format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} }
|
| 81 |
format.api { head :ok }
|
| 82 |
end
|
| 83 |
end
|
| 84 |
|
| 85 |
private |
| 86 |
def find_issue |
| 87 |
@issue = @object = Issue.find(params[:issue_id]) |
| 88 |
rescue ActiveRecord::RecordNotFound |
| 89 |
render_404 |
| 90 |
end
|
| 91 |
|
| 92 |
def find_relation |
| 93 |
@relation = IssueRelation.find(params[:id]) |
| 94 |
rescue ActiveRecord::RecordNotFound |
| 95 |
render_404 |
| 96 |
end
|
| 97 |
end
|