git-svn-id: http://svn.redmine.org/redmine/trunk@14788 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/3.2.0
@@ -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 |
@@ -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> |
@@ -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' %> |
@@ -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', |
@@ -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 |