@@ -199,13 +199,25 class IssuesController < ApplicationController | |||||
199 | def update |
|
199 | def update | |
200 | update_issue_from_params |
|
200 | update_issue_from_params | |
201 |
|
201 | |||
202 | if issue_update |
|
202 | if @issue.save_issue_with_child_records(params, @time_entry) | |
|
203 | render_attachment_warning_if_needed(@issue) | |||
|
204 | if !@issue.current_journal.new_record? | |||
|
205 | # Only send notification if something was actually changed | |||
|
206 | flash[:notice] = l(:notice_successful_update) | |||
|
207 | end | |||
|
208 | ||||
203 | respond_to do |format| |
|
209 | respond_to do |format| | |
204 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } |
|
210 | format.html { redirect_back_or_default({:action => 'show', :id => @issue}) } | |
205 | format.xml { head :ok } |
|
211 | format.xml { head :ok } | |
206 | end |
|
212 | end | |
207 | else |
|
213 | else | |
|
214 | render_attachment_warning_if_needed(@issue) | |||
|
215 | if !@issue.current_journal.new_record? | |||
|
216 | # Only send notification if something was actually changed | |||
|
217 | flash[:notice] = l(:notice_successful_update) | |||
|
218 | end | |||
208 | @journal = @issue.current_journal |
|
219 | @journal = @issue.current_journal | |
|
220 | ||||
209 | respond_to do |format| |
|
221 | respond_to do |format| | |
210 | format.html { render :action => 'edit' } |
|
222 | format.html { render :action => 'edit' } | |
211 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } |
|
223 | format.xml { render :xml => @issue.errors, :status => :unprocessable_entity } | |
@@ -562,32 +574,4 private | |||||
562 | end |
|
574 | end | |
563 |
|
575 | |||
564 | end |
|
576 | end | |
565 |
|
||||
566 | # TODO: Temporary utility method for #update. Should be split off |
|
|||
567 | # and moved to the Issue model (accepts_nested_attributes_for maybe?) |
|
|||
568 | def issue_update |
|
|||
569 | if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, @project) |
|
|||
570 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
|||
571 | @time_entry.attributes = params[:time_entry] |
|
|||
572 | @issue.time_entries << @time_entry |
|
|||
573 | end |
|
|||
574 |
|
||||
575 | if @issue.valid? |
|
|||
576 | attachments = Attachment.attach_files(@issue, params[:attachments]) |
|
|||
577 | render_attachment_warning_if_needed(@issue) |
|
|||
578 |
|
||||
579 | attachments[:files].each {|a| @issue.current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
|||
580 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @issue.current_journal}) |
|
|||
581 | if @issue.save |
|
|||
582 | if !@issue.current_journal.new_record? |
|
|||
583 | # Only send notification if something was actually changed |
|
|||
584 | flash[:notice] = l(:notice_successful_update) |
|
|||
585 | end |
|
|||
586 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => @issue.current_journal}) |
|
|||
587 | return true |
|
|||
588 | end |
|
|||
589 | end |
|
|||
590 | # failure, returns false |
|
|||
591 |
|
||||
592 | end |
|
|||
593 | end |
|
577 | end |
@@ -394,6 +394,34 class Issue < ActiveRecord::Base | |||||
394 | s |
|
394 | s | |
395 | end |
|
395 | end | |
396 |
|
396 | |||
|
397 | # Saves an issue, time_entry, attachments, and a journal from the parameters | |||
|
398 | def save_issue_with_child_records(params, existing_time_entry=nil) | |||
|
399 | if params[:time_entry] && params[:time_entry][:hours].present? && User.current.allowed_to?(:log_time, project) | |||
|
400 | @time_entry = existing_time_entry || TimeEntry.new | |||
|
401 | @time_entry.project = project | |||
|
402 | @time_entry.issue = self | |||
|
403 | @time_entry.user = User.current | |||
|
404 | @time_entry.spent_on = Date.today | |||
|
405 | @time_entry.attributes = params[:time_entry] | |||
|
406 | self.time_entries << @time_entry | |||
|
407 | end | |||
|
408 | ||||
|
409 | if valid? | |||
|
410 | attachments = Attachment.attach_files(self, params[:attachments]) | |||
|
411 | ||||
|
412 | attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |||
|
413 | # TODO: Rename hook | |||
|
414 | Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal}) | |||
|
415 | if save | |||
|
416 | # TODO: Rename hook | |||
|
417 | Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal}) | |||
|
418 | return true | |||
|
419 | end | |||
|
420 | end | |||
|
421 | # failure, returns false | |||
|
422 | ||||
|
423 | end | |||
|
424 | ||||
397 | # Unassigns issues from +version+ if it's no longer shared with issue's project |
|
425 | # Unassigns issues from +version+ if it's no longer shared with issue's project | |
398 | def self.update_versions_from_sharing_change(version) |
|
426 | def self.update_versions_from_sharing_change(version) | |
399 | # Update issues assigned to the version |
|
427 | # Update issues assigned to the version |
General Comments 0
You need to be logged in to leave comments.
Login now