Class: Carnival::Field

Inherits:
Object
  • Object
show all
Defined in:
app/models/carnival/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#columnObject

Returns the value of attribute column.



3
4
5
# File 'app/models/carnival/field.rb', line 3

def column
  @column
end

#lineObject

Returns the value of attribute line.



3
4
5
# File 'app/models/carnival/field.rb', line 3

def line
  @line
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/carnival/field.rb', line 3

def name
  @name
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'app/models/carnival/field.rb', line 3

def params
  @params
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'app/models/carnival/field.rb', line 3

def size
  @size
end

Instance Method Details

#actionsObject



139
140
141
# File 'app/models/carnival/field.rb', line 139

def actions
  @params[:actions]
end

#advanced_search_operatorObject



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

Returns:

  • (Boolean)


126
127
128
# File 'app/models/carnival/field.rb', line 126

def advanced_searchable?
  @params[:advanced_search]
end

#asObject



148
149
150
# File 'app/models/carnival/field.rb', line 148

def as
  @params[:as]
end

#association_field_nameObject



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_nameObject



20
21
22
# File 'app/models/carnival/field.rb', line 20

def association_name
  get_association_and_field[:association] || @name
end

#css_classObject



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

Returns:

  • (Boolean)


42
43
44
# File 'app/models/carnival/field.rb', line 42

def date_filter?
  @params[:date_filter]
end

#date_filter_periodsObject



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_filterObject



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_directionObject



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

Returns:

  • (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_onObject



83
84
85
# File 'app/models/carnival/field.rb', line 83

def depends_on
  @params[:depends_on]
end

#name_for_translationObject



30
31
32
# File 'app/models/carnival/field.rb', line 30

def name_for_translation
  @name.to_s.gsub('.', '_')
end

#nested_form?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/carnival/field.rb', line 87

def nested_form?
  @params[:nested_form]
end

#nested_form_allow_destroy?Boolean

Returns:

  • (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

Returns:

  • (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_scopeObject



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

Returns:

  • (Boolean)


122
123
124
# File 'app/models/carnival/field.rb', line 122

def searchable?
  @params[:searchable]
end

#show_as_listObject



130
131
132
# File 'app/models/carnival/field.rb', line 130

def show_as_list
  @params[:show_as_list]
end

#show_viewObject



156
157
158
# File 'app/models/carnival/field.rb', line 156

def show_view
  @params[:show_view]
end

#sort_nameObject



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

Returns:

  • (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_paramsObject



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

Returns:

  • (Boolean)


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

Returns:

  • (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

#widgetObject



152
153
154
# File 'app/models/carnival/field.rb', line 152

def widget
  @params[:widget].present? ? @params[:widget] : :input
end