Sha256: fe8370087ab311992837dc39a0e543dea0627fc9aa024b32183e81306a2f6942

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

class EstimatesController < ApplicationController
  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])
      @last_active = @task.lower_item.nil?
      @last_active_in_backlog = @last_active || @task.lower_item.backlog != @task.backlog
      finished_count = Task.count(:conditions => ['period_id = ? AND finished_at IS NOT NULL', @task.period_id])
      @first_finished = finished_count == 0
    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_ajax', :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

1 entries across 1 versions & 1 rubygems

Version Path
backlog-0.12.0 app/controllers/estimates_controller.rb