Module: CustomField

Defined in:
backend/app/model/reports/custom_field.rb

Defined Under Namespace

Modules: Mixin

Class Method Summary collapse

Class Method Details

.check_valid_record_type(record_type) ⇒ Object



32
33
34
35
# File 'backend/app/model/reports/custom_field.rb', line 32

def self.check_valid_record_type(record_type)
  data = @@registered_fields[record_type]
  raise "Invalid record type: #{record_type}" unless data
end

.fields_for(record_type) ⇒ Object



37
38
39
40
41
# File 'backend/app/model/reports/custom_field.rb', line 37

def self.fields_for(record_type)
  record_fields = @@registered_fields[record_type][:fields]
  global_fields = @@registered_fields['global'][:fields]
  record_fields + global_fields
end

.get_field_by_name(record_type, field_name) ⇒ Object



51
52
53
54
55
56
57
58
# File 'backend/app/model/reports/custom_field.rb', line 51

def self.get_field_by_name(record_type, field_name)
  fields_for(record_type).each do |field|
    if field[:name] == field_name.to_s
      return field
    end
  end
  nil
end

.register_field(record_type, field_name, data_type, options) ⇒ Object



6
7
8
9
10
11
12
# File 'backend/app/model/reports/custom_field.rb', line 6

def self.register_field(record_type, field_name, data_type, options)
  @@registered_fields[record_type] ||= {:fields => [], :subreports => []}
  info = options
  info[:name] = field_name
  info[:data_type] = data_type.to_s
  @@registered_fields[record_type][:fields].push(info)
end

.register_subreport(subreport, field_name, record_types, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'backend/app/model/reports/custom_field.rb', line 14

def self.register_subreport(subreport, field_name, record_types, options)
  if @@subreport_classes.has_key?(subreport.code)
    Log.warn("Subreport with code '#{subreport.code}' already registered")
  end
  @@subreport_classes[subreport.code] = subreport
  record_types.each do |record_type|
    @@registered_fields[record_type] ||= {:fields => [], :subreports => []}
    info = options
    info[:name] = field_name
    info[:code] = subreport.code
    @@registered_fields[record_type][:subreports].push(info)
  end
end

.registered_fieldsObject



28
29
30
# File 'backend/app/model/reports/custom_field.rb', line 28

def self.registered_fields
  @@registered_fields
end

.subreport_class(code) ⇒ Object



47
48
49
# File 'backend/app/model/reports/custom_field.rb', line 47

def self.subreport_class(code)
  @@subreport_classes[code]
end

.subreports_for(record_type) ⇒ Object



43
44
45
# File 'backend/app/model/reports/custom_field.rb', line 43

def self.subreports_for(record_type)
  @@registered_fields[record_type][:subreports]
end