fix all news
This commit is contained in:
@ -9,10 +9,6 @@ module Merged
|
||||
|
||||
fields :index , :section_id, :id , :text , :header, :image
|
||||
|
||||
def template_style
|
||||
section.card_template
|
||||
end
|
||||
|
||||
def move_up
|
||||
swap_index_with(next_card)
|
||||
end
|
||||
@ -60,11 +56,12 @@ module Merged
|
||||
|
||||
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|
|
||||
template = CardStyle.find_by_template( card_template )
|
||||
template.fields.each do |key|
|
||||
data[key] = "NEW"
|
||||
end
|
||||
card = Card.new(data)
|
||||
card.add_default_options
|
||||
card.add_default_options(template.options_definitions)
|
||||
card
|
||||
end
|
||||
|
||||
|
@ -23,12 +23,12 @@ module Merged
|
||||
end
|
||||
|
||||
def set_option( option , value)
|
||||
puts "#{template_style} setting option #{option}=#{value.class}"
|
||||
options[option] = value
|
||||
end
|
||||
|
||||
def add_default_options
|
||||
option_definitions.each do |option|
|
||||
def add_default_options( definitions = nil )
|
||||
definitions = option_definitions if definitions.nil?
|
||||
definitions.each do |option|
|
||||
next unless option.default
|
||||
set_option( option.name , option.default)
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ module Merged
|
||||
|
||||
def new_section(section_template)
|
||||
section_template = "section_spacer" if section_template.blank?
|
||||
section = Section.new_section(section_template, self.id , sections.length)
|
||||
section = Section.new_section(section_template, self.id , sections.length + 1)
|
||||
section
|
||||
end
|
||||
|
||||
|
@ -19,10 +19,8 @@ module Merged
|
||||
new_style = template_style
|
||||
if(new_style.has_cards?)
|
||||
unless card_template
|
||||
self.card_template = CardStyle.first.name
|
||||
self.card_template = CardStyle.first.template
|
||||
end
|
||||
else
|
||||
cards.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
@ -43,7 +41,6 @@ module Merged
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def move_up
|
||||
swap_index_with(next_section)
|
||||
end
|
||||
@ -60,19 +57,9 @@ module Merged
|
||||
page.sections.where(index: index + 1).first
|
||||
end
|
||||
|
||||
def self.new_section(template , page_id , index)
|
||||
data = { template: template , index: index , page_id: page_id}
|
||||
style = SectionStyle.find_by_template( template)
|
||||
style.fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end unless style.fields.blank?
|
||||
if(style.has_cards?)
|
||||
data["cards"] = []
|
||||
data["card_template"] = CardStyle.first.name
|
||||
end
|
||||
s = Section.new(data)
|
||||
s.add_default_options
|
||||
s
|
||||
def new_card
|
||||
card = Card.new_card(card_template, self.id , cards.length + 1)
|
||||
card
|
||||
end
|
||||
|
||||
def reset_index
|
||||
@ -98,6 +85,21 @@ module Merged
|
||||
Section.save_all
|
||||
end
|
||||
|
||||
def self.new_section(template , page_id , index)
|
||||
data = { template: template , index: index , page_id: page_id}
|
||||
style = SectionStyle.find_by_template( template)
|
||||
style.fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end unless style.fields.blank?
|
||||
if(style.has_cards?)
|
||||
data["cards"] = []
|
||||
data["card_template"] = CardStyle.first.name
|
||||
end
|
||||
s = Section.new(data)
|
||||
s.add_default_options
|
||||
s
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Section.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Section.full_path , data.to_yaml)
|
||||
|
Reference in New Issue
Block a user