Module: Faalis::Generators::Concerns::Fieldset

Included in:
DashboardScaffold
Defined in:
lib/faalis/generators/concerns/fieldset.rb

Overview

Allow to categorize fields in some fieldset

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) fieldset? (private)

Returns fields which is needed to be in bulk edit

Returns:

  • (Boolean)


12
13
14
# File 'lib/faalis/generators/concerns/fieldset.rb', line 12

def fieldset?
  !fields_with_attribute('fieldset').empty?
end

- (Object) fieldset_less_fields (private)



16
17
18
19
# File 'lib/faalis/generators/concerns/fieldset.rb', line 16

def fieldset_less_fields
  fields = Set.new(raw_fields_data) - Set.new(fields_with_attribute('fieldset'))
  fields.to_a
end

- (Object) fieldsets (private)

TODO: fix this method to allow usage on tabbed views too Return fields categorized by fieldsets. Only for views without tabs



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/faalis/generators/concerns/fieldset.rb', line 24

def fieldsets
  fieldsets = {resource.underscore.pluralize.humanize => fieldset_less_fields}
  fields = fields_with_attribute('fieldset')
  fields.each do |f|
    if fieldsets.include? f['fieldset']
      fieldsets[f['fieldset']] << f
    else
      fieldsets[f['fieldset']] = [f]
    end
  end

  # Convert hashes to proper field structure to use in templates
  fieldsets.each do |fieldset_name, fieldset_fields|
    if fieldset_fields[0].is_a? Hash
      fieldsets[fieldset_name] = fields(fieldset_fields)
    end
  end

  fieldsets
end