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
- #actions ⇒ Object
- #advanced_search_operator ⇒ Object
- #advanced_searchable? ⇒ Boolean
- #as ⇒ Object
- #association_field_name ⇒ Object
- #association_name ⇒ Object
- #css_class ⇒ Object
- #date_filter? ⇒ Boolean
- #date_filter_periods ⇒ Object
- #default_date_filter ⇒ Object
- #default_sort_direction ⇒ Object
- #default_sortable? ⇒ Boolean
- #depends_on ⇒ Object
-
#initialize(name, params = {}) ⇒ Field
constructor
A new instance of Field.
- #name_for_translation ⇒ Object
- #nested_form? ⇒ Boolean
- #nested_form_allow_destroy? ⇒ Boolean
- #nested_form_modes?(mode) ⇒ Boolean
- #nested_form_scope ⇒ Object
- #searchable? ⇒ Boolean
- #show_as_list ⇒ Object
- #show_view ⇒ Object
- #sort_name ⇒ Object
- #sortable? ⇒ Boolean
- #sortable_params ⇒ Object
-
#specified_association? ⇒ Boolean
def name @name.to_s end.
- #valid_for_action?(action) ⇒ Boolean
- #widget ⇒ Object
Constructor Details
#initialize(name, params = {}) ⇒ Field
Returns a new instance of Field.
5 6 7 8 9 10 |
# File 'app/models/carnival/field.rb', line 5 def initialize(name, params={}) @params = params @name = name set_position_by_params validate end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
3 4 5 |
# File 'app/models/carnival/field.rb', line 3 def column @column end |
#line ⇒ Object
Returns the value of attribute line.
3 4 5 |
# File 'app/models/carnival/field.rb', line 3 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'app/models/carnival/field.rb', line 3 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'app/models/carnival/field.rb', line 3 def params @params end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'app/models/carnival/field.rb', line 3 def size @size end |
Instance Method Details
#actions ⇒ Object
139 140 141 |
# File 'app/models/carnival/field.rb', line 139 def actions @params[:actions] end |
#advanced_search_operator ⇒ Object
134 135 136 137 |
# File 'app/models/carnival/field.rb', line 134 def advanced_search_operator return @params[:advanced_search][:operator] if advanced_searchable? and @params[:advanced_search][:operator].present? :like end |
#advanced_searchable? ⇒ Boolean
126 127 128 |
# File 'app/models/carnival/field.rb', line 126 def advanced_searchable? @params[:advanced_search] end |
#as ⇒ Object
148 149 150 |
# File 'app/models/carnival/field.rb', line 148 def as @params[:as] end |
#association_field_name ⇒ Object
24 25 26 27 28 |
# File 'app/models/carnival/field.rb', line 24 def association_field_name if specified_association? get_association_and_field[:field] end end |
#association_name ⇒ Object
20 21 22 |
# File 'app/models/carnival/field.rb', line 20 def association_name get_association_and_field[:association] || @name end |
#css_class ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/carnival/field.rb', line 34 def css_class if @params[:css_class] return @params[:css_class] else return "" end end |
#date_filter? ⇒ Boolean
42 43 44 |
# File 'app/models/carnival/field.rb', line 42 def date_filter? @params[:date_filter] end |
#date_filter_periods ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/carnival/field.rb', line 54 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
46 47 48 49 50 51 52 |
# File 'app/models/carnival/field.rb', line 46 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
74 75 76 77 78 79 80 81 |
# File 'app/models/carnival/field.rb', line 74 def default_sort_direction if default_sortable? if @params[:sortable][:direction] return @params[:sortable][:direction] end end return :asc end |
#default_sortable? ⇒ Boolean
70 71 72 |
# File 'app/models/carnival/field.rb', line 70 def default_sortable? @params[:sortable] && @params[:sortable].class == Hash && @params[:sortable][:default] == true end |
#depends_on ⇒ Object
83 84 85 |
# File 'app/models/carnival/field.rb', line 83 def depends_on @params[:depends_on] end |
#name_for_translation ⇒ Object
30 31 32 |
# File 'app/models/carnival/field.rb', line 30 def name_for_translation @name.to_s.gsub('.', '_') end |
#nested_form? ⇒ Boolean
87 88 89 |
# File 'app/models/carnival/field.rb', line 87 def nested_form? @params[:nested_form] end |
#nested_form_allow_destroy? ⇒ Boolean
91 92 93 |
# File 'app/models/carnival/field.rb', line 91 def nested_form_allow_destroy? @params[:nested_form_allow_destroy] end |
#nested_form_modes?(mode) ⇒ Boolean
95 96 97 98 99 100 |
# File 'app/models/carnival/field.rb', line 95 def nested_form_modes? (mode) associate = get_associate_nested_form_mode return true if associate.present? && mode == :associate return @params[:nested_form_modes].include?(mode) unless @params[:nested_form_modes].nil? return false end |
#nested_form_scope ⇒ Object
102 103 104 105 106 107 |
# File 'app/models/carnival/field.rb', line 102 def nested_form_scope return nil if !nested_form_modes? :associate associate_mode = get_associate_nested_form_mode return nil if associate_mode.is_a? Symbol return associate_mode[:scope] if associate_mode[:scope].present? end |
#searchable? ⇒ Boolean
122 123 124 |
# File 'app/models/carnival/field.rb', line 122 def searchable? @params[:searchable] end |
#show_as_list ⇒ Object
130 131 132 |
# File 'app/models/carnival/field.rb', line 130 def show_as_list @params[:show_as_list] end |
#show_view ⇒ Object
156 157 158 |
# File 'app/models/carnival/field.rb', line 156 def show_view @params[:show_view] end |
#sort_name ⇒ Object
160 161 162 163 |
# File 'app/models/carnival/field.rb', line 160 def sort_name return @params[:related_to].to_s if @params[:related_to].present? @name.to_s end |
#sortable? ⇒ Boolean
109 110 111 112 113 114 |
# File 'app/models/carnival/field.rb', line 109 def sortable? return true if @params[:sortable].nil? return true if @params[:sortable] return true if @params[:sortable].class == Hash return false end |
#sortable_params ⇒ Object
116 117 118 119 120 |
# File 'app/models/carnival/field.rb', line 116 def sortable_params return false if !sortable? return @params[:sortable].to_json if @params[:sortable].class == Hash return true end |
#specified_association? ⇒ Boolean
def name
@name.to_s
end
16 17 18 |
# File 'app/models/carnival/field.rb', line 16 def specified_association? not get_association_and_field[:association].nil? end |
#valid_for_action?(action) ⇒ Boolean
143 144 145 146 |
# File 'app/models/carnival/field.rb', line 143 def valid_for_action?(action) return false if @params[:actions].nil? @params[:actions].include?(action) end |
#widget ⇒ Object
152 153 154 |
# File 'app/models/carnival/field.rb', line 152 def @params[:widget].present? ? @params[:widget] : :input end |