@@ -191,44 +191,21 class IssuesController < ApplicationController | |||||
191 | end |
|
191 | end | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | #-- |
|
|||
195 | # Start converting to the Rails REST controllers |
|
|||
196 | #++ |
|
|||
197 | def update |
|
194 | def update | |
198 | update_issue_from_params |
|
195 | update_issue_from_params | |
199 |
|
196 | |||
200 | if request.get? |
|
197 | if issue_update | |
201 | # nop |
|
198 | respond_to do |format| | |
202 | else |
|
199 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | |
203 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
200 | format.xml { head :ok } | |
204 | @time_entry.attributes = params[:time_entry] |
|
|||
205 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? |
|
|||
206 | attachments = attach_files(@issue, params[:attachments]) |
|
|||
207 | attachments.each {|a| @journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
|||
208 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal}) |
|
|||
209 | if @issue.save |
|
|||
210 | # Log spend time |
|
|||
211 | if User.current.allowed_to?(:log_time, @project) |
|
|||
212 | @time_entry.save |
|
|||
213 | end |
|
|||
214 | if !@journal.new_record? |
|
|||
215 | # Only send notification if something was actually changed |
|
|||
216 | flash[:notice] = l(:notice_successful_update) |
|
|||
217 | end |
|
|||
218 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal}) |
|
|||
219 | respond_to do |format| |
|
|||
220 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
|||
221 | format.xml { head :ok } |
|
|||
222 | end |
|
|||
223 | return |
|
|||
224 | end |
|
|||
225 | end |
|
201 | end | |
226 | # failure |
|
202 | else | |
227 | respond_to do |format| |
|
203 | respond_to do |format| | |
228 | format.html { render :action => 'edit' } |
|
204 | format.html { render :action => 'edit' } | |
229 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } |
|
205 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } | |
230 | end |
|
206 | end | |
231 | end |
|
207 | end | |
|
208 | ||||
232 | rescue ActiveRecord::StaleObjectError |
|
209 | rescue ActiveRecord::StaleObjectError | |
233 | # Optimistic locking exception |
|
210 | # Optimistic locking exception | |
234 | flash.now[:error] = l(:notice_locking_conflict) |
|
211 | flash.now[:error] = l(:notice_locking_conflict) | |
@@ -579,4 +556,32 private | |||||
579 | end |
|
556 | end | |
580 |
|
557 | |||
581 | end |
|
558 | end | |
|
559 | ||||
|
560 | # TODO: Temporary utility method for #update. Should be split off | |||
|
561 | # and moved to the Issue model (accepts_nested_attributes_for maybe?) | |||
|
562 | # TODO: move attach_files to the model so this can be moved to the | |||
|
563 | # model also | |||
|
564 | def issue_update | |||
|
565 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) | |||
|
566 | @time_entry.attributes = params[:time_entry] | |||
|
567 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? | |||
|
568 | attachments = attach_files(@issue, params[:attachments]) | |||
|
569 | attachments.each {|a| @journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |||
|
570 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal}) | |||
|
571 | if @issue.save | |||
|
572 | # Log spend time | |||
|
573 | if User.current.allowed_to?(:log_time, @project) | |||
|
574 | @time_entry.save | |||
|
575 | end | |||
|
576 | if !@journal.new_record? | |||
|
577 | # Only send notification if something was actually changed | |||
|
578 | flash[:notice] = l(:notice_successful_update) | |||
|
579 | end | |||
|
580 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @journal}) | |||
|
581 | return true | |||
|
582 | end | |||
|
583 | end | |||
|
584 | # failure, returns false | |||
|
585 | ||||
|
586 | end | |||
582 | end |
|
587 | end |
General Comments 0
You need to be logged in to leave comments.
Login now