Class: ThinkFeelDoEngine::BitMaker::SlidesController
Overview
Enables admin to create, update, destroy, and reorder (sort) slides Slides belong to slideshows
Constant Summary
collapse
- FIRST_SLIDE_POSITION =
1
ApplicationController::CSRF_COOKIE_NAME, ApplicationController::CSRF_HEADER_NAME, ApplicationController::INACTIVE_MESSAGE, ApplicationController::ROOT_URI
Instance Method Summary
collapse
#access_denied_resource_path, #after_sign_in_path_for, #after_sign_out_path_for, #raise_not_found!, #render_not_found
Instance Method Details
#create ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 26
def create
@slide = @slideshow.slides.build(slide_params)
authorize! :create, @slide
@slide.position = @slideshow.slides.count + 1
if @slide.save
flash[:success] = "Successfully created slide for slideshow"
redirect_to arm_bit_maker_slideshow_path(@arm, @slideshow)
else
flash[:alert] = @slide.errors.full_messages.join(", ")
render :new
end
end
|
#create_table_of_contents ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 39
def create_table_of_contents
toc_increment_slide_pos(@slideshow)
@slide = @slideshow.slides.build(
position: FIRST_SLIDE_POSITION,
title: "Table of Contents",
is_title_visible: true,
body: ""
)
authorize! :create, @slide
if @slide.save
@slideshow.update(has_table_of_contents: true)
flash[:success] = "Successfully created table of contents for "\
"slideshow."
redirect_to arm_bit_maker_slideshow_path(@arm, @slideshow)
else
toc_decrement_slide_pos(@slideshow)
flash[:alert] = @slide.errors.full_messages.join(", ")
render :new
end
end
|
#destroy ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 92
def destroy
if @slide.destroy
flash[:success] = "Slide deleted."
else
flash[:error] = "There were errors."
end
redirect_to arm_bit_maker_slideshow_path(@arm, @slide.slideshow)
end
|
#destroy_table_of_contents ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 62
def destroy_table_of_contents
@slide = @slideshow.slides.where(position: FIRST_SLIDE_POSITION).first
if @slide.destroy
toc_decrement_slide_pos(@slideshow)
@slideshow.update(has_table_of_contents: false)
flash[:success] = "Table of contents deleted."
else
flash[:error] = "There were errors."
end
redirect_to arm_bit_maker_slideshow_path(@arm, @slide.slideshow)
end
|
#edit ⇒ Object
79
80
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 79
def edit
end
|
#index ⇒ Object
17
18
19
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 17
def index
authorize! :index, @slideshow
end
|
#new ⇒ Object
21
22
23
24
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 21
def new
@slide = @slideshow.slides.build(type: params[:type])
authorize! :create, @slide
end
|
#preview ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 121
def preview
render text: Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(
filter_html: true,
safe_links_only: true
)
).render(params[:content] || "").html_safe
end
|
#show ⇒ Object
75
76
77
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 75
def show
render "think_feel_do_engine/slides/show"
end
|
#sort ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 102
def sort
authorize! :update, BitCore::Slideshow
first_slide = BitCore::Slide.find(params[:slide][0])
if @slideshow.has_table_of_contents &&
first_slide.title != "Table of Contents"
flash[:alert] = "Table of contents cannot be moved out of"\
" the first position."
render "think_feel_do_engine/slides/sort_with_reload.js"
elsif @slideshow.sort(params[:slide])
flash.now[:notice] = "Reorder was successful."
render "think_feel_do_engine/slides/sort.js"
else
flash.now[:alert] = @slideshow.errors.full_messages.join(", ")
render "think_feel_do_engine/slides/sort.js"
end
end
|
#update ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'app/controllers/think_feel_do_engine/bit_maker/slides_controller.rb', line 82
def update
if @slide.update(slide_params)
flash[:success] = "Successfully updated slide for slideshow"
redirect_to arm_bit_maker_slideshow_path(@arm, @slide.slideshow)
else
flash[:alert] = @slide.errors.full_messages.join(", ")
render :edit
end
end
|