Class: SponsoredProjectEffortsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sponsored_project_efforts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#editObject


19
20
21
22
23
# File 'app/controllers/sponsored_project_efforts_controller.rb', line 19

def edit
  if authorized_or_redirect
    setup_edit
  end
end

#indexObject


7
8
9
10
11
12
13
# File 'app/controllers/sponsored_project_efforts_controller.rb', line 7

def index
  authorize! :read, SponsoredProjectEffort
  @month = params[:date][:month].to_i unless params[:date].nil?
  @month = @month ||= 1.month.ago.month
  @year = params[:year] ||= 1.month.ago.year
  @efforts = SponsoredProjectEffort.for_all_users_for_a_given_month(@month, @year)
end

#showObject


15
16
17
# File 'app/controllers/sponsored_project_efforts_controller.rb', line 15

def show
  redirect_to(edit_sponsored_project_effort_path)
end

#updateObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/sponsored_project_efforts_controller.rb', line 25

def update
  if authorized_or_redirect
    effort_id_values = params[:effort_id_values]

    @failed = false
    @changed_allocation = false
    effort_id_values.each do |key, value|
      effort = SponsoredProjectEffort.find(key)
      #      @changed_allocation = true if effort.actual_allocation != value
      effort.actual_allocation = value
      @changed_allocation = true if effort.actual_allocation_changed?
      effort.confirmed = true
      unless effort.save
        @failed = true
      end
    end
    if @changed_allocation
      SponsoredProjectEffort.emails_business_manager(effort_id_values.keys[0])
    end

    if @failed
      flash.now[:error] = 'Your allocations did not save.'
    else
      flash.now[:notice] = 'Your allocations are confirmed.'
    end

    setup_edit
    render 'edit'
  end
end