fic new cards
This commit is contained in:
parent
76f5e4e6e1
commit
dc4124a03d
@ -36,7 +36,7 @@ module Merged
|
||||
def save
|
||||
super
|
||||
data = Card.all.collect {|obj| obj.attributes}
|
||||
File.write( OptionDefinition.full_path , data.to_yaml)
|
||||
File.write( Card.full_path , data.to_yaml)
|
||||
end
|
||||
|
||||
def set_index(index)
|
||||
@ -47,12 +47,14 @@ module Merged
|
||||
CardStyle.find_by_template( section.card_template)
|
||||
end
|
||||
|
||||
def self.build_data(card_template)
|
||||
data = { "id" => SecureRandom.hex(10) }
|
||||
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|
|
||||
data[key] = key.upcase
|
||||
data[key] = "NEW"
|
||||
end
|
||||
data
|
||||
card = Card.new(data)
|
||||
card.add_default_options
|
||||
card
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -27,6 +27,13 @@ module Merged
|
||||
options[option] = value
|
||||
end
|
||||
|
||||
def add_default_options
|
||||
option_definitions.each do |option|
|
||||
next unless option.default
|
||||
set_option( option.name , option.default)
|
||||
end
|
||||
end
|
||||
|
||||
def update(key , value)
|
||||
raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key)
|
||||
if(! attributes[key].nil? ) # first setting ok, types not (yet?) specified
|
||||
|
@ -9,8 +9,6 @@ module Merged
|
||||
|
||||
fields :name , :content , :size , :updated_at
|
||||
|
||||
alias :id :name
|
||||
|
||||
def sections
|
||||
Section.where(page_id: name).order(index: :asc)
|
||||
end
|
||||
|
@ -35,11 +35,8 @@ module Merged
|
||||
end
|
||||
|
||||
def new_card
|
||||
card_data = Card.build_data(card_template)
|
||||
index = cards.length
|
||||
card = Card.new(self , index, card_data)
|
||||
@cards << card
|
||||
@content["cards"] << card_data
|
||||
card = Card.new_card( card_template , self.id , cards.length)
|
||||
card.save
|
||||
card
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user