Merge branch 'nccu_0509' of https://github.com/Rulingcom/orbit into nccu_0509

Conflicts:
	config/locales/zh_tw.yml
This commit is contained in:
Matthew K. Fu JuYuan committed 2012-05-14 12:36:09 +08:00
commit 2cd67356a5
80 files changed
+1216 -511

No files matched your search

+33 -54
View File
@@ -2,59 +2,31 @@ class Item
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Tree
include Mongoid::Tree::Ordering
field :name, :index => true
field :full_name, :index => true
field :position, :type => Integer
field :is_published, :type => Boolean, :default => false, :index => true
field :enabled_for, :type => Array, :default => nil
field :menu_enabled_for, :type => Array, :default => nil
field :name
field :path
field :is_published, :type => Boolean, :default => false
field :enabled_for, :type => Array, :default => nil
field :menu_enabled_for, :type => Array, :default => nil
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
validates_uniqueness_of :name, :scope => :parent_id
validates_presence_of :name, :full_name, :position
validates_presence_of :name
validates_associated :parent, :children
after_rearrange :rebuild_path
belongs_to :parent, :class_name => "Item"
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :children, :class_name => "Item", :as => 'parent'
before_validation :setup_default_value
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })
end
# Get an array of ancestors
def ancestors
node, nodes = self, []
nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
# Get an array of ancestor's id
def ancestor_ids
node, nodes = self, []
while !node.parent.blank? do
node = node.parent rescue nil
nodes << node.id if node
end
# nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
# Build the url from the array of ancestors
def url
urls = ancestors.map{ |a| a.name } << self.name
urls.join("/")
end
def ordered_children
self.children.asc(:position)
end
def ordered_and_visible_children
objects = ordered_children
def visible_children
objects = self.children
a = []
if objects
objects.each do |object|
@@ -63,23 +35,30 @@ class Item
end
a
end
def shift_to(new_parent, position)
unless self.parent_id.to_s.eql?(new_parent) && self.position.eql?(position.to_i)
new_parent = Item.find(new_parent)
current_position_sibling = find_by_parent_and_position(new_parent, position.to_i)
if current_position_sibling
current_position_sibling.at_bottom? ? move_below(current_position_sibling) : move_above(current_position_sibling)
elsif self.parent != new_parent
self.parent = new_parent
save!
end
end
end
protected
def setup_default_value
# Set the position value within the parent scope
if self.position.blank?
max_page = Item.where(:parent_id => self.parent_id).count
self.position = (max_page)? max_page + 1 : 1
end
# Build the full_name from the ancestors array
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
# Remove root node if not root
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
def rebuild_path
self.path = (self.ancestors_and_self - [Item.root]).collect{|x| x.name unless x.root?}.join('/')
end
def find_by_parent_and_position(parent, position)
parent.children.detect{|child| child.position == position}
end
# Enable the validation for parent_id
def validates_presence_of_parent_id?
true
+2 -4
View File
@@ -3,6 +3,8 @@ class Page < Item
field :content
field :app_frontend_url
field :theme_id, :type => BSON::ObjectId, :default => nil
field :category
field :tag
belongs_to :design
belongs_to :module_app
@@ -15,10 +17,6 @@ class Page < Item
before_save :create_parts, :set_key
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
def is_home?
self.parent ? false : true
end
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
+19 -1
View File
@@ -11,9 +11,27 @@ class PagePart
field :public_r_tag_option, :default => nil
field :widget_path
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_one :i18n_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
belongs_to :page
belongs_to :module_app
before_save :set_key
def i18n_variable
@i18n_variable ||= I18nVariable.first(:conditions => {:key => 'i18n_variable', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
protected
def set_key
title.key = 'title' if title && (title.key.blank? rescue true)
i18n_variable.key = 'i18n_variable' if i18n_variable && (i18n_variable.key.blank? rescue true)
end
end