Sha256: b20ae269811b4a6aef71b678582cb241485455bc8d9098345506a03e66c5ddd2
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
require 'clevic/delegates/combo_delegate' require 'clevic/dataset_roller.rb' module Clevic # Display a collection of possible related entities in the combo box. # TODO this should be a module class RelationalDelegate def needs_combo? dataset.count > 0 end def empty_set_message "There must be records in #{field.related_class} for this field to be editable." end def population # dataset contains the set of all possible related entities, # dataset is defined in Delegate # entity is set in init_component # field and entity are used by FieldValuer # including the current entity. # Could also use # dataset.or( entity_class.primary_key => entity_key.pk ) # but that would put current entity in the list somewhere # other than the top, which seems to be the most sensible # place for it. Could also create a special enumerator # which gives back the entity first, followed by the dataset. dataset.all.with do |values| # make sure there's only one instance of the current value, # and make sure it's at the top of the list values.delete( attribute_value ) values.unshift( attribute_value ) end end # don't allow new values def restricted?; true; end protected # Return an instance of the ORM dataset, # right now that's Sequel::Dataset. # This exists because convincing this functionality to # coexist in the same method as dataset would be tricky. def dataset unless field.find_options.empty? require 'clevic/ar_methods' field.related_class.plugin :ar_methods field.related_class.translate( field.find_options ) else field.dataset_roller.dataset end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
clevic-0.13.0.b9 | lib/clevic/delegates/relational_delegate.rb |
clevic-0.13.0.b6 | lib/clevic/delegates/relational_delegate.rb |
clevic-0.13.0.b5 | lib/clevic/delegates/relational_delegate.rb |