app/controllers/anoubis/data/convert.rb
##
# Convert value from database to table format for 'listbox' type
# @param key [Symbol] field's identifier in {Anoubis::Etc::Data#fields self.etc.data.fields} structure
# @param value [String] value from database
Convert value from database to table format for 'listbox' type
Convert value from database to table format for ' listbox ' type
def convert_db_to_view_value_listbox(key, value)
        field = self.etc.data.fields[key]
        new_value = ''
        if field.options
          if field.format == 'single'
            new_value = field.options.list[value.to_s.to_sym] if field.options.list
          else
            new_value = []
            if value
              if field.options.list
                value.each do |key|
                  new_value.push field.options.list[key.to_s.to_sym]
                end
              end
            end
          end
        end
        case self.etc.action
        when 'index', 'show', 'export'
          if field.format == 'single'
            return { key => new_value, format('%s_raw', key).to_sym => value }
          else
            return { key => new_value.join(', '), format('%s_raw', key).to_sym => new_value }
          end
        when 'new', 'edit'
          if field.format == 'single'
            return { key => value.to_s, format('%s_view', key).to_sym => new_value }
          else
            return { key => value, format('%s_view', key).to_sym => new_value.join(', ') }
          end
        else
          if field.format == 'single'
            return { key => value.to_s, format('%s_view', key).to_sym => new_value }
          else
            return { key => value, format('%s_view', key).to_sym => new_value.join(', ') }
          end
        end
      end
def convert_db_to_view_value_listbox ( key , value ) field = self . etc . data . fields [ key ] new_value = '' if field . options if field . format == 'single' new_value = field . options . list [ value . to_s . to_sym ] if field . options . list else new_value = [ ] if value if field . options . list value . each do | key | new_value . push field . options . list [ key . to_s . to_sym ] end end end end end case self . etc . action when 'index' , 'show' , 'export' if field . format == 'single' return { key => new_value , format ( '%s_raw' , key ) . to_sym => value } else return { key => new_value . join ( ', ' ) , format ( '%s_raw' , key ) . to_sym => new_value } end when 'new' , 'edit' if field . format == 'single' return { key => value . to_s , format ( '%s_view' , key ) . to_sym => new_value } else return { key => value , format ( '%s_view' , key ) . to_sym => new_value . join ( ', ' ) } end else if field . format == 'single' return { key => value . to_s , format ( '%s_view' , key ) . to_sym => new_value } else return { key => value , format ( '%s_view' , key ) . to_sym => new_value . join ( ', ' ) } end end end
Convert value from database to table format for 'listbox' type
Convert value from database to table format for ' listbox ' type
key
field's identifier in {Anoubis::Etc::Data#fields self.etc.data.fields} structure
field ' s identifier in { Anoubis :: Etc :: Data#fields self . etc . data . fields } structure
value
value from database
value from database