From dfd1d0c7feef44685f4c72a3126f972610021055 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 20 Aug 2010 15:22:19 +0000 Subject: [PATCH] Refactor: merge IssuesController#update_form into IssuesController#new The #update_form action was only refreshing the issue attributes form, so it's just a specialized JavaScript version of #new. This also removed old code that was extracted in other places (@issue.new_statuses_allowed_to). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4011 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 31 ++++++++++------------- app/views/issues/_form.rhtml | 2 +- test/functional/issues_controller_test.rb | 4 +-- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 83c2f2112..5f08224cc 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -21,7 +21,7 @@ class IssuesController < ApplicationController before_filter :find_issue, :only => [:show, :edit, :update] before_filter :find_issues, :only => [:bulk_edit, :move, :perform_move, :destroy] - before_filter :find_project, :only => [:new, :create, :update_form] + before_filter :find_project, :only => [:new, :create] before_filter :authorize, :except => [:index, :changes] before_filter :find_optional_project, :only => [:index, :changes] before_filter :check_for_default_issue_status, :only => [:new, :create] @@ -132,7 +132,10 @@ class IssuesController < ApplicationController # Add a new issue # The new issue will be created from an existing one if copy_from parameter is given def new - render :action => 'new', :layout => !request.xhr? + respond_to do |format| + format.html { render :action => 'new', :layout => !request.xhr? } + format.js { render :partial => 'attributes' } + end end def create @@ -258,20 +261,6 @@ class IssuesController < ApplicationController end end - def update_form - if params[:id].blank? - @issue = Issue.new - @issue.project = @project - else - @issue = @project.issues.visible.find(params[:id]) - end - @issue.attributes = params[:issue] - @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq - @priorities = IssuePriority.all - - render :partial => 'attributes' - end - private def find_issue @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) @@ -310,8 +299,14 @@ private # TODO: Refactor, lots of extra code in here def build_new_issue_from_params - @issue = Issue.new - @issue.copy_from(params[:copy_from]) if params[:copy_from] + if params[:id].blank? + @issue = Issue.new + @issue.copy_from(params[:copy_from]) if params[:copy_from] + @issue.project = @project + else + @issue = @project.issues.visible.find(params[:id]) + end + @issue.project = @project # Tracker must be set before custom field values @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml index ccb7a55a3..2bee7d36c 100644 --- a/app/views/issues/_form.rhtml +++ b/app/views/issues/_form.rhtml @@ -1,6 +1,6 @@
>

<%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>

-<%= observe_field :issue_tracker_id, :url => { :action => :update_form, :project_id => @project, :id => @issue }, +<%= observe_field :issue_tracker_id, :url => { :action => :new, :project_id => @project, :id => @issue }, :update => :attributes, :with => "Form.serialize('issue-form')" %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index d52f63834..dfdb74c42 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -365,7 +365,7 @@ class IssuesControllerTest < ActionController::TestCase def test_update_new_form @request.session[:user_id] = 2 - xhr :post, :update_form, :project_id => 1, + xhr :post, :new, :project_id => 1, :issue => {:tracker_id => 2, :subject => 'This is the test_new issue', :description => 'This is the description', @@ -617,7 +617,7 @@ class IssuesControllerTest < ActionController::TestCase def test_update_edit_form @request.session[:user_id] = 2 - xhr :post, :update_form, :project_id => 1, + xhr :post, :new, :project_id => 1, :id => 1, :issue => {:tracker_id => 2, :subject => 'This is the test_new issue',