##// END OF EJS Templates
Set default project version after selecting a different project on the new issue form (#1828)....
Jean-Philippe Lang -
r14406:fb8e348254a2
parent child
Show More
@@ -431,6 +431,11 class IssuesController < ApplicationController
431 431 if action_name == 'new' && params[:was_default_status] == attrs[:status_id]
432 432 attrs.delete(:status_id)
433 433 end
434 if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id'
435 # Discard submitted version when changing the project on the issue form
436 # so we can use the default version for the new project
437 attrs.delete(:fixed_version_id)
438 end
434 439 @issue.safe_attributes = attrs
435 440
436 441 if @issue.project
@@ -4,7 +4,7
4 4 <div class="splitcontentleft">
5 5 <% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>
6 6 <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true},
7 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
7 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
8 8 <%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %>
9 9 <% else %>
10 10 <p><label><%= l(:field_status) %></label> <%= @issue.status %></p>
@@ -1,5 +1,6
1 1 <%= labelled_fields_for :issue, @issue do |f| %>
2 2 <%= call_hook(:view_issues_form_details_top, { :issue => @issue, :form => f }) %>
3 <%= hidden_field_tag 'form_update_triggered_by', '' %>
3 4
4 5 <% if @issue.safe_attribute? 'is_private' %>
5 6 <p id="issue_is_private_wrap">
@@ -9,12 +10,12
9 10
10 11 <% if @issue.safe_attribute?('project_id') && (!@issue.new_record? || @project.nil? || @issue.copy?) %>
11 12 <p><%= f.select :project_id, project_tree_options_for_select(@issue.allowed_target_projects, :selected => @issue.project), {:required => true},
12 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
13 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
13 14 <% end %>
14 15
15 16 <% if @issue.safe_attribute? 'tracker_id' %>
16 17 <p><%= f.select :tracker_id, @issue.project.trackers.collect {|t| [t.name, t.id]}, {:required => true},
17 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
18 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
18 19 <% end %>
19 20
20 21 <% if @issue.safe_attribute? 'subject' %>
@@ -473,10 +473,13 function randomKey(size) {
473 473 return key;
474 474 }
475 475
476 function updateIssueFrom(url) {
476 function updateIssueFrom(url, el) {
477 477 $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
478 478 $(this).data('valuebeforeupdate', $(this).val());
479 479 });
480 if (el) {
481 $("#form_update_triggered_by").val($(el).attr('id'));
482 }
480 483 return $.ajax({
481 484 url: url,
482 485 type: 'post',
@@ -1980,6 +1980,22 class IssuesControllerTest < ActionController::TestCase
1980 1980 assert_equal 2, assigns(:issue).status_id
1981 1981 end
1982 1982
1983 def test_update_form_for_new_issue_should_ignore_version_when_changing_project
1984 version = Version.generate!(:project_id => 1)
1985 Project.find(1).update_attribute :default_version_id, version.id
1986 @request.session[:user_id] = 2
1987
1988 xhr :post, :new, :issue => {:project_id => 1,
1989 :fixed_version_id => ''},
1990 :form_update_triggered_by => 'issue_project_id'
1991 assert_response :success
1992 assert_template 'new'
1993
1994 issue = assigns(:issue)
1995 assert_equal 1, issue.project_id
1996 assert_equal version, issue.fixed_version
1997 end
1998
1983 1999 def test_post_create
1984 2000 @request.session[:user_id] = 2
1985 2001 assert_difference 'Issue.count' do
General Comments 0
You need to be logged in to leave comments. Login now