lib/netzke/basepack/search_panel.rb in netzke-basepack-0.8.2 vs lib/netzke/basepack/search_panel.rb in netzke-basepack-0.8.3
- old
+ new
@@ -10,26 +10,26 @@
:integer => [
["eq", I18n.t('netzke.basepack.search_panel.equals')],
["gt", I18n.t('netzke.basepack.search_panel.greater_than')],
["lt", I18n.t('netzke.basepack.search_panel.less_than')]
],
- :text => [
- ["contains", I18n.t('netzke.basepack.search_panel.contains')] # same as matches => %string%
+ :text => [
+ ["contains", I18n.t('netzke.basepack.search_panel.contains')] # same as matches => %string%
],
:string => [
["contains", I18n.t('netzke.basepack.search_panel.contains')], # same as matches => %string%
["matches", I18n.t('netzke.basepack.search_panel.matches')]
],
- :boolean => [
- ["is_any", I18n.t('netzke.basepack.search_panel.is_true')],
- ["is_true", I18n.t('netzke.basepack.search_panel.is_true')],
- ["is_false", I18n.t('netzke.basepack.search_panel.is_false')]
+ :boolean => [
+ ["is_any", I18n.t('netzke.basepack.search_panel.is_true')],
+ ["is_true", I18n.t('netzke.basepack.search_panel.is_true')],
+ ["is_false", I18n.t('netzke.basepack.search_panel.is_false')]
],
- :datetime => [
- ["eq", I18n.t('netzke.basepack.search_panel.date_equals')],
- ["gt", I18n.t('netzke.basepack.search_panel.after')],
- ["lt", I18n.t('netzke.basepack.search_panel.before')]
+ :datetime => [
+ ["eq", I18n.t('netzke.basepack.search_panel.date_equals')],
+ ["gt", I18n.t('netzke.basepack.search_panel.after')],
+ ["lt", I18n.t('netzke.basepack.search_panel.before')]
]
}
js_configure do |c|
c.extend = "Ext.form.FormPanel"
@@ -38,34 +38,19 @@
c.require :condition_field
c.mixin
c.attribute_operators_map = ATTRIBUTE_OPERATORS_MAP
end
- # Builds default query search panel, where each field is presented
- def default_query
- data_class.column_names.map do |c|
- column_type = data_class.columns_hash[c].type
- operator = (ATTRIBUTE_OPERATORS_MAP[column_type] || []).first.try(:fetch, 0) || "matches"
- {:attr => c, :attr_type => column_type, :operator => operator}
- end
+ def js_configure(c)
+ super
+ c.attrs = config[:fields]
+ c.preset_query = (config[:load_last_preset] ? last_preset.try(:fetch, "query") : config[:query]) || []
end
- def data_class
- @data_class ||= config[:model].constantize
- end
-
- def js_config
- super.merge(
- :attrs => attributes,
- :attrs_hash => data_class.column_names.inject({}){ |hsh,c|
- hsh.merge(c => data_adapter.get_property_type(data_class.columns_hash[c])) },
- :preset_query => (config[:load_last_preset] ? last_preset.try(:fetch, "query") : config[:query]) || []
- )
- end
-
def attributes
- config[:fields].map do |field|
- [field[:name], field[:field_label]]
+ config[:fields].map do |f|
+ f[:attr_type] ||= :string
+ {name: f[:name], field_label: f[:field_label], attr_type: f[:attr_type]}
end
end
def last_preset
(state[:presets] || []).last