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
- #hidden?(record, controller) ⇒ Boolean
-
#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
- #presenter_class ⇒ Object
- #searchable? ⇒ Boolean
- #show_as_list ⇒ Object
- #show_view ⇒ Object
- #sort_name ⇒ Object
- #sortable? ⇒ Boolean
- #sortable_params ⇒ Object
- #specified_association? ⇒ Boolean
- #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
145 146 147 |
# File 'app/models/carnival/field.rb', line 145 def actions @params[:actions] end |
#advanced_search_operator ⇒ Object
140 141 142 143 |
# File 'app/models/carnival/field.rb', line 140 def advanced_search_operator return @params[:advanced_search][:operator] if advanced_searchable? and @params[:advanced_search][:operator].present? :like end |
#advanced_searchable? ⇒ Boolean
132 133 134 |
# File 'app/models/carnival/field.rb', line 132 def advanced_searchable? @params[:advanced_search] end |
#as ⇒ Object
154 155 156 |
# File 'app/models/carnival/field.rb', line 154 def as @params[:as] end |
#association_field_name ⇒ Object
30 31 32 33 34 |
# File 'app/models/carnival/field.rb', line 30 def association_field_name if specified_association? get_association_and_field[:field] end end |
#association_name ⇒ Object
26 27 28 |
# File 'app/models/carnival/field.rb', line 26 def association_name get_association_and_field[:association] || @name end |
#css_class ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/models/carnival/field.rb', line 40 def css_class if @params[:css_class] return @params[:css_class] else return "" end end |
#date_filter? ⇒ Boolean
48 49 50 |
# File 'app/models/carnival/field.rb', line 48 def date_filter? @params[:date_filter] end |
#date_filter_periods ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/carnival/field.rb', line 60 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
52 53 54 55 56 57 58 |
# File 'app/models/carnival/field.rb', line 52 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
80 81 82 83 84 85 86 87 |
# File 'app/models/carnival/field.rb', line 80 def default_sort_direction if default_sortable? if @params[:sortable][:direction] return @params[:sortable][:direction] end end return :asc end |
#default_sortable? ⇒ Boolean
76 77 78 |
# File 'app/models/carnival/field.rb', line 76 def default_sortable? @params[:sortable] && @params[:sortable].class == Hash && @params[:sortable][:default] == true end |
#depends_on ⇒ Object
89 90 91 |
# File 'app/models/carnival/field.rb', line 89 def depends_on @params[:depends_on] end |
#hidden?(record, controller) ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'app/models/carnival/field.rb', line 12 def hidden?(record, controller) if @params.has_key?(:hide_if) block = @params[:hide_if] controller.instance_variable_set(:@record, record) controller.instance_eval(&block) else false end end |
#name_for_translation ⇒ Object
36 37 38 |
# File 'app/models/carnival/field.rb', line 36 def name_for_translation @name.to_s.gsub('.', '_') end |
#nested_form? ⇒ Boolean
93 94 95 |
# File 'app/models/carnival/field.rb', line 93 def nested_form? @params[:nested_form] end |
#nested_form_allow_destroy? ⇒ Boolean
97 98 99 |
# File 'app/models/carnival/field.rb', line 97 def nested_form_allow_destroy? @params[:nested_form_allow_destroy] end |
#nested_form_modes?(mode) ⇒ Boolean
101 102 103 104 105 106 |
# File 'app/models/carnival/field.rb', line 101 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
108 109 110 111 112 113 |
# File 'app/models/carnival/field.rb', line 108 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 |
#presenter_class ⇒ Object
170 171 172 |
# File 'app/models/carnival/field.rb', line 170 def presenter_class @params[:presenter] end |
#searchable? ⇒ Boolean
128 129 130 |
# File 'app/models/carnival/field.rb', line 128 def searchable? @params[:searchable] end |
#show_as_list ⇒ Object
136 137 138 |
# File 'app/models/carnival/field.rb', line 136 def show_as_list @params[:show_as_list] end |
#show_view ⇒ Object
162 163 164 |
# File 'app/models/carnival/field.rb', line 162 def show_view @params[:show_view] end |
#sort_name ⇒ Object
166 167 168 |
# File 'app/models/carnival/field.rb', line 166 def sort_name @name.to_s end |
#sortable? ⇒ Boolean
115 116 117 118 119 120 |
# File 'app/models/carnival/field.rb', line 115 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
122 123 124 125 126 |
# File 'app/models/carnival/field.rb', line 122 def sortable_params return false if !sortable? return @params[:sortable].to_json if @params[:sortable].class == Hash return true end |
#specified_association? ⇒ Boolean
22 23 24 |
# File 'app/models/carnival/field.rb', line 22 def specified_association? not get_association_and_field[:association].nil? end |
#valid_for_action?(action) ⇒ Boolean
149 150 151 152 |
# File 'app/models/carnival/field.rb', line 149 def valid_for_action?(action) return false if @params[:actions].nil? @params[:actions].include?(action) end |
#widget ⇒ Object
158 159 160 |
# File 'app/models/carnival/field.rb', line 158 def @params[:widget].present? ? @params[:widget] : :input end |