parent
541aa5831e
commit
11a371cbb9
|
@ -33,6 +33,7 @@ class OrbitBackendController< ApplicationController
|
||||||
|
|
||||||
def get_sorted_and_filtered(object_class, query=nil)
|
def get_sorted_and_filtered(object_class, query=nil)
|
||||||
objects = get_objects(object_class, query)
|
objects = get_objects(object_class, query)
|
||||||
|
object_class = object_class.classify.constantize
|
||||||
if !params[:sort].blank?
|
if !params[:sort].blank?
|
||||||
options = params[:sort_options]
|
options = params[:sort_options]
|
||||||
options = [options] if !options.class.eql?(Array)
|
options = [options] if !options.class.eql?(Array)
|
||||||
|
@ -87,7 +88,7 @@ class OrbitBackendController< ApplicationController
|
||||||
end if value.size > 0
|
end if value.size > 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Kaminari.paginate_array(objects).page(params[:page]).per(10)
|
Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_string_value_from_object(object)
|
def get_string_value_from_object(object)
|
||||||
|
@ -159,13 +160,16 @@ class OrbitBackendController< ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_objects(object_class, query=nil)
|
def get_objects(object_class, query=nil)
|
||||||
|
|
||||||
object_class = object_class.classify.constantize
|
object_class = object_class.classify.constantize
|
||||||
if query
|
if query
|
||||||
objects = object_class.all.where(query).entries
|
objects = object_class.all.where(query)
|
||||||
else
|
else
|
||||||
objects = object_class.all.entries
|
objects = object_class.all
|
||||||
end
|
end
|
||||||
|
objects
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_authorized_objects(objects)
|
||||||
if(!is_admin? || !is_manager?)
|
if(!is_admin? || !is_manager?)
|
||||||
objects.delete_if{ |object|
|
objects.delete_if{ |object|
|
||||||
if object.is_pending == true
|
if object.is_pending == true
|
||||||
|
|
|
@ -10,16 +10,18 @@ class Item
|
||||||
field :is_published, :type => Boolean, :default => false
|
field :is_published, :type => Boolean, :default => false
|
||||||
field :enabled_for, :type => Array, :default => nil
|
field :enabled_for, :type => Array, :default => nil
|
||||||
field :menu_enabled_for, :type => Array, :default => nil
|
field :menu_enabled_for, :type => Array, :default => nil
|
||||||
|
|
||||||
|
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
||||||
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
|
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
|
||||||
validates_uniqueness_of :name, :scope => :parent_id
|
validates_uniqueness_of :name, :scope => :parent_id
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
|
|
||||||
validates_associated :parent, :children
|
validates_associated :parent, :children
|
||||||
|
|
||||||
|
before_destroy :destroy_children
|
||||||
after_rearrange :rebuild_path
|
after_rearrange :rebuild_path
|
||||||
|
|
||||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
|
||||||
|
|
||||||
def self.find_by_name(item_name)
|
def self.find_by_name(item_name)
|
||||||
Item.first(:conditions => { :name => item_name, :is_published => true })
|
Item.first(:conditions => { :name => item_name, :is_published => true })
|
||||||
|
|
Loading…
Reference in New Issue