2022-11-28 22:58:17 +01:00
|
|
|
module Merged
|
|
|
|
class SectionsController < MergedController
|
2022-12-02 17:29:17 +01:00
|
|
|
before_action :set_section , except: [:index ,:new]
|
2022-11-28 22:58:17 +01:00
|
|
|
|
2022-11-30 15:22:11 +01:00
|
|
|
def index
|
|
|
|
@page = Page.find(params[:page_id])
|
|
|
|
end
|
2022-12-02 17:29:17 +01:00
|
|
|
|
2022-11-29 19:03:48 +01:00
|
|
|
def select_template
|
2022-12-10 19:29:31 +01:00
|
|
|
@sections = SectionStyle.all
|
2022-11-29 19:03:48 +01:00
|
|
|
end
|
2022-12-10 19:29:31 +01:00
|
|
|
|
2022-11-29 19:22:57 +01:00
|
|
|
def select_card_template
|
2022-12-10 19:29:31 +01:00
|
|
|
@cards = CardStyle.all
|
2022-11-29 19:22:57 +01:00
|
|
|
end
|
2022-11-28 22:58:17 +01:00
|
|
|
|
2022-12-02 17:29:17 +01:00
|
|
|
def new
|
|
|
|
page = Page.find(params[:page_id])
|
2022-12-02 23:14:19 +01:00
|
|
|
template = params[:template]
|
|
|
|
new_section = page.new_section(template)
|
2023-10-23 19:20:31 +02:00
|
|
|
new_section.add_save(current_member_email)
|
2022-12-02 23:14:19 +01:00
|
|
|
if(template.blank?) # new
|
2022-12-07 13:14:18 +01:00
|
|
|
redirect_to section_select_template_url(new_section.id), notice: "New section created"
|
2022-12-02 23:14:19 +01:00
|
|
|
else # copy
|
2022-12-07 13:14:18 +01:00
|
|
|
redirect_to section_url(new_section.id), notice: "Section copied"
|
2022-12-02 23:14:19 +01:00
|
|
|
end
|
2022-12-02 17:29:17 +01:00
|
|
|
end
|
|
|
|
|
2022-12-05 10:56:43 +01:00
|
|
|
def destroy
|
2023-10-23 19:20:31 +02:00
|
|
|
@section.delete_and_reset_index(current_member_email)
|
2022-12-11 20:30:25 +01:00
|
|
|
redirect_to page_sections_url(@section.page.id) , notice: "Section #{@section.header} removed"
|
2022-12-02 18:09:58 +01:00
|
|
|
end
|
|
|
|
|
2022-11-28 22:58:17 +01:00
|
|
|
def set_image
|
2022-12-19 17:55:11 +01:00
|
|
|
@section.image_id = params[:image_id].to_i
|
2023-10-23 19:20:31 +02:00
|
|
|
@section.edit_save(current_member_email)
|
2023-01-02 21:52:01 +01:00
|
|
|
message = @section.image ? "#{@section.image.name} selected" : "Image removed"
|
|
|
|
redirect_to section_url(@section.id) , notice: message
|
2022-11-28 22:58:17 +01:00
|
|
|
end
|
|
|
|
|
2022-11-29 19:03:48 +01:00
|
|
|
def set_template
|
2022-11-29 19:22:57 +01:00
|
|
|
template = params[:template]
|
|
|
|
raise "no template given" if template.blank?
|
2023-01-20 19:14:23 +01:00
|
|
|
style = SectionStyle.where(template: template).first
|
|
|
|
raise "no such template #{template}" unless style
|
|
|
|
if(! style.has_cards?)
|
|
|
|
if( @section.cards.length > 0 )
|
|
|
|
redirect_to section_url(@section.id) , alert: "Must delete cards first"
|
|
|
|
return
|
|
|
|
end
|
2023-01-23 14:30:43 +01:00
|
|
|
@section.card_template = ""
|
2023-01-20 19:14:23 +01:00
|
|
|
end
|
2022-12-02 23:14:19 +01:00
|
|
|
@section.set_template( template )
|
2023-10-23 19:20:31 +02:00
|
|
|
@section.edit_save(current_member_email)
|
2022-11-30 15:22:11 +01:00
|
|
|
redirect_to section_url(@section.id)
|
2022-11-29 19:22:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_card_template
|
|
|
|
card_template = params[:card_template]
|
|
|
|
raise "no card template given" if card_template.blank?
|
2022-12-14 16:17:16 +01:00
|
|
|
@section.card_template = card_template
|
2023-10-23 19:20:31 +02:00
|
|
|
@section.edit_save(current_member_email)
|
2022-11-30 15:22:11 +01:00
|
|
|
redirect_to section_url(@section.id)
|
2022-11-29 19:03:48 +01:00
|
|
|
end
|
|
|
|
|
2022-12-01 19:14:34 +01:00
|
|
|
def move
|
|
|
|
if( params[:dir] == "up")
|
|
|
|
@section.move_up
|
|
|
|
else
|
|
|
|
@section.move_down
|
|
|
|
end
|
2023-10-23 19:20:31 +02:00
|
|
|
@section.edit_save(current_member_email)
|
2022-12-11 15:44:19 +01:00
|
|
|
redirect_to page_sections_url(@section.page.id)
|
2022-12-01 19:14:34 +01:00
|
|
|
end
|
|
|
|
|
2022-11-28 22:58:17 +01:00
|
|
|
def update
|
2023-01-20 14:40:41 +01:00
|
|
|
@section.update(params[:section])
|
2023-01-20 15:49:11 +01:00
|
|
|
@section.update_options( params[:options])
|
2023-10-23 19:20:31 +02:00
|
|
|
@section.edit_save(current_member_email)
|
2022-12-07 13:14:18 +01:00
|
|
|
redirect_to :section , notice: "Update ok"
|
2022-11-28 22:58:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2022-11-30 15:22:11 +01:00
|
|
|
def set_section
|
|
|
|
@section = Section.find( params[:id] || params[:section_id] )
|
2022-11-28 22:58:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|