Class: Netzke::SearchPanel

Inherits:
FormPanel show all
Defined in:
lib/netzke/search_panel.rb

Overview

SearchPanel

FormPanel-based widget that allows create configurable searchlogic-compatible searches. Pretty much work in progress.

Constant Summary collapse

CONDITIONS =

Something like [:equals, :greater_than_or_equal_to, :does_not_equal, :less_than, :less_than_or_equal_to, :greater_than, :ends_with, :like, :begins_with, :empty, :null]

[:COMPARISON_CONDITIONS, :WILDCARD_CONDITIONS, :BOOLEAN_CONDITIONS].inject([]){|r, c| r + Searchlogic::NamedScopes::Conditions.const_get(c).keys}

Constants inherited from FormPanel

FormPanel::XTYPE_MAP

Instance Attribute Summary

Attributes inherited from FormPanel

#record

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FormPanel

#actions, #columns, config, #configuration_widgets, #data_class, #get_columns, include_js, #initialize, #normalized_columns, property_fields

Methods included from Plugins::ConfigurationTool

#config_tool_needed?, #config_with_config_tool, included, #initial_aggregatees_with_config_tool, #js_config_with_config_tool, #tools_with_config_tool

Methods included from DataAccessor

#apply_helpers, #normalize_array_of_columns, #normalize_column, #normalize_columns, #predefined_columns

Methods included from FormPanelApi

#array_of_values, #configuration_panel__fields__get_combobox_options, #create_or_update_record, #load, #submit

Methods included from FormPanelJs

included

Constructor Details

This class inherits a constructor from Netzke::FormPanel

Class Method Details

.config_columnsObject

columns to be displayed by the FieldConfigurator (which is GridPanel-based)



33
34
35
36
37
38
39
40
41
42
# File 'lib/netzke/search_panel.rb', line 33

def self.config_columns
  [
    {:name => :hidden, :type => :boolean, :editor => :checkbox, :width => 50},
    {:name => :name, :type => :string, :editor => :combobox},
    {:name => :condition, :type => :string, :editor => {:xtype => :combobox, :options => CONDITIONS}},
    {:name => :field_label, :type => :string},
    {:name => :xtype, :type => :string},
    {:name => :value, :type => :string},
  ]
end

Instance Method Details

#default_columnsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/netzke/search_panel.rb', line 16

def default_columns
  res = super

  res.map! do |f| 
    norm_column = normalize_column(f)
    norm_column.merge!({
      :condition => "equals"
    })
    norm_column.merge!(:hidden => true) if norm_column[:name].to_s.index("__")
    
    norm_column
  end
  
  res
end

#default_configObject



10
11
12
13
14
# File 'lib/netzke/search_panel.rb', line 10

def default_config
  super.merge({
    :data_class_name => @passed_config[:search_class_name]
  })
end

#get_combobox_options(params) ⇒ Object

we need to correct the queries to cut off the condition suffixes, otherwise the FormPanel gets confused



55
56
57
58
59
# File 'lib/netzke/search_panel.rb', line 55

def get_combobox_options(params)
  column_name = params[:column]
  CONDITIONS.each { |c| column_name.sub!(/_#{c}$/, "") }
  super(:column => column_name)
end

#js_configObject

tweaking the form fields at the last moment



45
46
47
48
49
50
51
52
# File 'lib/netzke/search_panel.rb', line 45

def js_config
  super.merge({
    :clmns => columns.map{ |c| c.merge({
      :field_label => "#{c[:field_label] || c[:name]} #{c[:condition]}".humanize,
      :name => "#{c[:name]}_#{c[:condition]}"
    })}
  })
end