parent
b268bbc38a
commit
ee85a792e8
@ -0,0 +1,2 @@ |
||||
class Widget |
||||
end |
@ -0,0 +1,16 @@ |
||||
class Widget::Base |
||||
attr_reader :engine |
||||
|
||||
def self.render(subject) |
||||
new(subject).render |
||||
end |
||||
|
||||
def initialize(query) |
||||
@query = query |
||||
@engine = query.engine |
||||
end |
||||
|
||||
def render |
||||
raise NotImplementedError, "#render is not implemented in the subclasses" |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
class Widget::Filters < Widget::Base |
||||
def render |
||||
@query.engine::Filter.all.collect do |f| |
||||
render_filter f |
||||
end.join |
||||
end |
||||
|
||||
def render_filter(f) |
||||
Filters::Label.render(f) |
||||
Filters::Operators.render(f) |
||||
|
||||
return filter.custom_elements if filter.custom_elements? |
||||
return object_elements_with_dependents filter if filter.has_dependents? |
||||
return text_elements filter if engine::Operator.string_operators.all? { |o| filter.available_operators.include? o } |
||||
return date_elements filter if engine::Operator.time_operators.all? { |o| filter.available_operators.include? o } |
||||
return object_elements filter |
||||
end |
||||
|
||||
def object_elements_with_dependents(filter) |
||||
object_elements(filter).tap do |elements| |
||||
elements.last[:dependents] = filter.injected_dependents.collect(&:underscore_name) |
||||
elements.last[:name] = :multi_values_with_dependent |
||||
end |
||||
end |
||||
|
||||
def object_elements(f) |
||||
Filters::MultiValues.render(f) |
||||
end |
||||
|
||||
def date_elements(filter) |
||||
[ |
||||
{:name => :date, :filter_name => filter.underscore_name}] |
||||
end |
||||
|
||||
def text_elements(filter) |
||||
[ |
||||
{:name => :text_box, :filter_name => filter.underscore_name}] |
||||
end |
||||
end |
@ -0,0 +1,8 @@ |
||||
class Widget::Filters::Base < Widget::Base |
||||
attr_reader :filter |
||||
|
||||
def initialize(filter) |
||||
@filter = filter |
||||
@engine = engine |
||||
end |
||||
end |
@ -0,0 +1,17 @@ |
||||
class Widget::Filters::Date < Widget::Filters::Base |
||||
def render |
||||
name = "values[#{filter.underscore_name}][]" |
||||
id_prefix = "#{filter.underscore_name}_" |
||||
|
||||
content_tag :td do |
||||
content_tag :div, :id => "#{id_prefix}arg_1", :class => "filter_values" do |
||||
text_field_tag name, "", :size => 10, :class => "select-small", :id => "#{id_prefix}arg_1_val" |
||||
calendar_for("#{id_prefix}arg_1_val") |
||||
content_tag :span, :id => "#{id_prefix}arg_2", :class => "between_tags" do |
||||
text_field_tag "#{name}", "", :size => 10, :class => "select-small", :id => "#{id_prefix}arg_2_val" |
||||
calendar_for "#{id_prefix}arg_2_val" |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,9 @@ |
||||
class Widget::Filters::Label < Widget::Filters::Base |
||||
def render |
||||
content_tag :td, :width => (filter.width || 150) do |
||||
content_tag :label, :id => filter.underscore_name do |
||||
l(filter.label) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
class Widget::Filters::MultiValues < Widget::Filters::Base |
||||
|
||||
def render |
||||
content_tag :td do |
||||
content_tag :div, :id => filter.underscore_name, :class => "filter_values" do |
||||
content_tag :select, :style => "vertical-align: top;", # FIXME: Do CSS |
||||
:name => "values[#{filter.underscore_name}][]", |
||||
:id => "#{filter.underscore_name}_arg_1_val", |
||||
:class => "select-small filters-select", |
||||
:multiple => "multiple" do |
||||
# multiple will be disabled/enabled later by JavaScript anyhow. |
||||
# We need to specify multiple here because of an IE6-bug. |
||||
filter.values.each do |name, id, *args| |
||||
options = args.first || {} # optional configuration for values |
||||
level = options[:level] # nesting_level is optional for values |
||||
name = l(name) if name.is_a? Symbol |
||||
name_prefix = ((level && level > 0) ? (' ' * 2 * level + '> ') : '') |
||||
unless options[:optgroup] |
||||
content_tag :option, :value => id do |
||||
name_prefix + h(name) |
||||
end |
||||
else |
||||
tag :optgroup, :label => l(:label_sector) |
||||
end |
||||
end |
||||
end |
||||
link_to_function image_tag('bullet_toggle_plus.png'), |
||||
"toggle_multi_select($('#{element[:filter_name]}_arg_1_val'));", |
||||
:style => "vertical-align: bottom;" |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,23 @@ |
||||
class Widget::Filters::Operators < Widget::Filters::Base |
||||
def render |
||||
content_tag :td, :width => (filter.width || 100) do |
||||
content_tag :select, :class => "select-small filters-select", |
||||
:style => "vertical-align: top", # FIXME: put into CSS |
||||
:id => "operators[#{filter.underscore_name}]", |
||||
:onchange => "operator_changed('#{filter.underscore_name}', this);", |
||||
:name => "operators[#{filter.underscore_name}]" do |
||||
filter.available_operators.each do |o| |
||||
if filter.operator.to_s = o.to_s |
||||
content_tag :option, :value => h(o.to_s), :data-arity => o.arity, :selected => "selected" do |
||||
h(l(o.label)) |
||||
end |
||||
else |
||||
content_tag :option, :value => h(o.to_s), :data-arity => o.arity do |
||||
h(l(o.label)) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,2 @@ |
||||
class Widget::GroupBys < Widget::Base |
||||
end |
@ -0,0 +1,2 @@ |
||||
class Widget::Settings < Widget::Base |
||||
end |
@ -0,0 +1,2 @@ |
||||
class Widget::Table < Widget::Base |
||||
end |
Loading…
Reference in new issue