Class: ODDB::View::SearchBar

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) init



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'src/view/searchbar.rb', line 11

def init
  super
  val = @lookandfeel.lookup(@name)
  if(@value.nil? || @value.is_a?(StandardError))
    txt_val = if(@session.respond_to?(:persistent_user_input))
      @session.persistent_user_input(@name) 
    end || val
    @attributes.store('value', txt_val)
  end
  @attributes.update({
    'onFocus'  => "if (value=='#{val}') { value='' };",
    'onBlur' =>  "if (value=='') { value='#{val}' };",
    'id'     =>  "searchbar",
  })
  args = ['zone', @session.zone, @name, '']
  submit = @lookandfeel._event_url(@container.event, args)
  script = "if(#{@name}.value!='#{val}'){"
  script << "var href = '#{submit}'"
  script << "+encodeURIComponent(#{@name}.value.replace(/\\//, '%2F'));"
  script << "if(this.search_type)"
  script << "href += '/search_type/' + this.search_type.value;"
  unless @lookandfeel.disabled?(:best_result)
    script << "href += '#best_result';"
  end
  script << "document.location.href=href; } return false"
  self.onsubmit = script
end