diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2010-04-22 15:43:57 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2010-04-22 15:43:57 +0000 |
commit | 2c898d8a817ee5bd1182cf111db5f8fa1e91e870 (patch) | |
tree | b34762bc3c7211232379f7b07aa392e3715e1e81 /app | |
parent | 9b595c689d06ffc1386e242177358711bdbf5c3a (diff) | |
download | redmine-2c898d8a817ee5bd1182cf111db5f8fa1e91e870.tar.gz redmine-2c898d8a817ee5bd1182cf111db5f8fa1e91e870.zip |
Refactor: Split IssuesController#new to #new and #create to match REST pattern.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3688 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/issues_controller.rb | 77 | ||||
-rw-r--r-- | app/views/issues/new.rhtml | 2 |
2 files changed, 50 insertions, 29 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 1d13afa0e..798bb5a83 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, :reply] before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] - before_filter :find_project, :only => [:new, :update_form, :preview, :auto_complete] + before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete] before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] accept_key_auth :index, :show, :changes @@ -51,6 +51,7 @@ class IssuesController < ApplicationController :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed } + verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } def index @@ -145,35 +146,55 @@ class IssuesController < ApplicationController @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) end @issue.author = User.current - - if request.get? || request.xhr? - @issue.start_date ||= Date.today - else - call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) - if @issue.save - attachments = Attachment.attach_files(@issue, params[:attachments]) - render_attachment_warning_if_needed(@issue) - flash[:notice] = l(:notice_successful_create) - call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) - respond_to do |format| - format.html { - redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, - :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : - { :action => 'show', :id => @issue }) - } - format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } - end - return - else - respond_to do |format| - format.html { } - format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } - end - end - end + @issue.start_date ||= Date.today + @priorities = IssuePriority.all + @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) + render :action => 'new', :layout => !request.xhr? + end + + def create + @issue = Issue.new + @issue.copy_from(params[:copy_from]) if params[:copy_from] + @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) + if @issue.tracker.nil? + render_error l(:error_no_tracker_in_project) + return + end + if @issue.status.nil? + render_error l(:error_no_default_issue_status) + return + end + if params[:issue].is_a?(Hash) + @issue.safe_attributes = params[:issue] + @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) + end + @issue.author = User.current + @priorities = IssuePriority.all @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) - render :layout => !request.xhr? + + call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) + if @issue.save + attachments = Attachment.attach_files(@issue, params[:attachments]) + render_attachment_warning_if_needed(@issue) + flash[:notice] = l(:notice_successful_create) + call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) + respond_to do |format| + format.html { + redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : + { :action => 'show', :id => @issue }) + } + format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } + end + return + else + respond_to do |format| + format.html { render :action => 'new' } + format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } + end + end end # Attributes that can be updated on workflow transition (without :edit permission) diff --git a/app/views/issues/new.rhtml b/app/views/issues/new.rhtml index 94f86dde9..839286bdb 100644 --- a/app/views/issues/new.rhtml +++ b/app/views/issues/new.rhtml @@ -1,6 +1,6 @@ <h2><%=l(:label_issue_new)%></h2> -<% labelled_tabular_form_for :issue, @issue, +<% labelled_tabular_form_for :issue, @issue, :url => {:controller => 'issues', :action => 'create', :project_id => @project}, :html => {:multipart => true, :id => 'issue-form'} do |f| %> <%= error_messages_for 'issue' %> <div class="box"> |