forked from wearefine/Redmine-Workload-Dnoise
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwl_national_holiday_controller.rb
More file actions
84 lines (68 loc) · 2.55 KB
/
Copy pathwl_national_holiday_controller.rb
File metadata and controls
84 lines (68 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class WlNationalHolidayController < ApplicationController
unloadable
require 'json'
before_action :check_edit_rights, only: [:edit, :update, :create, :destroy]
before_action :select_year
helper :work_load
def index
filter_year_start=Date.new(@this_year,01,01)
filter_year_end=Date.new(@this_year,12,31)
@wl_national_holiday = WlNationalHoliday.where("start between ? AND ?", filter_year_start, filter_year_end)
@is_allowed = User.current.allowed_to_globally?(:edit_national_holiday)
end
def new
end
def edit
@wl_national_holiday = WlNationalHoliday.find(params[:id]) rescue nil
end
def update
@wl_national_holiday = WlNationalHoliday.find(params[:id]) rescue nil
respond_to do |format|
if @wl_national_holiday.update_attributes(wl_national_holiday_params)
format.html { redirect_to(:action => 'index', :notice => 'Holiday was successfully updated.', :params => { :year =>params[:year]} ) }
format.xml { head :ok }
else
format.html {
flash[:error] = "<ul>" + @wl_national_holiday.errors.full_messages.map{|o| "<li>" + o + "</li>" }.join("") + "</ul>"
render :action => "edit" }
format.xml { render :xml => @wl_national_holiday.errors, :status => :unprocessable_entity }
end
end
end
def create
@wl_national_holiday = WlNationalHoliday.new(wl_national_holiday_params)
if @wl_national_holiday.save
redirect_to action: 'index', notice: 'Holiday was successfully saved.', year: params[:year]
else
respond_to do |format|
format.html {
flash[:error] = "<ul>" + @wl_national_holiday.errors.full_messages.map{|o| "<li>" + o + "</li>" }.join("") + "</ul>"
render :new }
format.api { render_validation_errors(@wl_national_holiday) }
end
end
end
def destroy
@wl_national_holiday = WlNationalHoliday.find(params[:id]) rescue nil
@wl_national_holiday.destroy
redirect_to(:action => 'index', :notice => 'Holiday was successfully deleted.', :year => params[:year])
end
private
def check_edit_rights
right = User.current.allowed_to_globally?(:edit_national_holiday)
if !right
flash[:error] = translate 'no_right'
redirect_to :back
end
end
def select_year
if (params[:year])
@this_year=params[:year].to_i
else
@this_year=Date.today.strftime("%Y").to_i if @this_year.blank?
end
end
def wl_national_holiday_params
params.require(:wl_national_holiday).permit(:start,:end,:reason)
end
end