Merge branch 'nccu_master' into demo_site

Conflicts:
	Gemfile
	app/assets/javascripts/tinymce_orbit.js.erb
	app/assets/stylesheets/style.css.erb
	app/controllers/admin/assets_controller.rb
	app/controllers/admin/module_apps_new_interface_controller.rb
	app/controllers/admin/page_parts_controller.rb
	app/jobs/sync_db.rb
	app/models/page.rb
	app/models/page_part.rb
	app/models/user/user.rb
	app/uploaders/image_uploader.rb
	app/views/admin/assets/create.js.erb
	app/views/admin/module_apps/reload_frontend_pages.js.erb
	app/views/layouts/_orbit_bar.html.erb
	app/views/layouts/_side_bar.html.erb
	app/views/layouts/_users_checkbox_ary.html.erb
	app/views/shared/_privilege_user.html.erb
	config/mongoid.yml
	lib/parsers/parser_common.rb
	vendor/built_in_modules/announcement/announcement.json
	vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb
	vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form_bulletin_link.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb
This commit is contained in:
chris committed 2012-08-22 18:07:49 +08:00
commit 7d5531bf01
432 files changed
+8773 -17035

No files matched your search

+2
View File
@@ -21,6 +21,8 @@ attr_writer :transition_sec
APP_NAME = 'ad_banners'
ObjectAuthTitlesOptions = %W{edit}
def pp_object
title
end
+13 -2
View File
@@ -4,8 +4,8 @@ class AdImage
mount_uploader :file, ImageUploader
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :context, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :title, localize: true
field :context, localize: true
field :direct_to_after_click,type: Boolean
@@ -26,6 +26,9 @@ class AdImage
# validates_format_of :out_link, with: /(http:\/\/.*|)/ ,:message => 'Need a valid URL'
attr_reader :parse_post_date,:parse_unpost_date
before_validation :add_http
validates :out_link, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix, :allow_blank => true
def parse_post_date=(att)
self.post_date = (Date.parse att.gsub(/\s+/, "") rescue nil)
end
@@ -52,4 +55,12 @@ class AdImage
end
time
end
protected
def add_http
unless self.out_link[/^http:\/\//] || self.out_link[/^https:\/\//] || self.out_link.blank?
self.out_link = 'http://' + self.out_link
end
end
end
+1 -1
View File
@@ -1,7 +1,7 @@
class AppManager
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :user
belongs_to :managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :managers,:foreign_key => "user_id"
+10 -22
View File
@@ -6,40 +6,28 @@ class Asset
mount_uploader :data, FileAssetUploader
field :filename
field :description
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :description, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :description, localize: true
field :title, localize: true
validates_presence_of :title, :data, :description
validates :title, :at_least_one => true
validates :description, :at_least_one => true
validates_presence_of :data
belongs_to :asset_category
belongs_to :assetable, polymorphic: true
has_and_belongs_to_many :tags, :class_name => "AssetTag"
before_save :set_key
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def description
@description ||= I18nVariable.first(:conditions => {:key => 'description', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
before_save :clean_tags
def sorted_tags
tags.order_by(I18n.locale, :asc)
end
protected
def set_key
if title && title.new_record?
title.key = 'title'
end
if description && description.new_record?
description.key = 'description'
end
def clean_tags
self.tag_ids.delete('')
end
end
+1 -2
View File
@@ -4,8 +4,7 @@ class AssetCategory
field :key
field :display
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
field :title, localize: true
has_many :assets
+6 -3
View File
@@ -2,11 +2,14 @@ class I18nVariable
include Mongoid::Document
include Mongoid::Timestamps
field :key
field :document_class, :type => String
field :key, :index => true
field :document_class, :type => String, :index => true
field :parent_id, :type => BSON::ObjectId, :index => true
belongs_to :language_value, polymorphic: true
def method_missing(*field)
+7 -3
View File
@@ -10,8 +10,9 @@ class Item
field :is_published, :type => Boolean, :default => false
field :enabled_for, :type => Array, :default => nil
field :menu_enabled_for, :type => Array, :default => nil
field :title, localize: true
field :sitemap_enabled, :type => Boolean, :default => true
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
@@ -20,9 +21,12 @@ class Item
validates_associated :parent, :children
before_destroy :destroy_children
after_rearrange :rebuild_path
after_rearrange :rebuild_path, :if => "parent_id_changed? || name_changed?"
def enabled_for_lang(lang)
enabled_for.include?(lang)
end
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })
end
+2 -3
View File
@@ -4,16 +4,15 @@ class Meta
include Mongoid::Timestamps
field :key
field :title, localize: true
field :value, :default => nil
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
def get_name_content
[self.key, get_content]
end
def get_content
self.value ? self.value : self.i18n_variable[I18n.locale]
self.value ? self.value : self.title
end
end
+3 -3
View File
@@ -4,7 +4,7 @@ class ModuleApp
include OrbitCoreLib::ObjectTokenUnility
field :key
field :title
field :title
field :version
field :organization
field :author
@@ -18,8 +18,8 @@ class ModuleApp
field :widgets ,type: Hash
field :widget_fields ,type: Array
has_many :managers,as: :managing_app ,:class_name => "AppManager" #,:dependent => :destroy,:foreign_key => "managing_app_id",:inverse_of => :managing_app
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
has_many :tags
has_many :page_parts
+30 -40
View File
@@ -6,9 +6,10 @@ class Page < Item
field :content
field :app_frontend_url
field :theme_id, :type => BSON::ObjectId, :default => nil
field :category
field :tag
field :category, :default => ''
field :tag, :default => ''
field :view_count, :type => Integer, :default => 0
field :page_title, localize: true
field :frontend_style
field :frontend_field , :type => Array
@@ -16,59 +17,48 @@ class Page < Item
belongs_to :design
belongs_to :module_app
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_many :page_parts, :autosave => true, :dependent => :destroy
has_many :page_contexts, :autosave => true, :dependent => :destroy
has_many :page_metas, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :page_parts, :allow_destroy => true
before_save :create_parts, :set_key , :delete_empty_frontend_field
before_save :create_parts, :delete_empty_frontend_field
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
protected
def create_parts
page_design = self.design
parent = self.parent
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
page_design.layout.layout_parts.each do |layout_part|
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
if menu_part && current_part.name.eql?(menu_part.name)
if current_part.new_record?
current_part.kind = menu_part.kind
current_part.public_r_tag = menu_part.public_r_tag
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
else
current_part.update_attributes(:kind => menu_part.kind, :public_r_tag => menu_part.public_r_tag, :public_r_tag_object_id => menu_part.public_r_tag_object_id)
if self.new_record? || self.design.changed?
page_design = self.design
parent = self.parent
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
page_design.layout.layout_parts.each do |layout_part|
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
if menu_part && current_part.name.eql?(menu_part.name)
if current_part.new_record?
current_part.kind = menu_part.kind
current_part.public_r_tag = menu_part.public_r_tag
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
else
current_part.update_attributes(:kind => menu_part.kind, :public_r_tag => menu_part.public_r_tag, :public_r_tag_object_id => menu_part.public_r_tag_object_id)
end
end
end
end
end
def set_key
if title && title.new_record?
title.key = 'title'
end
end
def delete_empty_frontend_field
if self.frontend_field
self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) }
# self.frontend_field.each do | ff |
# if ff[0].blank? || ff[1].blank?
# self.frontend_field.delete("") if self.frontend_field
# self.frontend_field.delete(ff)
# end
# end
end
if self.frontend_field
self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) }
# self.frontend_field.each do | ff |
# if ff[0].blank? || ff[1].blank?
# self.frontend_field.delete("") if self.frontend_field
# self.frontend_field.delete(ff)
# end
# end
end
end
end
+6 -22
View File
@@ -4,45 +4,29 @@ class PagePart
include Mongoid::Timestamps
field :name
field :content
field :content, localize: true
field :kind
field :public_r_tag
field :public_r_tag_object_id, :default => nil
field :public_r_tag_option, :default => nil
field :page_title, localize: true
field :widget_path
field :widget_style
field :widget_field , :type => Array
field :widget_data_count
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, :delete_empty_widget_field
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
before_save :delete_empty_widget_field
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
def delete_empty_widget_field
if self.widget_field
self.widget_field.reject! { |wf| (wf[0].blank? || wf[1].blank?) }
end
if self.widget_field
self.widget_field.reject! { |wf| (wf[0].blank? || wf[1].blank?) }
end
# self.widget_field.delete("") if self.widget_field
end
+12 -33
View File
@@ -20,12 +20,13 @@ class Site
mount_uploader :default_image, ImageUploader
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :footer, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :sub_menu, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_many :site_metas, :autosave => true, :dependent => :destroy
field :search,:type => Hash
field :title, localize: true
field :footer, localize: true
field :sub_menu, localize: true
before_save :set_key
has_many :site_metas, :autosave => true, :dependent => :destroy
def generate_keys
private_key = OpenSSL::PKey::RSA.generate(2048)
@@ -42,39 +43,17 @@ class Site
res.eql?('local out of date') ? false : true
end
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def footer
@footer ||= I18nVariable.first(:conditions => {:key => 'footer', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def sub_menu
@sub_menu ||= I18nVariable.first(:conditions => {:key => 'sub_menu', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
METAS.each do |meta|
define_method meta do
define_method meta do |locale|
fetch_meta = self.site_metas.where(key: meta).limit(1)
fetch_meta.blank? ? nil : fetch_meta[0].i18n_variable
fetch_meta.blank? ? nil : fetch_meta[0].title_translations[locale]
end
define_method "#{meta}=" do |values|
if a = self.send(meta)
a.update_attributes(values)
else
a = self.site_metas.build(key: meta)
a.build_i18n_variable(values)
end
fetch_meta = self.site_metas.where(key: meta).limit(1)[0] rescue nil
fetch_meta = self.site_metas.build(key: meta) if fetch_meta.blank?
fetch_meta.title_translations = values
fetch_meta.save
end
end
protected
def set_key
title.key = 'title' if title && (title.key.blank? rescue true)
footer.key = 'footer' if footer && (footer.key.blank? rescue true)
sub_menu.key = 'sub_menu' if sub_menu && (sub_menu.key.blank? rescue true)
end
end
+33 -2
View File
@@ -1,10 +1,41 @@
class Tag
include Mongoid::Document
include Mongoid::Timestamps
include Impressionist::Impressionable
is_impressionable :counter_cache => { :column_name => :view_count }
field :key
field :view_count, :type => Integer, :default => 0
#field :cloud_amper,:type: Integer,:default=> 0
belongs_to :module_app
def self.sorted_for_cloud
tags = {}
self.all.each{ |tag|
tags.merge!({tag => self.get_impressionist(tag)})
}
if !tags.blank?
sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
sorted_tags[0][1] = :hot1
offset = (sorted_tags.size - 1) / 3
i = 1
class_i = 2
sorted_tags[1..-1].collect!{ |x|
x[1] = "hot#{class_i}"
i == offset ? i = 1 : i += 1 if class_i < 4
class_i += 1 if i == offset && class_i < 4
}
sorted_tags
else
[]
end
end
protected
def self.get_impressionist(item_tag = self)
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
end
end
+1 -1
View File
@@ -6,9 +6,9 @@ class Attribute
field :key
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
has_many :attribute_fields, :autosave => true, :dependent => :destroy
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
def is_built_in?
+1 -1
View File
@@ -9,9 +9,9 @@ class AttributeField
field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
belongs_to :attribute
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :attribute_values
# validates_uniqueness_of :key
+1 -2
View File
@@ -6,11 +6,10 @@ class Role
field :key
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
has_many :sub_roles, :autosave => true, :dependent => :destroy
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :users
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
accepts_nested_attributes_for :sub_roles, :allow_destroy => true
def is_built_in?
+12 -15
View File
@@ -9,6 +9,7 @@ class User
field :admin, :type => Boolean, :default => true
field :active_role
field :nccu_ldap_uid
# field :cache_dept
# has_one :cache_dept, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
@@ -16,10 +17,10 @@ class User
has_many :attribute_values, :autosave => true, :dependent => :destroy
has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists
has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth"
has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth"
has_many :managing_apps,:class_name => "AppManager"
has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth", :dependent => :destroy
has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth", :dependent => :destroy
has_many :managing_apps,:class_name => "AppManager", :dependent => :destroy
has_one :desktop, :autosave => true, :dependent => :destroy
has_many :other_accounts, :autosave => true, :dependent => :destroy
has_many :journals, :autosave => true, :dependent => :destroy
@@ -27,19 +28,17 @@ class User
belongs_to :role
has_and_belongs_to_many :sub_roles
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
before_create :initialize_desktop
scope :remote_account, where(:nccu_id.ne => nil)
def create_dept_cache
dept_hash = {}
VALID_LOCALES.each do |loc|
locale = loc.to_sym
# debugger
# if(self.cache_dept.nil?)
# self.build_cache_dept key: "dept_cache_user_#{self.id}"
# end
dept_hash[locale] = sub_roles.collect{|sr| sr.i18n_variable[locale]}.join(',')
# self.cache_dept[locale] = sub_roles.collect{|sr| sr.i18n_variable[locale]}.join(',')
dept_hash[locale] = sub_roles.collect{|sr| sr.title}.join(',')
end
self.cache_dept = dept_hash
self.save!
@@ -48,13 +47,11 @@ class User
def self.current
Thread.current[:user]
end
def self.current=(user)
Thread.current[:user] = user
end
before_create :initialize_desktop
def avb_apps
sub_role_ids_ary=self.sub_roles.collect{|t| t.id}
query1 = AppAuth.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: self.id)
@@ -67,7 +64,7 @@ class User
if info
first_name = get_attribute_values.detect {|value| value.key.to_s.eql?('first_name') }[I18n.locale.to_s] rescue nil
last_name = get_attribute_values.detect {|value| value.key.to_s.eql?('last_name') }[I18n.locale.to_s] rescue nil
return "#{first_name} #{last_name}"
return "#{last_name} #{first_name}"
else
return nil
end