summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-11-01 08:38:21 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-11-01 08:38:21 +0000
commitfb8e348254a24cc3facb238789f555aa70d9857b (patch)
tree9c2c03173c053763c8a4377a86de2e65ad251b73
parent3d513cae6ee96d0ce6c10b5068f91a6df10999d3 (diff)
downloadredmine-fb8e348254a24cc3facb238789f555aa70d9857b.tar.gz
redmine-fb8e348254a24cc3facb238789f555aa70d9857b.zip
Set default project version after selecting a different project on the new issue form (#1828).
git-svn-id: http://svn.redmine.org/redmine/trunk@14788 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/issues_controller.rb5
-rw-r--r--app/views/issues/_attributes.html.erb2
-rw-r--r--app/views/issues/_form.html.erb5
-rw-r--r--public/javascripts/application.js5
-rw-r--r--test/functional/issues_controller_test.rb16
5 files changed, 29 insertions, 4 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 2abe13ae8..f2dd1acd2 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -431,6 +431,11 @@ class IssuesController < ApplicationController
if action_name == 'new' && params[:was_default_status] == attrs[:status_id]
attrs.delete(:status_id)
end
+ if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id'
+ # Discard submitted version when changing the project on the issue form
+ # so we can use the default version for the new project
+ attrs.delete(:fixed_version_id)
+ end
@issue.safe_attributes = attrs
if @issue.project
diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb
index c5c4e8d1b..4ec2f8159 100644
--- a/app/views/issues/_attributes.html.erb
+++ b/app/views/issues/_attributes.html.erb
@@ -4,7 +4,7 @@
<div class="splitcontentleft">
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true},
- :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
+ :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
<%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %>
<% else %>
<p><label><%= l(:field_status) %></label> <%= @issue.status %></p>
diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb
index 9449938c1..5c0ced141 100644
--- a/app/views/issues/_form.html.erb
+++ b/app/views/issues/_form.html.erb
@@ -1,5 +1,6 @@
<%= labelled_fields_for :issue, @issue do |f| %>
<%= call_hook(:view_issues_form_details_top, { :issue => @issue, :form => f }) %>
+<%= hidden_field_tag 'form_update_triggered_by', '' %>
<% if @issue.safe_attribute? 'is_private' %>
<p id="issue_is_private_wrap">
@@ -9,12 +10,12 @@
<% if @issue.safe_attribute?('project_id') && (!@issue.new_record? || @project.nil? || @issue.copy?) %>
<p><%= f.select :project_id, project_tree_options_for_select(@issue.allowed_target_projects, :selected => @issue.project), {:required => true},
- :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
+ :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
<% end %>
<% if @issue.safe_attribute? 'tracker_id' %>
<p><%= f.select :tracker_id, @issue.project.trackers.collect {|t| [t.name, t.id]}, {:required => true},
- :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
+ :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
<% end %>
<% if @issue.safe_attribute? 'subject' %>
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 610cb60e7..b39b0fead 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -473,10 +473,13 @@ function randomKey(size) {
return key;
}
-function updateIssueFrom(url) {
+function updateIssueFrom(url, el) {
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
$(this).data('valuebeforeupdate', $(this).val());
});
+ if (el) {
+ $("#form_update_triggered_by").val($(el).attr('id'));
+ }
return $.ajax({
url: url,
type: 'post',
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index b1c2b26e5..32776d419 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -1980,6 +1980,22 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 2, assigns(:issue).status_id
end
+ def test_update_form_for_new_issue_should_ignore_version_when_changing_project
+ version = Version.generate!(:project_id => 1)
+ Project.find(1).update_attribute :default_version_id, version.id
+ @request.session[:user_id] = 2
+
+ xhr :post, :new, :issue => {:project_id => 1,
+ :fixed_version_id => ''},
+ :form_update_triggered_by => 'issue_project_id'
+ assert_response :success
+ assert_template 'new'
+
+ issue = assigns(:issue)
+ assert_equal 1, issue.project_id
+ assert_equal version, issue.fixed_version
+ end
+
def test_post_create
@request.session[:user_id] = 2
assert_difference 'Issue.count' do