Class: Carnival::Field
- Inherits:
-
Object
- Object
- Carnival::Field
- Defined in:
- app/models/carnival/field.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #advanced_search_operator ⇒ Object
- #advanced_searchable? ⇒ Boolean
- #as ⇒ Object
- #css_class ⇒ Object
- #date_filter? ⇒ Boolean
- #date_filter_periods ⇒ Object
- #default_date_filter ⇒ Object
- #default_sort_direction ⇒ Object
- #default_sortable? ⇒ Boolean
-
#initialize(name, params = {}) ⇒ Field
constructor
A new instance of Field.
- #nested_form? ⇒ Boolean
- #nested_form_allow_destroy? ⇒ Boolean
- #searchable? ⇒ Boolean
- #sortable? ⇒ Boolean
- #valid_for_action?(action) ⇒ Boolean
- #widget ⇒ Object
Constructor Details
#initialize(name, params = {}) ⇒ Field
Returns a new instance of Field.
6 7 8 9 10 |
# File 'app/models/carnival/field.rb', line 6 def initialize(name, params={}) @params = params @name = name set_position_by_params end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
4 5 6 |
# File 'app/models/carnival/field.rb', line 4 def column @column end |
#line ⇒ Object
Returns the value of attribute line.
4 5 6 |
# File 'app/models/carnival/field.rb', line 4 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'app/models/carnival/field.rb', line 4 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'app/models/carnival/field.rb', line 4 def params @params end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'app/models/carnival/field.rb', line 4 def size @size end |
Instance Method Details
#advanced_search_operator ⇒ Object
84 85 86 87 |
# File 'app/models/carnival/field.rb', line 84 def advanced_search_operator return @params[:advanced_search][:operator] if advanced_searchable? and @params[:advanced_search][:operator].present? :like end |
#advanced_searchable? ⇒ Boolean
80 81 82 |
# File 'app/models/carnival/field.rb', line 80 def advanced_searchable? @params[:advanced_search] end |
#as ⇒ Object
93 94 95 |
# File 'app/models/carnival/field.rb', line 93 def as @params[:as] end |
#css_class ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/models/carnival/field.rb', line 16 def css_class if @params[:css_class] return @params[:css_class] else return "" end end |
#date_filter? ⇒ Boolean
24 25 26 |
# File 'app/models/carnival/field.rb', line 24 def date_filter? @params[:date_filter] end |
#date_filter_periods ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/carnival/field.rb', line 36 def date_filter_periods if @params[:date_filter_periods] @params[:date_filter_periods] else {:today => ["#{Date.today}", "#{Date.today}"], :yesterday => ["#{Date.today - 1.day}", "#{Date.today - 1.day}"], :this_week => ["#{Date.today.beginning_of_week}", "#{Date.today.end_of_week}"], :last_week => ["#{(Date.today - 1.week).beginning_of_week}", "#{(Date.today - 1.week).end_of_week}"], :this_month => ["#{Date.today.beginning_of_month}", "#{Date.today.end_of_month}"], :last_month => ["#{(Date.today - 1.month).beginning_of_month}", "#{(Date.today - 1.month).end_of_month}"], :this_year => ["#{Date.today.beginning_of_year}", "#{Date.today.end_of_year}"], :last_year => ["#{(Date.today - 1.year).beginning_of_year}", "#{(Date.today - 1.year).end_of_year}"] } end end |
#default_date_filter ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/models/carnival/field.rb', line 28 def default_date_filter if @params[:date_filter_default] @params[:date_filter_default] else date_filter_periods.first.first end end |
#default_sort_direction ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/models/carnival/field.rb', line 55 def default_sort_direction if default_sortable? if @params[:sortable][:direction] return @params[:sortable][:direction] end end return :asc end |
#default_sortable? ⇒ Boolean
51 52 53 |
# File 'app/models/carnival/field.rb', line 51 def default_sortable? @params[:sortable] && @params[:sortable].class == Hash && @params[:sortable][:default] == true end |
#nested_form? ⇒ Boolean
64 65 66 |
# File 'app/models/carnival/field.rb', line 64 def nested_form? @params[:nested_form] end |
#nested_form_allow_destroy? ⇒ Boolean
68 69 70 |
# File 'app/models/carnival/field.rb', line 68 def nested_form_allow_destroy? @params[:nested_form_allow_destroy] end |
#searchable? ⇒ Boolean
76 77 78 |
# File 'app/models/carnival/field.rb', line 76 def searchable? @params[:searchable] end |
#sortable? ⇒ Boolean
72 73 74 |
# File 'app/models/carnival/field.rb', line 72 def sortable? @params[:sortable] end |
#valid_for_action?(action) ⇒ Boolean
89 90 91 |
# File 'app/models/carnival/field.rb', line 89 def valid_for_action?(action) @params[:actions].include?(action) end |
#widget ⇒ Object
97 98 99 |
# File 'app/models/carnival/field.rb', line 97 def @params[:widget].present? ? @params[:widget] : :input end |