put module app json into init,making orbit app work with module app.

This commit is contained in:
Matthew K. Fu JuYuan committed 2012-11-29 14:21:46 +08:00
1 parent 3d573680b2
commit f9bcb27efc
15 files changed
+349 -66

No files matched your search

@@ -31,9 +31,9 @@ class Admin::PagePartsController < ApplicationController
@widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0]
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.widgets.any?{|b| b.class == Array}
# @widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
# end
case @module_app.key
when 'announcement'
@@ -119,7 +119,6 @@ class Admin::PagePartsController < ApplicationController
def reload_widget_styles
@module_app = ModuleApp.find(params[:module_app_id])
@widget_style = @module_app.widgets[params[:id]]
respond_to do |format|
+3 -2
View File
@@ -4,7 +4,8 @@ class Item
include Mongoid::Timestamps
include Mongoid::Tree
include Mongoid::Tree::Ordering
LIST = YAML.load(File.read('config/list.yml'))
field :name
field :path
field :is_published, :type => Boolean, :default => false
@@ -15,7 +16,7 @@ class Item
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_presence_of :name
validates_associated :parent, :children
+35 -16
View File
@@ -5,30 +5,45 @@ class ModuleApp
field :key
field :title
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
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 :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)
end
# %w{label_i18n }.each do |field|
# define_method(field){|var| get_registration.send("get_#{m}") }
# 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_for_select
widgets = get_registration.get_widgets
ary = widgets.collect{|k,v| [I18n.t(v["label"]),k]}
ary << [I18n.t('widget.default_widget'),'default_widget']if using_default_widget?
end
def is_manager?(user)
managing_users.include?(user)
end
@@ -79,6 +94,10 @@ class ModuleApp
end
end
def label
I18n.t(label_i18n)
end
protected
def set_key
@@ -10,12 +10,12 @@
</div>
<span id='module_app_list'>
<%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :title, :selected => @module_app.id), {}, {:rel => admin_page_parts_path} %>
<%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :label, :selected => @module_app.id), {}, {:rel => admin_page_parts_path} %>
</span>
<span id='widget_list'>
<%#= f.select :widget_path, @module_app.widgets.collect{|widget| [widget.humanize, widget]}, :selected => @part.widget_path %>
<%= f.select :widget_path, @module_app.widgets.collect{|k,v| [k.humanize, k]}, {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
<%= f.select :widget_path, @module_app.get_widget_for_select, {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %>
</span>
<span id='widget_style_list'>
@@ -34,18 +34,10 @@
</span>
<span id='widget_field'>
<%= render 'widget_fields' %>
<%#= f.label :widget_field %>
<%# @module_app.widget_fields.each_with_index do |widget_field, i| %>
<%#= i+1 %>
<%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part.widget_field ? @part.widget_field[i] : nil) ), :include_blank => true %> <br />
<%# end %>
<%#= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, @part.widget_field.collect{|widget_field| widget_field}), {:multiple => :multiple, :size => 6} %>
</span>
<div id="widget_data_count">
<%= f.label :widget_data_count %>
<%= f.text_field :widget_data_count %>
@@ -1,4 +1,4 @@
$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k}) %>");
$('#widget_list select').html("<%= j options_for_select(@module_app.get_widget_for_select) %>");
$('#widget_style_list').html("<%= escape_javascript(select 'page_part', 'widget_style', @module_app.widgets[@widget_path]) if !@widget_path.blank? %>");
$('#widget_field').html("<%= j render 'widget_fields' %>");
$('#widget_category').html("<%= j render 'widget_categories' %>");