add files
This commit is contained in:
parent
2ccc2c9b39
commit
a06aa15721
|
@ -0,0 +1,50 @@
|
|||
class AttributeModel
|
||||
|
||||
include Mongoid::Document
|
||||
|
||||
field :key
|
||||
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
||||
field :markup
|
||||
field :locale, :type => Boolean
|
||||
field :list_options, :type => Array
|
||||
|
||||
embedded_in :user_role_model, :inverse_of => :attribute_models
|
||||
validates_uniqueness_of :key
|
||||
|
||||
# Destroy the i18n_variable
|
||||
def destroy_i18n_variable
|
||||
self.i18n_variable.destroy rescue nil
|
||||
end
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr)
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.user_role_model.i18n_variable_id}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
# Convert the string list_options into an array
|
||||
def select_list_options=(var)
|
||||
self.list_options = var.gsub(' ', '').split(',')
|
||||
end
|
||||
|
||||
# Convert the array list_options into a string
|
||||
def select_list_options
|
||||
self.list_options.to_a.join(', ')
|
||||
end
|
||||
|
||||
# Check if the attribute is set to be destroyed
|
||||
def should_destroy?
|
||||
should_destroy.to_i == 1 rescue nil
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class UserInfo
|
||||
|
||||
include Mongoid::Document
|
||||
|
||||
field :key
|
||||
|
||||
embedded_in :user, :inverse_of => :user_info
|
||||
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class UserInfoModel < UserAttributeModel
|
||||
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class UserRole
|
||||
|
||||
include Mongoid::Document
|
||||
|
||||
field :key
|
||||
|
||||
embedded_in :user, :inverse_of => :user_roles
|
||||
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
class UserRoleModel < UserAttributeModel
|
||||
|
||||
# Destroy the i18n_variables
|
||||
def destroy_i18n_variables
|
||||
self.i18n_variable.destroy rescue nil
|
||||
self.attribute_models.each do |attr|
|
||||
attr.destroy_i18n_variable
|
||||
end
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr) rescue nil
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue