category disable for backend

This commit is contained in:
Matthew K. Fu JuYuan committed 2012-07-06 18:11:55 +08:00
1 parent c5fdff764e
commit 56caf4b34e
13 files changed
+190 -88

No files matched your search

+38 -5
View File
@@ -1,11 +1,44 @@
module OrbitControllerLib
module DivisionForDisable
def get_disable_object_by_user(object_class)
if is_admin? or is_manager?
object_class.admin_manager_all
else
object_class.all
# def get_disable_object_by_user(object_class)
# if is_admin? or is_manager?
# object_class.admin_manager_all
# else
# object_class.all
# end
# end
def get_categories_for_index(object_class,id = nil)
class_ref = object_class.constantize
ivar_name = "@#{object_class.to_s.underscore.pluralize}"
instance_variable_set(ivar_name, [])
if(is_manager? || is_admin?)
instance_variable_set(ivar_name, (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
elsif is_sub_manager?
instance_variable_set(ivar_name, (class_ref.all))
end
instance_variable_get(ivar_name)
end
def get_categorys(object_class,id = nil,func_authed_for_sub_manager = 'submit')
class_ref = object_class.constantize
# ivar_name = "@#{object_class.to_s.underscore.pluralize}"
ivar_name = "@#{object_class.to_s.underscore}s"
instance_variable_set(ivar_name, [])
@bulletin_categorys = []
if(is_manager? || is_admin?)
#instance_variable_set(ivar_name, (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
instance_variable_set(ivar_name, (id ? class_ref.all.find(id).to_a : class_ref.all))
elsif is_sub_manager?
instance_variable_set(ivar_name, class_ref.all.authed_for_user(current_user,func_authed_for_sub_manager))
end
if instance_variable_get(ivar_name).empty? && params[:action] != "index"
flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
redirect_to :action => :index
end
end
end
end
+12 -1
View File
@@ -5,13 +5,24 @@ module OrbitCoreLib
base.instance_eval("field :disable,type: Boolean,:default => false")
base.instance_eval("scope :all,where(disable: false)")
base.instance_eval("scope :admin_manager_all,find(:all)")
base.define_singleton_method :find do |*args|
if args ==[:all]
unscoped
else
unscoped.find(args)
res = unscoped.find(args)
res.count == 1 ? res[0] : res
end
end
base.define_singleton_method :first do |*args|
all.first
end
base.define_singleton_method :last do |*args|
all.last
end
end
end
module ObjectAuthable