delete code, untested
This commit is contained in:
@ -10,11 +10,7 @@ module Merged
|
||||
fields :index , :section_id, :id , :text , :header, :image
|
||||
|
||||
def template_style
|
||||
@section.card_template
|
||||
end
|
||||
|
||||
def destroy
|
||||
@section.remove_card( self)
|
||||
section.card_template
|
||||
end
|
||||
|
||||
def move_up
|
||||
@ -33,12 +29,6 @@ module Merged
|
||||
section.cards.where(index: index + 1).first
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
data = Card.all.collect {|obj| obj.attributes}
|
||||
File.write( Card.full_path , data.to_yaml)
|
||||
end
|
||||
|
||||
def set_index(index)
|
||||
@index = index
|
||||
end
|
||||
@ -47,6 +37,27 @@ module Merged
|
||||
CardStyle.find_by_template( section.card_template)
|
||||
end
|
||||
|
||||
def destroy
|
||||
delete
|
||||
Card.save_all
|
||||
end
|
||||
|
||||
def delete(reindex = true)
|
||||
Card.delete( self.id )
|
||||
section.reset_index if reindex
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
Card.save_all
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Card.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Card.full_path , data.to_yaml)
|
||||
Card.reload
|
||||
end
|
||||
|
||||
def self.new_card(card_template , section_id , index)
|
||||
data = { section_id: section_id , index: index}
|
||||
CardStyle.find_by_template( card_template ).fields.each do |key|
|
||||
|
@ -25,11 +25,6 @@ module Merged
|
||||
Page.new(name)
|
||||
end
|
||||
|
||||
def self.destroy( page )
|
||||
@@all.delete(page.name)
|
||||
File.delete(Rails.root.join(Page.cms_root , page.name + ".yaml"))
|
||||
end
|
||||
|
||||
def new_section(section_template)
|
||||
section_template = "section_spacer" if section_template.blank?
|
||||
section_data = Section.build_data(section_template)
|
||||
@ -54,11 +49,36 @@ module Merged
|
||||
@content[0]["template"]
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
data = Page.all.collect {|obj| obj.attributes}
|
||||
File.write( Page.full_path , data.to_yaml)
|
||||
def reset_index
|
||||
sections.each_with_index{|section, index| section.index = index + 1}
|
||||
end
|
||||
|
||||
def destroy
|
||||
has_sections , has_cards = delete()
|
||||
Page.save_all
|
||||
if has_sections > 0
|
||||
Section.save_all
|
||||
Card.save_all if has_cards > 0
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
has_sections = sections.length
|
||||
has_cards = 0
|
||||
sections.each {|section| has_cards += section.delete(false) }
|
||||
Page.delete( self.id )
|
||||
[has_sections , has_cards]
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
Page.save_all
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Page.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Page.full_path , data.to_yaml)
|
||||
Page.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -66,13 +66,6 @@ module Merged
|
||||
page.sections.where(index: index + 1).first
|
||||
end
|
||||
|
||||
|
||||
def save
|
||||
super
|
||||
data = Section.all.collect {|obj| obj.attributes}
|
||||
File.write( Section.full_path , data.to_yaml)
|
||||
end
|
||||
|
||||
def self.build_data(template)
|
||||
data = { "template" => template , "id" => SecureRandom.hex(10) }
|
||||
style = SectionStyle.sections[ template ]
|
||||
@ -86,5 +79,34 @@ module Merged
|
||||
data
|
||||
end
|
||||
|
||||
def reset_index
|
||||
cards.each_with_index{|card, index| card.index = index + 1}
|
||||
end
|
||||
|
||||
def destroy
|
||||
has_cards = delete()
|
||||
Section.save_all
|
||||
Card.save_all if has_cards > 0
|
||||
end
|
||||
|
||||
def delete( reindex = true )
|
||||
has_cards = cards.length
|
||||
cards.each {|card| card.delete(false) }
|
||||
Section.delete( self.id )
|
||||
page.reset_index if reindex
|
||||
has_cards
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
Section.save_all
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Section.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Section.full_path , data.to_yaml)
|
||||
Section.reload
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Merged
|
||||
fields :template , :text , :header, :fields , :cards
|
||||
|
||||
def has_cards?
|
||||
cards == true
|
||||
cards
|
||||
end
|
||||
|
||||
def section_preview
|
||||
|
Reference in New Issue
Block a user