From: Jean-Philippe Lang Date: Sun, 1 Nov 2015 08:38:21 +0000 (+0000) Subject: Set default project version after selecting a different project on the new issue... X-Git-Tag: 3.2.0~86 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fb8e348254a24cc3facb238789f555aa70d9857b;p=redmine.git 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 --- 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 @@
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>

<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true}, - :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %>

+ :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %>

<%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %> <% else %>

<%= @issue.status %>

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' %>

@@ -9,12 +10,12 @@ <% if @issue.safe_attribute?('project_id') && (!@issue.new_record? || @project.nil? || @issue.copy?) %>

<%= 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)}')" %>

+ :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %>

<% end %> <% if @issue.safe_attribute? 'tracker_id' %>

<%= 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)}')" %>

+ :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %>

<% 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