fixing the updates
This commit is contained in:
parent
912400b852
commit
aa20013121
@ -56,7 +56,7 @@ module Merged
|
||||
private
|
||||
def set_card
|
||||
card_id = params[:id] || params[:card_id]
|
||||
@card = Card.find_card( card_id )
|
||||
@card = Card.find( card_id )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -17,16 +17,6 @@ module Merged
|
||||
@section.remove_card( self)
|
||||
end
|
||||
|
||||
def update(key , value)
|
||||
return if key == "id" #not updating that
|
||||
if(! @content[key].nil? )
|
||||
if( @content[key].class != value.class )
|
||||
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
|
||||
end
|
||||
end
|
||||
@content[key] = value
|
||||
end
|
||||
|
||||
def move_up
|
||||
swap_index_with(next_card)
|
||||
end
|
||||
@ -57,10 +47,6 @@ module Merged
|
||||
CardStyle.find_by_template( section.card_template)
|
||||
end
|
||||
|
||||
def allowed_fields
|
||||
template_style.fields
|
||||
end
|
||||
|
||||
def self.build_data(card_template)
|
||||
data = { "id" => SecureRandom.hex(10) }
|
||||
CardStyle.find_by_template( card_template ).fields.each do |key|
|
||||
@ -69,11 +55,5 @@ module Merged
|
||||
data
|
||||
end
|
||||
|
||||
def self.find_card(id)
|
||||
raise "nil given" if id.blank?
|
||||
card = @@all[id]
|
||||
raise "Section not found #{id}" unless card
|
||||
return card
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,9 @@
|
||||
module Merged
|
||||
#relies only on @content["options"]
|
||||
#and a method template_style
|
||||
# and index
|
||||
# and is due for a rename
|
||||
|
||||
module Optioned
|
||||
def has_option?(option)
|
||||
options.has_key?(option) and !options[option].blank?
|
||||
@ -15,15 +18,25 @@ module Merged
|
||||
end
|
||||
|
||||
def options
|
||||
attributes[:options] || {}
|
||||
return attributes[:options] unless attributes[:options].blank?
|
||||
attributes[:options] = {}
|
||||
end
|
||||
|
||||
def set_option( option , value)
|
||||
puts "#{template_style} setting option #{option}=#{value.class}"
|
||||
@content["options"] = {} if @content["options"].nil?
|
||||
options[option] = value
|
||||
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
|
||||
if( @attributes[key].class != value.class )
|
||||
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
|
||||
end
|
||||
end
|
||||
attributes[key] = value
|
||||
end
|
||||
|
||||
#other may be nil
|
||||
def swap_index_with(other)
|
||||
return unless other
|
||||
@ -32,5 +45,9 @@ module Merged
|
||||
other.index = old_index
|
||||
end
|
||||
|
||||
def allowed_fields
|
||||
template_style.fields.collect{|f| f.to_sym}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -30,10 +30,6 @@ module Merged
|
||||
SectionStyle.find_by_template( template )
|
||||
end
|
||||
|
||||
def allowed_fields
|
||||
template_style.fields
|
||||
end
|
||||
|
||||
def has_cards?
|
||||
! card_template.blank?
|
||||
end
|
||||
@ -73,15 +69,6 @@ module Merged
|
||||
page.sections.where(index: index + 1).first
|
||||
end
|
||||
|
||||
def update(key , value)
|
||||
raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key)
|
||||
if(! @content[key].nil? ) # first setting ok, types not (yet?) specified
|
||||
if( @content[key].class != value.class )
|
||||
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
|
||||
end
|
||||
end
|
||||
@content[key] = value
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
@ -89,10 +76,6 @@ module Merged
|
||||
File.write( Section.full_path , data.to_yaml)
|
||||
end
|
||||
|
||||
def set_index(index)
|
||||
@index = index
|
||||
end
|
||||
|
||||
def self.build_data(template)
|
||||
data = { "template" => template , "id" => SecureRandom.hex(10) }
|
||||
style = SectionStyle.sections[ template ]
|
||||
|
Loading…
Reference in New Issue
Block a user