Class: Aurita::GUI::Lore_Model_Select_Field
- Defined in:
- lib/lore/gui/lore_model_select_field.rb
Instance Method Summary collapse
-
#initialize(model, params, &block) ⇒ Lore_Model_Select_Field
constructor
A new instance of Lore_Model_Select_Field.
- #option_elements ⇒ Object
Constructor Details
#initialize(model, params, &block) ⇒ Lore_Model_Select_Field
Returns a new instance of Lore_Model_Select_Field.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lore/gui/lore_model_select_field.rb', line 9 def initialize(model, params, &block) @model = model @filter = params[:filter] @filter ||= true @data_type = Lore::PG_INT if block_given? then @select_block = block else @select_block = Proc.new { |clause| clause.where(@filter) } end params.delete(:filter) super(params) end |
Instance Method Details
#option_elements ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lore/gui/lore_model_select_field.rb', line 23 def option_elements elements = [] = [] foreign_table = @model.table_name selectables = @model.select(&@select_block) selectables.each { |foreign| foreign_label = '' if @model.get_labels.nil? then raise Aurita::GUI::Form_Error.new('Specify a label for has_a - related model klasses (here: ' << @model.to_s + ') via "use_label".') end @model.get_labels.each { |label_attrib| foreign_label << foreign.get_attribute_values[foreign_table][label_attrib.split('.')[-1]].to_s << ' ' } @model.get_primary_keys[foreign_table].uniq.each { |keys| key_string = '' keys.each { |key| # concatenate combined primary keys like 'id--id2' -> '3--4' if key_string != '' then key_string << '--' end key_string << foreign.get_attribute_values[foreign_table][key] } << { key_string => foreign_label } } } .each { |map| map.each_pair { |k,v| elements << HTML.option(:value => k) { v } } } elements end |