lib/netzke/basepack/search_panel.rb in netzke-basepack-0.7.7 vs lib/netzke/basepack/search_panel.rb in netzke-basepack-0.8.0
- old
+ new
@@ -4,51 +4,49 @@
# +load_last_preset+ - on load, tries to load the latest saved preset
class SearchPanel < Base
include Netzke::Basepack::DataAccessor
- js_base_class "Ext.form.FormPanel"
-
- js_properties(
- :padding => 5,
- :auto_scroll => true
- )
-
- js_include :condition_field
-
- js_mixin :search_panel
-
- js_property :attribute_operators_map, {
+ ATTRIBUTE_OPERATORS_MAP = {
: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"
+ c.padding = 5
+ c.auto_scroll = true
+ 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 = (self.class.js_property(:attribute_operators_map)[column_type] || []).first.try(:fetch, 0) || "matches"
+ operator = (ATTRIBUTE_OPERATORS_MAP[column_type] || []).first.try(:fetch, 0) || "matches"
{:attr => c, :attr_type => column_type, :operator => operator}
end
end
def data_class
@@ -56,10 +54,10 @@
end
def js_config
super.merge(
:attrs => attributes,
- :attrs_hash => data_class.column_names.inject({}){ |hsh,c|
+ :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