Class: WorkLocksController
Constant Summary
Localization::LOCALIZED_STRINGS
Instance Method Summary
collapse
in_place_edit_for, #initialize
#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
#l, load_localized_strings, #valid_language?
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
33
34
35
|
# File 'app/controllers/work_locks_controller.rb', line 33
def edit
@work_lock = WorkLock.find(params[:id])
end
|
#index ⇒ Object
2
3
4
5
|
# File 'app/controllers/work_locks_controller.rb', line 2
def index
list
render :action => 'list'
end
|
#list ⇒ Object
11
12
13
|
# File 'app/controllers/work_locks_controller.rb', line 11
def list
@work_lock_pages, @work_locks = paginate :work_locks, :per_page => 10
end
|
#lock ⇒ Object
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_account_subscribers = Work.works_for_week(@year, @week).flatten.compact.map {|w| w.work_account}.uniq.map {|wa| wa.work_lock_subscribers}.flatten.uniq
user_subscribers = current_user.work_lock_subscribers
notify_users = (work_account_subscribers + user_subscribers).uniq
notify_users.each do |user|
week_url = url_for :controller => 'works', :action => :weekly_work_sheet_by_work_account, :year => @year, :week => @week
spreadsheet_url = url_for :controller => 'works', :action => :timeliste, :year => @year, :week => @week
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
|
#new ⇒ Object
19
20
21
|
# File 'app/controllers/work_locks_controller.rb', line 19
def new
@work_lock = WorkLock.new
end
|
#show ⇒ Object
15
16
17
|
# File 'app/controllers/work_locks_controller.rb', line 15
def show
@work_lock = WorkLock.find(params[:id])
end
|
#unlock ⇒ Object
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
|
#update ⇒ Object
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
|