Class: WorkLocksController

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

Constant Summary

Constants included from Localization

Localization::LOCALIZED_STRINGS

Instance Method Summary collapse

Methods inherited from ApplicationController

in_place_edit_for, #initialize, #render_to_string

Methods included from ApplicationHelper

#back_or_link_to, #detour?, #detour_to, #display_notice, #h, #image_button_to, #image_detour_to, #image_link_to, #image_link_to_remote, #insert, #record, #resolution_image, #t, #update_task, #with_detour

Methods included from Localization

#l, load_localized_strings, #valid_language?

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/work_locks_controller.rb', line 23

def create
  @work_lock = WorkLock.new(params[:work_lock])
  if @work_lock.save
    flash[:notice] = 'WorkLock was successfully created.'
    redirect_to :action => 'list'
  else
    render :action => 'new'
  end
end

#destroyObject



47
48
49
50
# File 'app/controllers/work_locks_controller.rb', line 47

def destroy
  WorkLock.find(params[:id]).destroy
  redirect_to :action => 'list'
end

#editObject



33
34
35
# File 'app/controllers/work_locks_controller.rb', line 33

def edit
  @work_lock = WorkLock.find(params[:id])
end

#indexObject



2
3
4
5
# File 'app/controllers/work_locks_controller.rb', line 2

def index
  list
  render :action => 'list'
end

#listObject



11
12
13
# File 'app/controllers/work_locks_controller.rb', line 11

def list
  @work_locks = WorkLock.paginate :per_page => 10, :page => params[:page]
end

#lockObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/work_locks_controller.rb', line 52

def lock
  @year = (params[:year] && params[:year].to_i) || Date.today.year
  @week = (params[:week] && params[:week].to_i) || Date.today.cweek
  first_date = Date.commercial(@year, @week, 1)
  last_date = first_date + 6
  @lock = WorkLock.find(:first, :conditions => ['user_id = ? AND start_on <= ? AND end_on >= ?', current_user.id, first_date, last_date])
  raise "Already locked" if @lock
  WorkLock.create! :user_id => current_user.id, :start_on => first_date, :end_on => last_date
   = Work.works_for_week(@year, @week).flatten.compact.map {|w| w.}.uniq.map {|wa| wa.work_lock_subscribers}.flatten.uniq
  user_subscribers = current_user.work_lock_subscribers
  notify_users = ( + user_subscribers).uniq
  notify_users.each do |user|
    week_url = url_for :controller => 'works', :action => :weekly_work_sheet, :year => @year, :week => @week, :user_id => current_user.id
    spreadsheet_url = url_for :controller => 'works', :action => :timeliste, :year => @year, :week => @week, :user_id => current_user.id
    WorkLockNotify.deliver_lock(user, current_user, @week, week_url, spreadsheet_url)
  end
  back_or_redirect_to :controller => 'works', :action => :weekly_work_sheet, :year => @year, :week => @week
end

#newObject



19
20
21
# File 'app/controllers/work_locks_controller.rb', line 19

def new
  @work_lock = WorkLock.new
end

#showObject



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

def show
  @work_lock = WorkLock.find(params[:id])
end

#unlockObject



71
72
73
74
75
76
# File 'app/controllers/work_locks_controller.rb', line 71

def unlock
  get_lock_from_params
  raise "Not locked" unless @lock
  raise "Unable to destroy" unless @lock.destroy
  back_or_redirect_to :controller => 'works', :action => :weekly_work_sheet, :year => @year, :week => @week
end

#updateObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/work_locks_controller.rb', line 37

def update
  @work_lock = WorkLock.find(params[:id])
  if @work_lock.update_attributes(params[:work_lock])
    flash[:notice] = 'WorkLock was successfully updated.'
    redirect_to :action => 'show', :id => @work_lock
  else
    render :action => 'edit'
  end
end