2011-11-19 06:33:26 +00:00
|
|
|
class ModuleApp
|
2011-11-16 07:21:31 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2012-12-03 10:52:36 +00:00
|
|
|
include OrbitCoreLib::ObjectTokenUtility
|
2011-11-16 07:21:31 +00:00
|
|
|
|
2012-01-30 10:12:18 +00:00
|
|
|
field :key
|
2012-06-25 08:23:16 +00:00
|
|
|
field :title
|
2012-11-29 06:21:46 +00:00
|
|
|
|
2011-11-16 07:21:31 +00:00
|
|
|
field :version
|
|
|
|
field :organization
|
|
|
|
field :author
|
|
|
|
field :intro
|
|
|
|
field :update_info
|
|
|
|
field :create_date
|
2012-02-16 04:16:27 +00:00
|
|
|
field :enable_frontend, type: Boolean, :default => true
|
2012-12-28 07:30:46 +00:00
|
|
|
|
2011-12-20 08:47:17 +00:00
|
|
|
field :app_pages ,type: Array
|
2012-07-16 08:13:38 +00:00
|
|
|
# field :widgets ,type: Array
|
|
|
|
field :widgets ,type: Hash
|
2012-07-26 08:39:29 +00:00
|
|
|
field :widget_fields ,type: Array
|
2012-12-28 07:30:46 +00:00
|
|
|
field :widget_options,type:Hash
|
|
|
|
field :widget_options_fields_i18n,type:Hash
|
2013-01-04 10:42:25 +00:00
|
|
|
field :widget_fields_link_method,type:Hash
|
|
|
|
field :get_default_widget,type:Hash
|
|
|
|
|
2013-01-08 06:17:21 +00:00
|
|
|
|
2012-06-25 08:23:16 +00:00
|
|
|
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
|
2012-01-13 10:20:04 +00:00
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
# has_many :tags
|
2012-02-16 04:16:27 +00:00
|
|
|
has_many :page_parts
|
|
|
|
has_many :pages
|
2012-02-14 16:32:20 +00:00
|
|
|
|
2011-12-20 08:47:17 +00:00
|
|
|
has_one :app_auth,dependent: :delete
|
2012-11-29 06:21:46 +00:00
|
|
|
|
2012-01-30 10:12:18 +00:00
|
|
|
before_save :set_key
|
2012-11-29 06:21:46 +00:00
|
|
|
|
|
|
|
def get_registration
|
|
|
|
OrbitApp::Module::Registration.find_by_key(key)
|
|
|
|
end
|
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
%w{widget_styles }.each do |field|
|
|
|
|
define_method(field){|var| get_registration.send("get_#{field}") }
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_default_widget
|
|
|
|
get_registration.get_default_widget
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable_frontend?
|
|
|
|
get_registration.get_enable_frontend
|
|
|
|
end
|
2012-11-29 06:21:46 +00:00
|
|
|
|
|
|
|
def label_i18n
|
|
|
|
reg = get_registration
|
|
|
|
reg.nil? ? 'Init is not defined completely' : get_registration.get_label_i18n
|
|
|
|
end
|
|
|
|
|
|
|
|
# def method_missing(m, *args, &block)
|
|
|
|
# # get_registration.send("get_#{m}")
|
|
|
|
# end
|
|
|
|
|
|
|
|
def using_default_widget?
|
|
|
|
!get_registration.get_default_widget.blank?
|
|
|
|
end
|
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
def get_widget_style
|
|
|
|
widgets = get_registration.get_widgets
|
|
|
|
end
|
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def get_widget_for_select
|
|
|
|
widgets = get_registration.get_widgets
|
2012-12-03 10:52:36 +00:00
|
|
|
ary = widgets.collect do |k,v|
|
|
|
|
if k == 'default_widget'
|
|
|
|
[I18n.t('widget.default_widget'),'default_widget']
|
|
|
|
else
|
|
|
|
[I18n.t(v[:label]),k]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-11-29 06:21:46 +00:00
|
|
|
end
|
|
|
|
|
2012-02-15 10:20:44 +00:00
|
|
|
def is_manager?(user)
|
2012-12-07 04:40:47 +00:00
|
|
|
if user.nil?
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
m_users = managing_users
|
|
|
|
if m_users.blank?
|
|
|
|
false
|
|
|
|
else
|
|
|
|
m_users.include?(user)
|
|
|
|
end
|
|
|
|
end
|
2012-02-15 10:20:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_sub_manager?(user)
|
2012-12-07 04:40:47 +00:00
|
|
|
if user.nil?
|
|
|
|
return false
|
|
|
|
else # when user is guest
|
|
|
|
s_m_users = sub_managing_users
|
|
|
|
result = false
|
|
|
|
if s_m_users.blank?
|
|
|
|
result = false
|
|
|
|
else
|
|
|
|
result = s_m_users.include?(user)
|
|
|
|
end
|
|
|
|
result || is_manager?(user)
|
|
|
|
end
|
2012-02-15 10:20:44 +00:00
|
|
|
end
|
|
|
|
|
2012-01-17 08:20:03 +00:00
|
|
|
def managing_users
|
|
|
|
self.managers.collect{ |t| t.user }
|
|
|
|
end
|
|
|
|
|
|
|
|
def sub_managing_users
|
|
|
|
self.sub_managers.collect{ |t| t.user }
|
|
|
|
end
|
2012-01-13 10:20:04 +00:00
|
|
|
|
|
|
|
def assign_manager(user,assigner)
|
|
|
|
manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil
|
2012-01-17 08:20:03 +00:00
|
|
|
if manager.nil?
|
2012-10-16 07:08:02 +00:00
|
|
|
manager = self.managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil))
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
manager
|
|
|
|
end
|
|
|
|
|
|
|
|
def assign_sub_manager(user,assigner)
|
|
|
|
submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil
|
2012-01-17 08:20:03 +00:00
|
|
|
if submanager.nil? && !self.managing_users.include?(user)
|
2012-10-16 07:08:02 +00:00
|
|
|
submanager = self.sub_managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil) )
|
2012-01-13 10:20:04 +00:00
|
|
|
end
|
|
|
|
submanager
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_manager(user)
|
|
|
|
manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil
|
|
|
|
if manager
|
|
|
|
manager.destroy
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2012-01-05 08:20:51 +00:00
|
|
|
|
2012-01-13 10:20:04 +00:00
|
|
|
def remove_sub_manager(user)
|
|
|
|
submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil
|
|
|
|
if submanager
|
|
|
|
submanager.destroy
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2011-11-16 07:21:31 +00:00
|
|
|
|
2013-01-08 06:17:21 +00:00
|
|
|
|
2012-11-29 06:21:46 +00:00
|
|
|
def label
|
|
|
|
I18n.t(label_i18n)
|
|
|
|
end
|
|
|
|
|
2012-12-28 07:30:46 +00:00
|
|
|
def needs_to_widget_option?
|
|
|
|
if self.widget_options
|
|
|
|
self.widget_options.has_key? widgets.first
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-30 10:12:18 +00:00
|
|
|
protected
|
2011-12-23 10:34:21 +00:00
|
|
|
|
2012-01-30 10:12:18 +00:00
|
|
|
def set_key
|
2012-10-30 09:10:59 +00:00
|
|
|
self.key = self.title.underscore.singularize if self.title
|
2012-01-30 10:12:18 +00:00
|
|
|
end
|
2012-02-16 05:57:28 +00:00
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
|
2011-11-16 07:21:31 +00:00
|
|
|
end
|