Class: ODDB::View::AutocompleteSearchBar

Inherits:
HtmlGrid::InputText
  • Object
show all
Defined in:
src/view/searchbar.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) init



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'src/view/searchbar.rb', line 40

def init
  super
  val = @lookandfeel.lookup(@name)
  @container.additional_javascripts.push "function initMatches() {\nvar searchbar = dojo.byId('searchbar');\ndojo.connect(searchbar, 'onkeypress', function(e) {\nif(e.keyCode == dojo.keys.ENTER) {\nsearchbar.form.submit();\n}\n});\ndojo.connect(searchbar, 'onfocus', function(e) {\nif(searchbar.value == '\#{val}') { searchbar.value = ''; }\n});\ndojo.connect(searchbar, 'onblur', function(e) {\nif(searchbar.value == '') { searchbar.value = '\#{val}'; }\n});\n}\ndojo.addOnLoad(initMatches);\n"
  @attributes.update 'dojotype'      => 'dijit.form.ComboBox',
                     'jsId'          => 'searchbar',
                     'id'            => 'searchbar',
                     'store'         => 'search_matches',
                     'queryExpr'     => '${0}',
                     'searchAttr'    => 'search_query',
                     'hasDownArrow'  => 'false',
                     'autoComplete'  => 'false',
                     'value'         => @session.persistent_user_input(:search_query)
end

- (Object) to_html(context, *args)



71
72
73
74
75
76
77
78
79
80
81
82
# File 'src/view/searchbar.rb', line 71

def to_html(context, *args)
  args = []
  if @container.respond_to?(:index_name) && (index = @container.index_name)
    args.push :index_name, index
  end
  target = @lookandfeel._event_url(:ajax_matches, args)
  html = context.div 'dojoType'      => 'dojox.data.JsonRestStore',
                     'jsId'          => 'search_matches',
                     'idAttribute'   => 'search_query',
                     'target'        => target
  html << super
end