Class: KirguduBase::Models::DataFilter

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/kirgudu_base/models/data_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ DataFilter

Returns a new instance of DataFilter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 7

def initialize(name, options = {})
  options ||= {}


  self.name = name # **  SETTING NAME  **
  self.css_span = options[:span].to_s if options[:span] # **  SETTING SPAN  **
  self.css_class = options[:class].to_s if options[:class] # **  SETTING CLASS  **
  self.input_type = options[:input_type] || :text_edit # **  SETTING INPUT TYPE  **
  self.filter_name = options[:filter_name] # **  SETTING INPUT TYPE  **
  self.placeholder = options[:placeholder] # **  SETTING PLACEHOLDER  **
  self.label = options[:label] # **  SETTING LABEL  **
  self.parent = options[:parent] # **  SETTING PARENT  **
  self.source = options[:source] # **  SETTING SOURCE  **
  self.source_url = options[:source_url] # **  SETTING SOURCE URL  **


  # ******************* SETTING MASS ASSIGNMENT *****************************
  if options[:mass_assignment].is_a?(Array)
    options[:mass_assignment].each do |ma_val|
      unless [:create, :update, :in_place].include?(ma_val)
        raise "FORM PROPERTY ERROR\r\nForm Property: \"#{name}\".\r\nValue \"#{ma_val}\" is not allowed for array of values of \"mass_assignment\" option"
      end
      if options[:mass_assignment].include?(ma_val)
        raise "FORM PROPERTY ERROR\r\nForm Property: \"#{name}\".\r\nDuplicate value \"#{ma_val}\" in array of values of \"mass_assignment\" option"
      end
      self.mass_assignment.push(ma_val)
    end
  else
    if options[:mass_assignment] == :all
      [:create, :update, :in_place].each do |ma|
        self.mass_assignment.push(ma)
      end
    elsif options[:mass_assignment] == :none

    elsif [:create, :update, :in_place].include?(options[:mass_assignment])
      self.mass_assignment.push(options[:mass_assignment])
    else
      if options[:mass_assignment]
        raise "FORM PROPERTY ERROR\r\nForm Property \"#{name}\".\r\nValue \"#{options[:mass_assignment]}\" is not allowed for \"mass_assignment\" option"
      else
        options[:mass_assignment] = [:create, :update, :in_place]
      end
    end
  end

  #validateing property by input_type
  case self.input_type
    when :chosen_select
      validate_chosen_select
    when :autocomplete_with_id
      validate_autocomplete_with_id
    when :switcher

    when :date_picker
    when :time_picker
    when :image_selector
    when :check_box
    when :radio_button
    when :link
    when :elastic_text_area
    when :text_area
    when :text_edit

    else
      raise "Data Filter: '#{self.name}'\r\nINPUT TYPE #{self.input_type} is not supported at the moment"
  end
  validate_attribute_class # validating class attribute
  validate_attribute_span # validating span attribute
end

Instance Attribute Details

#css_classObject

Returns the value of attribute css_class.



81
82
83
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 81

def css_class
  @css_class
end

#css_spanObject

Returns the value of attribute css_span.



80
81
82
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 80

def css_span
  @css_span
end

#filter_nameObject

Returns the value of attribute filter_name.



79
80
81
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 79

def filter_name
  @filter_name
end

#input_typeObject

Returns the value of attribute input_type.



82
83
84
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 82

def input_type
  @input_type
end

#labelObject

Returns the value of attribute label.



83
84
85
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 83

def label
  @label
end

#nameObject

Returns the value of attribute name.



78
79
80
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 78

def name
  @name
end

#on_changeObject

Returns the value of attribute on_change.



88
89
90
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 88

def on_change
  @on_change
end

#parentObject

Returns the value of attribute parent.



85
86
87
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 85

def parent
  @parent
end

#placeholderObject

Returns the value of attribute placeholder.



84
85
86
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 84

def placeholder
  @placeholder
end

#sourceObject

Returns the value of attribute source.



86
87
88
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 86

def source
  @source
end

#source_urlObject

Returns the value of attribute source_url.



87
88
89
# File 'app/helpers/kirgudu_base/models/data_filter.rb', line 87

def source_url
  @source_url
end