lib/rfm/layout.rb in ginjo-rfm-2.1.0.pre02 vs lib/rfm/layout.rb in ginjo-rfm-2.1.0

- old
+ new

@@ -152,11 +152,11 @@ # @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 :field_mapping 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. @@ -207,10 +207,12 @@ # assumed to be FileMaker's internal id for a record (the recid). # # myLayout.find 54321 # def find(find_criteria, options = {}) + #puts "layout.find-#{self}" + options.merge!({:field_mapping => field_mapping}) if field_mapping get_records(*Rfm::CompoundQuery.new(find_criteria, options)) end # Access to raw -findquery command. def query(query_hash, options = {}) @@ -262,16 +264,25 @@ 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. + # TODO: The grammar stuff here won't work properly until you handle config between + # models/sublayouts/layout/server (Is this done now?). 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 = server.connect(state[:account_name], state[:password], action, params.merge(extra_params), options).body - #Rfm::Resultset.new(db.server, xml_response, self, include_portals) + #include_portals = options[:include_portals] ? options.delete(:include_portals) : nil + include_portals = !options[:ignore_portals] + + # Apply mapping from :field_mapping, to send correct params in URL. + prms = params.merge(extra_params) + map = field_mapping.invert + # TODO: Make this part handle string AND symbol keys. + #map.each{|k,v| prms[k]=prms.delete(v) if prms[v]} + prms.dup.each_key{|k| prms[map[k.to_s]]=prms.delete(k) if map[k.to_s]} + + xml_response = server.connect(state[:account_name], state[:password], action, prms, options).body Rfm::Resultset.new(xml_response, self, include_portals) end def params {"-db" => db.name, "-lay" => self.name} @@ -397,11 +408,11 @@ @value_lists.freeze end # process field controls doc['FMPXMLLAYOUT']['LAYOUT']['FIELD'].each {|field| - name = field['NAME'] + name = field_mapping[field['NAME']] || field['NAME'] style = field['STYLE'] type = style['TYPE'] value_list_name = style['VALUELIST'] value_list = @value_lists[value_list_name] if value_list_name != '' field_control = Rfm::Metadata::FieldControl.new(name, type, value_list_name, value_list) @@ -417,9 +428,21 @@ end } @field_names ||= @field_controls.collect{|k,v| v.name rescue v[0].name} @field_controls.freeze end + + def field_mapping + @field_mapping ||= load_field_mapping(get_config[:field_mapping]) + end + + def load_field_mapping(mapping={}) + mapping = (mapping || {}).to_cih + def mapping.invert + super.to_cih + end + mapping + end private :load, :get_records, :params end # Layout \ No newline at end of file