]> source.dussan.org Git - redmine.git/commitdiff
Set default project version after selecting a different project on the new issue...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 1 Nov 2015 08:38:21 +0000 (08:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 1 Nov 2015 08:38:21 +0000 (08:38 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14788 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/views/issues/_attributes.html.erb
app/views/issues/_form.html.erb
public/javascripts/application.js
test/functional/issues_controller_test.rb

index 2abe13ae8a11ea1977b195d2d3dac8b2bd45ea62..f2dd1acd218c5e191572c4ed94b24b0e6e7d244a 100644 (file)
@@ -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
index c5c4e8d1bbbc5a7a31b454cc27563fed43e71fc6..4ec2f81590c9a854320c0337f112b06890cf0a72 100644 (file)
@@ -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>
index 9449938c1fc9b0ae2180525f6667c784140739bc..5c0ced141d50305233419dc465c950eab9652ad0 100644 (file)
@@ -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">
 
 <% 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' %>
index 610cb60e75768e2c06d055aa283a660fce85cfaf..b39b0fead82448506784c72f0f37c2a7ef7da41b 100644 (file)
@@ -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',
index b1c2b26e5d615db8f4c725799a91d78338210810..32776d4198696f8156edb0f05e2296eb8f4909ba 100644 (file)
@@ -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