Class: DcBigTable

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_big_table.rb

Overview

Mongoid::Document model for dc_big_table collection.

Big table is meant to be a common space for defining default choices for select fields on forms. Documents are organized as key-value pair with the difference that values for the key can be defined for every site and can also be localized.

Usage (as used in forms):

In the example administrator may help user by providing values that can be used on DcAd document position field by defining them in ads-position key of big table. Example is from dc_ads.yml form.

10:
  name: position
  type: text_with_select
  eval: dc_big_table 'ads-positions'
  html:
    size: 20

dc_big_table collection embeds many DcBigTableValue documents.

Class Method Summary collapse

Class Method Details

.choices4(key, site, locale = nil) ⇒ Object

Will return possible choices for specified key prepared for usega in select input field.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/dc_big_table.rb', line 68

def self.choices4(key, site, locale=nil)
  a = []
  r = find(key: key, site: site)
  if r
    r.dc_big_table_values.each do |v| 
      desc = v.description
      if locale
        d = v.find('dc_big_table_values.locale' => locale)
        desc = d.value if d
      end             
      a << [v.value, desc]
    end
  end
# Error if empty
  a = [[I18n.t('drgcms.error'),I18n.t('drgcms.error')]] if a.size == 0
  a
end