class ColumnEntry include Mongoid::Document include Mongoid::Timestamps include Admin::UniversalTablesHelper include ActionView::Helpers::NumberHelper field :text, :localize => true field :content, :localize => true field :date, type: DateTime field :period_from, type: DateTime field :period_to, type: DateTime field :number, type: Integer mount_uploader :image, ImageUploader has_many :column_entry_files, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :column_entry_files, :allow_destroy => true after_save :save_column_entry_files belongs_to :table_entry, index: true belongs_to :table_column, index: true I18n.available_locales.each do |locale| index({text: 1}, { collation: {locale: locale.to_s}, unique: false, background: true }) index({content: 1}, { collation: {locale: locale.to_s}, unique: false, background: true }) end def type self.table_column.type end def save_column_entry_files return if @skip_callback self.column_entry_files.each do |t| if t.should_destroy t.destroy end end end def have_data(locale) flag = nil case self.type when "text" flag = self.text_translations[locale].present? when "integer" flag = true when "editor" flag = self.content_translations[locale].present? when "date" flag = self.date.present? when "period" flag = self.period_from.present? || self.period_to.present? when "image" flag = self.image.present? when "file" flag = false self.column_entry_files.each do |entry_file| next unless entry_file.choose_lang_display(locale) && entry_file.file.present? flag = true end else flag = true end flag end def get_frontend_text(column) text = "" case self.type when "text" text = self.text when "integer" text = self.number when "editor" text = self.content when "date" text = format_date(self.date, column.date_format) when "period" text = format_date(self.period_from, column.date_format) + " ~ " + format_date(self.period_to, column.date_format) text = "" if text.starts_with?(" ~") when "image" text = "" when "file" locale = I18n.locale.to_s text = "