-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathworkshop_ideas_controller.rb
More file actions
143 lines (124 loc) · 4.3 KB
/
workshop_ideas_controller.rb
File metadata and controls
143 lines (124 loc) · 4.3 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
class WorkshopIdeasController < ApplicationController
include AssetUpdatable
before_action :set_workshop_idea, only: [ :show, :edit, :update, :destroy ]
def index
per_page = params[:number_of_items_per_page].presence || 25
workshop_ideas = WorkshopIdea.search(params.slice(:title, :author_name))
@workshop_ideas_count = workshop_ideas.size
@workshop_ideas = workshop_ideas.paginate(page: params[:page], per_page: per_page).decorate
end
def show
end
def new
@workshop_idea = WorkshopIdea.new
set_form_variables
end
def create
@workshop_idea = WorkshopIdea.new(workshop_idea_params)
if @workshop_idea.save
NotificationServices::CreateNotification.call(
noticeable: @workshop_idea,
kind: :idea_submitted_fyi,
recipient_role: :admin,
recipient_email: ENV.fetch("REPLY_TO_EMAIL", "programs@awbw.org"),
notification_type: 0)
if params.dig(:library_asset, :new_assets).present?
update_asset_owner(@workshop_idea)
end
redirect_to workshop_ideas_path, notice: "Workshop idea was successfully created."
else
set_form_variables
render :new, status: :unprocessable_content
end
end
def edit
set_form_variables
end
def update
if @workshop_idea.update(workshop_idea_params)
redirect_to workshop_ideas_path, notice: "Workshop idea was successfully updated.", status: :see_other
else
set_form_variables
render :edit, status: :unprocessable_content
end
end
def destroy
@workshop_idea.destroy!
redirect_to workshop_ideas_path, notice: "Workshop idea was successfully destroyed."
end
# Optional hooks for setting variables for forms or index
def set_form_variables
@age_ranges = Category.includes(:category_type).where("category_types.name = 'AgeRange'").pluck(:name)
@potential_series_workshops = Workshop.published.order(:title)
@category_types = CategoryType.includes(:categories).published.decorate
@sectors = Sector.published
@windows_types = WindowsType.all
end
private
def set_workshop_idea
@workshop_idea = WorkshopIdea.find(params[:id])
end
# Strong parameters
def workshop_idea_params
params.require(:workshop_idea).permit(
:title, :staff_notes,
:created_by_id, :updated_by_id, :windows_type_id,
:time_closing, :time_creation, :time_demonstration,
:time_hours, :time_intro, :time_minutes,
:time_opening, :time_opening_circle, :time_warm_up,
:age_range, :age_range_spanish,
:closing, :closing_spanish,
:creation, :creation_spanish,
:demonstration, :demonstration_spanish,
:description, :description_spanish,
:instructions, :instructions_spanish,
:introduction, :introduction_spanish,
:materials, :materials_spanish,
:notes, :notes_spanish,
:objective, :objective_spanish,
:opening_circle, :opening_circle_spanish,
:optional_materials, :optional_materials_spanish,
:setup, :setup_spanish,
:tips, :tips_spanish,
:timeframe, :timeframe_spanish,
:visualization, :visualization_spanish,
:warm_up, :warm_up_spanish,
:rhino_objective,
:rhino_materials,
:rhino_optional_materials,
:rhino_setup,
:rhino_introduction,
:rhino_opening_circle,
:rhino_demonstration,
:rhino_warm_up,
:rhino_visualization,
:rhino_creation,
:rhino_closing,
:rhino_notes,
:rhino_tips,
:rhino_misc1,
:rhino_misc2,
:rhino_extra_field,
:rhino_objective_spanish,
:rhino_materials_spanish,
:rhino_optional_materials_spanish,
:rhino_age_range_spanish,
:rhino_setup_spanish,
:rhino_introduction_spanish,
:rhino_opening_circle_spanish,
:rhino_demonstration_spanish,
:rhino_warm_up_spanish,
:rhino_visualization_spanish,
:rhino_creation_spanish,
:rhino_closing_spanish,
:rhino_notes_spanish,
:rhino_tips_spanish,
:rhino_misc1_spanish,
:rhino_misc2_spanish,
:rhino_extra_field_spanish,
workshop_series_children_attributes: [ :id, :workshop_child_id, :workshop_parent_id, :theme_name,
:series_description, :series_description_spanish,
:position, :_destroy ],
)
end
end