user new interface 70%
This commit is contained in:
1 parent
1aacf5e2ce
commit
9f825de288
20 files changed
+589
-52
No files matched your search
@@ -2,9 +2,11 @@ class AttributeField
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
include AttributeFieldHelper
|
||||
|
||||
field :key
|
||||
field :markup #[select,text_field,email,date,addr]
|
||||
field :markup_value ,:type => Hash
|
||||
field :locale, :type => Boolean, :default => true
|
||||
field :list_options, :type => Array
|
||||
field :built_in, :type => Boolean, :default => false
|
||||
@@ -46,7 +48,7 @@ class AttributeField
|
||||
end
|
||||
|
||||
def title=(var)
|
||||
binding.pry
|
||||
# binding.pry
|
||||
if locale
|
||||
self.locale_title = var
|
||||
else
|
||||
|
||||
@@ -2,14 +2,52 @@ class AttributeValue
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
field :key
|
||||
|
||||
belongs_to :attribute_field
|
||||
belongs_to :user
|
||||
|
||||
def method_missing(field)
|
||||
self[field]
|
||||
|
||||
before_save :check_key
|
||||
|
||||
NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
|
||||
|
||||
def check_key
|
||||
self.key = attribute_field.key
|
||||
end
|
||||
|
||||
def method_missing(*field)
|
||||
if field.size < 1
|
||||
self[field[0]]
|
||||
else
|
||||
self[(field[0].to_s.delete "=")] = field[1]
|
||||
end
|
||||
end
|
||||
|
||||
def get_value_by_locale(locale)
|
||||
case self.attribute_field.markup
|
||||
when "text_field"
|
||||
self.attribute_field.locale ? self[locale] : self[:value]
|
||||
when "select"
|
||||
self.attribute_field.markup_value[self[:value]][locale.to_s] || NoData
|
||||
when "email"
|
||||
self[:value]
|
||||
when "date"
|
||||
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i)
|
||||
when "addr"
|
||||
self[:value]
|
||||
else
|
||||
self.attribute_field.locale ? self[locale] : self[:value]
|
||||
end
|
||||
end
|
||||
|
||||
def get_values
|
||||
if self.attribute_field.locale && !(NO_MULTI_TAG.include? self.attribute_field.markup)
|
||||
return Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
|
||||
else
|
||||
return self[:value]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
+22
-17
@@ -43,28 +43,33 @@ class User
|
||||
self.status_record.store(sub_role_id,status_id)
|
||||
end
|
||||
|
||||
def get_status(*params)
|
||||
param = params[0]
|
||||
case param.class.to_s
|
||||
when 'String'
|
||||
sr = ::SubRole.find sub_role_id
|
||||
when 'Hash'
|
||||
sr = ::SubRole.first({conditions:{key: param[:key]}})
|
||||
end
|
||||
if self.sub_roles.include?(sr)
|
||||
return ::Status.find(status_record.fetch(sr.id.to_s))
|
||||
else
|
||||
nil
|
||||
# def get_status(*params)
|
||||
# param = params[0]
|
||||
# case param.class.to_s
|
||||
# when 'String'
|
||||
# sr = ::SubRole.find sub_role_id
|
||||
# when 'Hash'
|
||||
# sr = ::SubRole.first({conditions:{key: param[:key]}})
|
||||
# end
|
||||
# if self.sub_roles.include?(sr)
|
||||
# return ::Status.find(status_record.fetch(sr.id.to_s))
|
||||
# else
|
||||
# nil
|
||||
# end
|
||||
# end
|
||||
def new_attribute_values=(fields)
|
||||
fields.each do |key,field|
|
||||
self.attribute_values.build(field)
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_by_status_and_sub_role_key(sub_role_key,status_key)
|
||||
def self.find_by_status_and_sub_role_key(sub_role_key,status_key) #Query for users by using specific sub_role and status key
|
||||
sr = ::SubRole.first({conditions: { key: sub_role_key }})
|
||||
status = ::Status.first({conditions:{role_id: sr.role.id,key: status_key}})
|
||||
find_by_status(sr.id,status.id)
|
||||
end
|
||||
|
||||
def self.find_by_status(sub_role_id,status_id)
|
||||
def self.find_by_status(sub_role_id,status_id) #Query for users by using specific sub_role and status key buy within ID
|
||||
User.where("status_record.#{sub_role_id}" => status_id)
|
||||
end
|
||||
|
||||
@@ -112,7 +117,7 @@ class User
|
||||
def get_value_from_field_id(field_id)
|
||||
values = get_attribute_values
|
||||
value = values.detect {|value| value.attribute_field_id == field_id} rescue nil
|
||||
value ? value : self.attribute_values.build
|
||||
value ? value : nil
|
||||
end
|
||||
|
||||
def self.from_id(id)
|
||||
@@ -128,7 +133,7 @@ class User
|
||||
def check_status_record
|
||||
roles = sub_roles.collect{|t| t.role}.uniq #get all role from sub_roles
|
||||
sub_roles_ary = sub_roles.collect{|t| t.id.to_s}
|
||||
self.status_record = status_record.keep_if{|sub_role_id, status_id|
|
||||
self.status_record = status_record.keep_if{|sub_role_id, status_id|
|
||||
includeing = sub_roles_ary.include?(sub_role_id)
|
||||
valide = false
|
||||
if includeing
|
||||
@@ -137,7 +142,7 @@ class User
|
||||
end
|
||||
|
||||
(includeing and valide)
|
||||
}
|
||||
} rescue {}
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user