Module: ViewMapper::AutoCompleteView
- Defined in:
- lib/view_mapper/views/auto_complete/auto_complete_view.rb
Class Method Summary collapse
Instance Method Summary collapse
- #auto_complete_attributes ⇒ Object
- #auto_complete_for_method(attrib) ⇒ Object
- #auto_complete_installed ⇒ Object
- #manifest ⇒ Object
- #parse_auto_complete_attributes_from_param ⇒ Object
- #validate ⇒ Object
- #validate_auto_complete_attribute(attrib_name) ⇒ Object
- #validate_auto_complete_attributes ⇒ Object
Class Method Details
.source_root ⇒ Object
4 5 6 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 4 def self.source_root File.(File.dirname(__FILE__) + "/templates") end |
Instance Method Details
#auto_complete_attributes ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 25 def auto_complete_attributes if view_param parse_auto_complete_attributes_from_param elsif view_only? model.text_fields else [] end end |
#auto_complete_for_method(attrib) ⇒ Object
21 22 23 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 21 def auto_complete_for_method(attrib) "auto_complete_for_#{singular_name}_#{attrib}" end |
#auto_complete_installed ⇒ Object
72 73 74 75 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 72 def auto_complete_installed ActionController::Base.methods.include?('auto_complete_for') || ActionController::Base.methods.include?(:auto_complete_for) end |
#manifest ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 8 def manifest manifest = super if @valid auto_complete_attributes.each do |attrib| manifest.route :name => 'connect', :path => auto_complete_for_method(attrib), :controller => controller_file_name, :action => auto_complete_for_method(attrib) end end manifest end |
#parse_auto_complete_attributes_from_param ⇒ Object
35 36 37 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 35 def parse_auto_complete_attributes_from_param view_param.split(',') end |
#validate ⇒ Object
39 40 41 42 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 39 def validate super @valid &&= validate_auto_complete_attributes end |
#validate_auto_complete_attribute(attrib_name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 60 def validate_auto_complete_attribute(attrib_name) attrib = attributes.find { |a| a.name == attrib_name } if attrib.nil? logger.error "Field '#{attrib_name}' does not exist." return false elsif !ModelInfo.is_text_field_attrib_type? attrib.type logger.error "Field '#{attrib_name}' is not a text field." return false end true end |
#validate_auto_complete_attributes ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/view_mapper/views/auto_complete/auto_complete_view.rb', line 44 def validate_auto_complete_attributes if !auto_complete_installed logger.error "The auto_complete plugin does not appear to be installed." return false elsif auto_complete_attributes.empty? if view_only? logger.error "No text fields exist in the specified class." else logger.error "No auto_complete attribute specified." end return false else !auto_complete_attributes.detect { |a| !validate_auto_complete_attribute(a) } end end |