Mercurial > hg > soundsoftware-site
comparison app/controllers/issue_relations_controller.rb @ 1338:25603efa57b5
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:14 +0100 |
parents | 433d4f72a19b |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
1209:1b1138f6f55e | 1338:25603efa57b5 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
37 format.html { render :nothing => true } | 37 format.html { render :nothing => true } |
38 format.api | 38 format.api |
39 end | 39 end |
40 end | 40 end |
41 | 41 |
42 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |
43 def create | 42 def create |
44 @relation = IssueRelation.new(params[:relation]) | 43 @relation = IssueRelation.new(params[:relation]) |
45 @relation.issue_from = @issue | 44 @relation.issue_from = @issue |
46 if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/) | 45 if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/) |
47 @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) | 46 @relation.issue_to = Issue.visible.find_by_id(m[1].to_i) |
48 end | 47 end |
49 saved = @relation.save | 48 saved = @relation.save |
50 | 49 |
51 respond_to do |format| | 50 respond_to do |format| |
52 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | 51 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } |
53 format.js do | 52 format.js { |
54 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | 53 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
55 render :update do |page| | 54 } |
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 { | 55 format.api { |
64 if saved | 56 if saved |
65 render :action => 'show', :status => :created, :location => relation_url(@relation) | 57 render :action => 'show', :status => :created, :location => relation_url(@relation) |
66 else | 58 else |
67 render_validation_errors(@relation) | 59 render_validation_errors(@relation) |
68 end | 60 end |
69 } | 61 } |
70 end | 62 end |
71 end | 63 end |
72 | 64 |
73 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } | |
74 def destroy | 65 def destroy |
75 raise Unauthorized unless @relation.deletable? | 66 raise Unauthorized unless @relation.deletable? |
76 @relation.destroy | 67 @relation.destroy |
77 | 68 |
78 respond_to do |format| | 69 respond_to do |format| |
79 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @issue } | 70 format.html { redirect_to issue_path } # TODO : does this really work since @issue is always nil? What is it useful to? |
80 format.js { render(:update) {|page| page.remove "relation-#{@relation.id}"} } | 71 format.js |
81 format.api { head :ok } | 72 format.api { render_api_ok } |
82 end | 73 end |
83 end | 74 end |
84 | 75 |
85 private | 76 private |
86 def find_issue | 77 def find_issue |