@@ -1,101 +1,97 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class IssueRelationsController < ApplicationController |
|
19 | 19 | before_filter :find_issue, :find_project_from_association, :authorize, :only => [:index, :create] |
|
20 | 20 | before_filter :find_relation, :except => [:index, :create] |
|
21 | 21 | |
|
22 | 22 | accept_api_auth :index, :show, :create, :destroy |
|
23 | 23 | |
|
24 | 24 | def index |
|
25 | 25 | @relations = @issue.relations |
|
26 | 26 | |
|
27 | 27 | respond_to do |format| |
|
28 | 28 | format.html { render :nothing => true } |
|
29 | 29 | format.api |
|
30 | 30 | end |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def show |
|
34 | 34 | raise Unauthorized unless @relation.visible? |
|
35 | 35 | |
|
36 | 36 | respond_to do |format| |
|
37 | 37 | format.html { render :nothing => true } |
|
38 | 38 | format.api |
|
39 | 39 | end |
|
40 | rescue ActiveRecord::RecordNotFound | |
|
41 | render_404 | |
|
42 | 40 | end |
|
43 | 41 | |
|
44 | 42 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
|
45 | 43 | def create |
|
46 | 44 | @relation = IssueRelation.new(params[:relation]) |
|
47 | 45 | @relation.issue_from = @issue |
|
48 | 46 | if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) |
|
49 | 47 | @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
|
50 | 48 | end |
|
51 | 49 | saved = @relation.save |
|
52 | 50 | |
|
53 | 51 | respond_to do |format| |
|
54 | 52 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
55 | 53 | format.js do |
|
56 | 54 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
|
57 | 55 | render :update do |page| |
|
58 | 56 | page.replace_html "relations", :partial => 'issues/relations' |
|
59 | 57 | if @relation.errors.empty? |
|
60 | 58 | page << "$('relation_delay').value = ''" |
|
61 | 59 | page << "$('relation_issue_to_id').value = ''" |
|
62 | 60 | end |
|
63 | 61 | end |
|
64 | 62 | end |
|
65 | 63 | format.api { |
|
66 | 64 | if saved |
|
67 | 65 | render :action => 'show', :status => :created, :location => relation_url(@relation) |
|
68 | 66 | else |
|
69 | 67 | render_validation_errors(@relation) |
|
70 | 68 | end |
|
71 | 69 | } |
|
72 | 70 | end |
|
73 | 71 | end |
|
74 | 72 | |
|
75 | 73 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } |
|
76 | 74 | def destroy |
|
77 | 75 | raise Unauthorized unless @relation.deletable? |
|
78 | 76 | @relation.destroy |
|
79 | 77 | |
|
80 | 78 | respond_to do |format| |
|
81 | 79 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
|
82 | 80 | format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} } |
|
83 | 81 | format.api { head :ok } |
|
84 | 82 | end |
|
85 | rescue ActiveRecord::RecordNotFound | |
|
86 | render_404 | |
|
87 | 83 | end |
|
88 | 84 | |
|
89 | 85 | private |
|
90 | 86 | def find_issue |
|
91 | 87 | @issue = @object = Issue.find(params[:issue_id]) |
|
92 | 88 | rescue ActiveRecord::RecordNotFound |
|
93 | 89 | render_404 |
|
94 | 90 | end |
|
95 | 91 | |
|
96 | 92 | def find_relation |
|
97 | 93 | @relation = IssueRelation.find(params[:id]) |
|
98 | 94 | rescue ActiveRecord::RecordNotFound |
|
99 | 95 | render_404 |
|
100 | 96 | end |
|
101 | 97 | end |
General Comments 0
You need to be logged in to leave comments.
Login now