lib/rfm/layout.rb in ginjo-rfm-2.0.2 vs lib/rfm/layout.rb in ginjo-rfm-2.1.0.pre02
- old
+ new
@@ -117,10 +117,11 @@
# * +value_lists+ is a hash of arrays. The keys are value list names, and the values in the hash
# are arrays containing the actual value list items. +value_lists+ will include every value
# list that is attached to any field on the layout
class Layout
+ include Config
# Initialize a layout object. You never really need to do this. Instead, just do this:
#
# myServer = Rfm::Server.new(...)
# myDatabase = myServer["Customers"]
@@ -131,36 +132,48 @@
#
# In case it isn't obvious, this is more easily expressed this way:
#
# myServer = Rfm::Server.new(...)
# myLayout = myServer["Customers"]["Details"]
- def initialize(name, db_obj)
- raise Rfm::Error::RfmError.new(0, "New instance of Rfm::Layout has no name. Attempted name '#{name}'.") if name.to_s == ''
- @name = name.to_s
- rfm_metaclass.instance_variable_set :@db, db_obj
-
+ def initialize(*args) #name, db_obj
+ options = get_config(*args)
+ rfm_metaclass.instance_variable_set :@db, (options[:objects].delete_at(0) || options[:database_object])
+ config :parent=> 'db'
+ options = get_config(options)
+
+ config sanitize_config(options, {}, true)
+ config :layout => options[:strings].delete_at(0) || options[:layout]
+
+ raise Rfm::Error::RfmError.new(0, "New instance of Rfm::Layout has no name. Attempted name '#{state[:layout]}'.") if state[:layout].to_s == ''
+
@loaded = false
@field_controls = Rfm::CaseInsensitiveHash.new
@value_lists = Rfm::CaseInsensitiveHash.new
- # @portal_meta = nil
- # @field_names = nil
- @ignore_bad_data = (db_obj.server.state[:ignore_bad_data] rescue nil)
+ # @portal_meta = nil
+ # @field_names = nil
+ #@ignore_bad_data = (db_obj.server.state[:ignore_bad_data] rescue nil)
end
meta_attr_reader :db
- attr_reader :name #, :db
+ #attr_reader :name #, :db
attr_writer :field_names, :portal_meta, :table
def_delegator :db, :server
alias_method :database, :db
+
+ # This method may be obsolete, since the option can now be set with #config.
+ def ignore_bad_data(val = nil)
+ (config :ignore_bad_data => val) unless val.nil?
+ state[:ignore_bad_data]
+ end
-
# These methods are to be inclulded in Layout and SubLayout, so that
- # they have their own descrete 'self' in the master class and the subclass.
+ # they have their own discrete 'self' in the master class and the subclass.
# This means these methods will not get forwarded, and will talk to the correct
# variables & objects of the correct self.
# Do not get or set instance variables in Layout from other objects directly,
# always use getter & setter methods.
+ # This all means that any chain of methods that want to refer ultimately to Sublayout, must all be defined or included in Sublayout
module LayoutModule
# Returns a ResultSet object containing _every record_ in the table associated with this layout.
def all(options = {})
get_records('-findall', {}, options)
@@ -249,13 +262,17 @@
def view(options = {})
get_records('-view', {}, options)
end
def get_records(action, extra_params = {}, options = {})
+ # The grammar stuff here won't work properly until you handle config between models/sublayouts/layout/server.
+ grammar_option = state(options)[:grammar]
+ options.merge!(:grammar=>grammar_option) if grammar_option
include_portals = options[:include_portals] ? options.delete(:include_portals) : nil
- xml_response = db.server.connect(db.account_name, db.password, action, params.merge(extra_params), options).body
- Rfm::Resultset.new(db.server, xml_response, self, include_portals)
+ xml_response = server.connect(state[:account_name], state[:password], action, params.merge(extra_params), options).body
+ #Rfm::Resultset.new(db.server, xml_response, self, include_portals)
+ Rfm::Resultset.new(xml_response, self, include_portals)
end
def params
{"-db" => db.name, "-lay" => self.name}
end
@@ -279,13 +296,39 @@
hash[key] = val.join('\x1D')
end
end
hash
end
+
+ def name; state[:layout].to_s; end
+ def state(*args)
+ get_config(*args)
+ end
+
end # LayoutModule
+
include LayoutModule
+
+
+ ###
+ def view_meta
+ @view_meta ||= view
+ end
+ def date_format
+ @date_format ||= view_meta.date_format
+ end
+ def time_format
+ @time_format ||= view_meta.time_format
+ end
+ def timestamp_format
+ @timestamp_format ||= view_meta.timestamp_format
+ end
+ def field_meta
+ @field_meta ||= view_meta.field_meta
+ end
+ ###
def field_controls
load unless @loaded
@field_controls
@@ -373,14 +416,9 @@
@field_controls[name] = field_control
end
}
@field_names ||= @field_controls.collect{|k,v| v.name rescue v[0].name}
@field_controls.freeze
- end
-
- def ignore_bad_data(val = nil)
- (@ignore_bad_data = val) unless val.nil?
- @ignore_bad_data
end
private :load, :get_records, :params
\ No newline at end of file