remove sections ok

This commit is contained in:
Torsten 2022-12-02 19:09:58 +02:00
parent 2eaa344ed0
commit 3d61e44e09
5 changed files with 25 additions and 4 deletions

View File

@ -23,6 +23,13 @@ module Merged
redirect_to section_select_template_url(new_section.id)
end
def remove
page = @section.page
page.remove_section( @section )
page.save
redirect_to page_sections_url(page.name)
end
def set_image
@section.content["image"] = params[:image]
@section.save

View File

@ -12,8 +12,8 @@ module Merged
def green_button( text, url)
button( text , url , "bg-green-500" )
end
def submit_button(text)
clazz = "bg-blue-500 " + button_classes
def submit_button(text , danger = false )
clazz = danger ? "bg-blue-500 " : "bg-blue-500 " + button_classes
content_tag(:button , class: clazz , type: :submit) do
text
end

View File

@ -43,6 +43,15 @@ module Merged
section
end
def remove_section(section)
from_index = section.index
@sections.delete_at(from_index)
@content.delete_at(from_index)
@sections.each_with_index do |section, index|
section.set_index(index)
end
end
def first_template
@content[0]["template"]
end

View File

@ -13,7 +13,7 @@
= blue_button( "Up" , section_move_url(section.id , dir: :up) )
= blue_button( "Down" , section_move_url(section.id , dir: :down) )
= yellow_button("Edit" , section_path(section.id) )
= red_button( "Delete" , "/index" )
= red_button( "Delete" , section_remove_path(section.id) )
.relative.block.border.border-gray-100.p-4
%h3.mt-4.text-lg.font-bold Template
%p= section.template

View File

@ -10,12 +10,17 @@ Merged::Engine.routes.draw do
get :select_card_template
get :set_card_template
get :move
get :remove
resources :cards do
get :select_image
get :set_image
get :move
get :remove
end
end
get :remove
end
resources :images do
get :remove
end
resources :images
end