first version of app config and modified inits.

This commit is contained in:
Fu Matthew committed 2013-01-29 20:33:40 +08:00
1 parent bfaa22052f
commit 71d5abae2e
36 files changed
+377 -264

No files matched your search

+15 -44
View File
@@ -29,37 +29,24 @@ class Admin::PagePartsController < ApplicationController
@user_choose = @part.widget_path
@r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
@tag_objects = @r_tag.classify.constantize.all rescue nil
@widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0]
@widget_style = @module_app.get_widget_style[@widget_path][:style] unless @widget_path.nil?
@categories = @module_app.get_registration.get_categories
@tags = @module_app.get_registration.get_tags
# if @module_app.widgets.any?{|b| b.class == Array}
# @widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
# end
if @module_app
@widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0]
@widget_style = @module_app.get_widget_style[@widget_path][:style] unless @widget_path.nil? or @module_app.nil?
end
unless @module_app.nil?
@categories = @module_app.get_categories
@tags = @module_app.get_tags
end
@widget_path = @part.widget_path ? @part.widget_path : (@module_app.widgets.keys[0] rescue nil)
if @module_app && @module_app.widgets.any?{|b| b.class == Array}
@widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
end
# TODO 應該要有一些東西來決定 @categories @tags
# case @module_app.key
# when 'announcement'
# @categories = BulletinCategory.all
# @tags = AnnouncementTag.all
# when 'gallery'
# @albums = GalleryAlbum.all
# when 'web_resource'
# @categories = WebLinkCategory.all
# @tags = WebResourceTag.all
# when 'archive'
# @categories = ArchiveFileCategory.all
# @tags = ArchiveTag.all
# end if @module_app
end
def create
@@ -107,29 +94,13 @@ class Admin::PagePartsController < ApplicationController
def reload_widgets
@part = PagePart.find params[:id]
@categories =[]
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil
@widget_path = @module_app.widgets.keys[0] if (@module_app && @module_app.widgets[0].blank? )
@categories =@module_app ? @module_app.get_categories : []
@tags =@module_app ? @module_app.get_tags : []
@widget_path = @module_app.widgets.keys[0] if (@module_app && @module_app.widgets[0].blank? )
@widget_style = @module_app.widgets[@widget_path] if ( !@widget_path.blank? )
case @module_app.key
when 'announcement'
@categories = BulletinCategory.all
@tags = AnnouncementTag.all
when 'gallery'
@albums = GalleryAlbum.all
@tags = []
when 'web_resource'
@categories = WebLinkCategory.all
@tags = WebResourceTag.all
when 'archive'
@categories = ArchiveFileCategory.all
@tags = ArchiveTag.all
end if @module_app
@part.widget_path = @module_app.widgets.first if( @module_app && @module_app.needs_to_widget_option?)
@part.widget_path = @module_app.widgets.first if( @module_app)
respond_to do |format|
format.js {}
end
+4 -6
View File
@@ -29,8 +29,8 @@ helper Admin::PagePartsHelper
@design = @item.design ? @item.design : @designs.first
if @item.module_app
@app_frontend_urls = @item.module_app.app_pages
@app_frontend_urls << 'default_widget' if @item.module_app.has_default_widget?
@app_frontend_urls = @item.module_app.app_pages.map{|t| [I18n.t(t[0]),t[1]]}
@app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if @item.module_app.has_default_widget?
end
@@ -140,11 +140,9 @@ helper Admin::PagePartsHelper
@page = Page.find params[:id] rescue nil
# @categories =[]
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil
@app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages
@app_frontend_urls << 'default_widget' if(@module_app && @module_app.has_default_widget?)
@app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages.map{|t| [I18n.t(t[0]),t[1]]}
@app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if(@module_app && @module_app.has_default_widget?)
case (@module_app.nil? ? nil : @module_app.key )
when 'announcement'
@categories = BulletinCategory.all
+5 -1
View File
@@ -12,7 +12,11 @@ module Admin::PagePartsHelper
def widget_field_options(i,local_item=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
options = @module_app.widget_fields.collect{|widget_field| [I18n.t(widget_field[1]), widget_field[0]]}
options = @module_app.widget_fields.collect do |widget_field|
label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}")
[label, widget_field[0]]
end
case local_item
when Page
+88 -141
View File
@@ -2,74 +2,40 @@ class ModuleApp
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCoreLib::ObjectTokenUtility
include OrbitApp::ModuleAppMembershipTools
field :key
field :title
field :sidebar_order#,type: Integer
field :version
field :organization
field :author
field :intro
field :update_info
field :create_date
field :enable_frontend, type: Boolean, :default => true
field :app_pages ,type: Array
# field :widgets ,type: Array
field :widgets ,type: Hash
field :widget_fields ,type: Array
field :widget_options,type:Hash
field :widget_options_fields_i18n,type:Hash
field :widget_fields_link_method,type:Hash
field :get_default_widget,type:Hash
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
has_many :pages
has_one :app_auth,dependent: :delete
before_save :set_key
def get_registration
OrbitApp::Module::Registration.find_by_key(key)
def refetch_setting!(reg)
# %w{module_label category base_url version organization author intro update_info create_date}.each do |field|
# self[field.to_sym] = reg.send field
# end
self[:app_pages] = reg.get_app_pages
self[:enable_frontend] = reg.get_enable_frontend
self[:get_widget_style] = reg.get_widgets
self[:using_default_widget] = !reg.get_default_widget.blank?
self[:widgets] = reg.get_widgets
end
%w{widget_styles }.each do |field|
define_method(field){|var| get_registration.send("get_#{field}") }
# def app_pages
# get_registration.get_app_pages
# end
def enable_frontend?
self[:enable_frontend]
end
def get_default_widget
get_registration.get_default_widget
raise 'Need to link with OrbitApp [type: Array]'
end
def enable_frontend?
get_registration.get_enable_frontend
end
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
def get_widget_style
widgets = get_registration.get_widgets
end
def get_widget_for_select
widgets = get_registration.get_widgets
widgets = get_widget_style
ary = widgets.collect do |k,v|
if k == 'default_widget'
[I18n.t('widget.default_widget'),'default_widget']
@@ -80,104 +46,85 @@ class ModuleApp
end
end
def is_manager?(user)
if user.nil?
return false
else
m_users = managing_users
if m_users.blank?
false
else
m_users.include?(user)
end
end
# def get_widget_style
# get_registration.get_widgets
# end
def has_default_widget?
self[:widgets].has_key? 'default_widget'
end
def is_sub_manager?(user)
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
end
def managing_users
self.managers.collect{ |t| t.user }
end
def sub_managing_users
self.sub_managers.collect{ |t| t.user }
end
def assign_manager(user,assigner)
manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil
if manager.nil?
manager = self.managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil))
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
if submanager.nil? && !self.managing_users.include?(user)
submanager = self.sub_managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil) )
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
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
def label
I18n.t(label_i18n)
end
def needs_to_widget_option?
if self.widget_options
self.widget_options.has_key? widgets.first
else
false
end
def label_i18n
reg = get_registration
reg.nil? ? 'Init is not defined completely' : get_registration.get_label_i18n
end
def has_default_widget?
case self[:widgets]
when Array
false
when Hash
self[:widgets].has_key? 'default_widget'
end
# def needs_to_widget_option?
# if self.widget_options
# self.widget_options.has_key? widgets.first
# else
# false
# end
# end
def using_default_widget?
# !get_registration.get_default_widget.blank?
self[:get_default_widget]
end
protected
def widget_fields
# binding.pry
# raise 'Need to link with OrbitApp [type: Array]'
get_registration.get_default_widget_fields
end
# def widgets
# # get_registration.get_widgets
# # get_registration.get_default_widget
# end
def widget_options(widget_path=nil)
get_registration.get_widget_by_path(widget_path)
# raise 'Need to link with OrbitApp [type: Hash]'
end
def widget_options_fields_i18n
raise 'Need to link with OrbitApp [type: Hash]'
end
def widget_fields_link_method
raise 'Need to link with OrbitApp [type: Hash]'
end
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
def set_key
self.key = self.title.underscore.singularize if self.title
# # has_many :tags
has_many :page_parts
has_many :pages
has_one :app_auth,dependent: :delete
def get_tags
get_registration.get_tags
end
def get_categories
get_registration.get_categories
end
def module_name
I18n.t(get_registration.get_label_i18n)
end
def get_registration
OrbitApp::Module::Registration.find_by_key(key)
end
end
@@ -1 +1 @@
<%= f.select :module_app_id, @apps.collect { |t| [t.title.capitalize, t.id] }, {:include_blank => true} ,{:rel => admin_module_apps_path } %>
<%= f.select :module_app_id, @apps.collect { |t| [t.module_name, t.id] }, {:include_blank => true} ,{:rel => admin_module_apps_path } %>
@@ -6,11 +6,11 @@
<% if @module_app.nil? || @module_app.widgets.nil? || (@module_app.widgets[@widget_path].blank? rescue true) %>
<%= t("default_widget.no_support_setting")%>
<%else%>
<%= select('page_part', 'widget_style', @module_app.widgets[@widget_path]) %>
<%= select('page_part', 'widget_style', @module_app.widgets[@widget_path]["style"]) %>
<% end %>
</div>
</div>
<% if(@module_app && @module_app.widget_options && @module_app.widget_options.has_key?(@widget_path)) %>
<% if(@module_app && @module_app.widget_options(@widget_path)) %>
<div class="style_switch control-group">
<label class="control-label"><%= t("default_widget.select_widget_ext_option") %></label>
<div class="controls well" >
@@ -17,7 +17,7 @@
<%= t "default_widget.select_module_app" %>
</label>
<div class="controls">
<%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :title, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => admin_page_parts_path,:id=>"page_module_app_id"} %>
<%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :module_name, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => admin_page_parts_path,:id=>"page_module_app_id"} %>
</div>
</div>
@@ -26,7 +26,7 @@
<%= t "default_widget.select_widget_path" %>
</label>
<div class="controls">
<%= f.select :widget_path, @module_app ? @module_app.widgets.collect{|k,v| [k.humanize, k]} : [], {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
<%= f.select :widget_path, @module_app ? @module_app.widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} : [], {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
</div>
</div>
@@ -14,7 +14,7 @@
<%= content_tag_for(:label, @tags,:class=>"radio inline") do |tag|%>
<%= radio_button_tag("#{field_name}[tag]", tag.id, tag_checked_value(object,tag.id) ) %>
<%= tag[I18n.locale]%>
<% end %>
<% end if @tags%>
</fieldset>
<% else %>
<%= t("default_widget.no_support_setting")%>
@@ -1,5 +1,6 @@
<% @module_app.widget_options[@widget_path].each do |key,options| %>
<%= label_tag(t(@module_app.widget_options_fields_i18n[@widget_path][key]))%>
<% @module_app.widget_options(@widget_path).get_options.each do |key,settings| %>
<% options = settings[:opts] %>
<%= label_tag(t(settings[:label_i18n]))%>
<% case options%>
<% when Hash%>
<%= select_tag "page_part[widget_options][#{key}]", options_from_collection_for_select(eval(options["query"]), options["value"], options["label"].to_s, :selected => (@part.widget_options[key] rescue nil)) %>
@@ -1,5 +1,5 @@
<% if @module_app%>
$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k},@part.widget_path) %>");
$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| [I18n.t(v['i18n']),k]},@part.widget_path) %>");
$("#widget_data_source_category").html("<%= j render :partial => 'widget_data_source_category',:locals=>{:object=>@part} %>");
$("#widget_data_source_tag").html("<%= j render :partial => 'widget_data_source_tag',:locals=>{:object=>@part} %>");
+1 -1
View File
@@ -1 +1 @@
<%= f.select :module_app_id, @apps.collect { |t| [t.title.capitalize, t.id] }, {:include_blank => true} ,{:rel => admin_pages_path } %>
<%= f.select :module_app_id, @apps.collect { |t| [t.module_name, t.id] }, {:include_blank => true} ,{:rel => admin_pages_path } %>