Sha256: 551e151f1ccd8a003a0bf263bef03e8703c866204d641ee0781ba385b99eb185

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

class EstimatesController < ApplicationController
  helper :tasks
  
  verify :method => :post, :redirect_to => ''
  
  def create
    @success, @message = do_create

    unless @success
      @task.errors.add :estimate, @message
      render :file => "public/500.html", :layout => true, :status => 500
      return
    end

    flash[:notice] = @message
    redirect_to :controller => 'periods', :action => :show, :id => @task.root_task.period, :task_id => @task.id
  end
  
  def create_ajax
    if @task = Task.find_by_id(params[:id])
      setup_remove
    end
    @success, @message = do_create
    # Only necessary since we have an unecessary complex update of estimates
    @task.reload
    if @task.finished?
      render :template => '/tasks/finish', :layout => false
    end
  end
  
  private
  
  def do_create
    if params[:id]
      @task = Task.find(params[:id])
      if params[:estimate] && params[:estimate][:todo]
        begin
          Float(params[:estimate][:todo])
          @task.estimate(params[:estimate][:todo])
          @period = @task.period
          return true, 'Estimate updated'
          rescue ArgumentError => e
          return false, "Estimate was not numeric"
        end
      else
        return false, "Estimate is missing."
      end
    else
      @estimate = Estimate.new
      return false, 'Task id is missing.'
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
backlog-0.12.3 app/controllers/estimates_controller.rb
backlog-0.12.4 app/controllers/estimates_controller.rb
backlog-0.13.0 app/controllers/estimates_controller.rb