diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index 1ac7d669b..6442d2fc7 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -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 diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index e1cd0c0da..f2de0c9e4 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -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 diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index 24f21b78c..818fe46bd 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -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 diff --git a/app/models/module_app.rb b/app/models/module_app.rb index d188a70b9..fb735438a 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -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 diff --git a/app/views/admin/module_apps/_app_selector.html.erb b/app/views/admin/module_apps/_app_selector.html.erb index c20a38858..60cf2d6fa 100644 --- a/app/views/admin/module_apps/_app_selector.html.erb +++ b/app/views/admin/module_apps/_app_selector.html.erb @@ -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 } %> diff --git a/app/views/admin/page_parts/_custom_widget_setting.html.erb b/app/views/admin/page_parts/_custom_widget_setting.html.erb index 33615e5b6..998b5853c 100644 --- a/app/views/admin/page_parts/_custom_widget_setting.html.erb +++ b/app/views/admin/page_parts/_custom_widget_setting.html.erb @@ -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 %> - <% if(@module_app && @module_app.widget_options && @module_app.widget_options.has_key?(@widget_path)) %> + <% if(@module_app && @module_app.widget_options(@widget_path)) %>
diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 1db248b55..38fb013f6 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -17,7 +17,7 @@ <%= t "default_widget.select_module_app" %>
- <%= 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"} %>
@@ -26,7 +26,7 @@ <%= t "default_widget.select_widget_path" %>
- <%= 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 } %>
diff --git a/app/views/admin/page_parts/_widget_data_source_tag.html.erb b/app/views/admin/page_parts/_widget_data_source_tag.html.erb index 521d2ff4b..bcb3e9c3b 100644 --- a/app/views/admin/page_parts/_widget_data_source_tag.html.erb +++ b/app/views/admin/page_parts/_widget_data_source_tag.html.erb @@ -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%> <% else %> <%= t("default_widget.no_support_setting")%> diff --git a/app/views/admin/page_parts/_widget_ext_options.html.erb b/app/views/admin/page_parts/_widget_ext_options.html.erb index c38d0543e..6985939bb 100644 --- a/app/views/admin/page_parts/_widget_ext_options.html.erb +++ b/app/views/admin/page_parts/_widget_ext_options.html.erb @@ -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)) %> diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb index 40e9ec8fb..c32e07c28 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -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} %>"); diff --git a/app/views/admin/pages/_app_selector.html.erb b/app/views/admin/pages/_app_selector.html.erb index 6c0d1b406..9cb4c694b 100644 --- a/app/views/admin/pages/_app_selector.html.erb +++ b/app/views/admin/pages/_app_selector.html.erb @@ -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 } %> diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 80ec221cf..0bbb1755a 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,7 +1,11 @@ zh_tw: _locale: 中文 - + rulingcom: + errors: + init: + app_page_noname: 未命名前台頁面 + module_app_noname: 未命名模組 front_page: select_app_url: 模組前台樣式 is_published: 是否公開 @@ -112,6 +116,7 @@ zh_tw: delete: 刪除 delete_file: 刪除檔案 default_widget: + name: 預設樣式 no_support_setting: 沒有可以使用的設定 no_value: 不設定(全部) fields_: 前台輸出欄位 @@ -361,7 +366,7 @@ zh_tw: link: 連結已更新成功 page: 頁面已更新成功 user: 使用者已更新成功 - success_: 更新成功 + # success_: 更新成功 paper: Paper was successfully updated. user: User was successfully updated. success_: S使用者已更新成功 diff --git a/lib/orbit_app/module/front_end.rb b/lib/orbit_app/module/front_end.rb index 65f79f8ea..0c5b245c2 100644 --- a/lib/orbit_app/module/front_end.rb +++ b/lib/orbit_app/module/front_end.rb @@ -4,13 +4,14 @@ module OrbitApp Version = "0.1" module ClassMethods - @@frontend_pages = [] + @@frontend_pages = [] + #Record all frontend pages of orbit - def add(var) + def add(var) #build @@frontend_pages @@frontend_pages << var end - def all + def all #return all frontend_pages of orbit return @@frontend_pages end @@ -21,18 +22,18 @@ module OrbitApp other.extend( ClassMethods ) end - class AppPageSet + class AppPageSet # From Registration def initialize(&block) - @frontend_pages = [] + @frontend_pages = [] block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end - def app_page(name,options ={}) - @frontend_pages << AppPage.new(name,options) + def app_page(name,&block) + @frontend_pages << AppPage.new(name,&block) end - def to_module_app_format - @frontend_pages.collect{|t| t.name} + def to_module_app_format #For ModuleApp to fetch data + @frontend_pages.collect{|t| [t.get_i18n,t.name]} end end @@ -40,10 +41,20 @@ module OrbitApp class AppPage attr_reader :name - def initialize(name,options ={}) + def initialize(name,&block) @name = name + @frontend_i18n = 'rulingcom.errors.init.app_page_noname' + block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end + def frontend_i18n(i18n) + @frontend_i18n = i18n + end + + def get_i18n + @frontend_i18n + end + def finalize! end diff --git a/lib/orbit_app/module/registration.rb b/lib/orbit_app/module/registration.rb index 4c64f6298..4911042b7 100644 --- a/lib/orbit_app/module/registration.rb +++ b/lib/orbit_app/module/registration.rb @@ -35,6 +35,7 @@ module OrbitApp @key = name.underscore.singularize @side_bar = nil @front_end_app_pages = nil + @module_label = 'rulingcom.errors.init.module_app_noname' block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? setup_module_app end @@ -46,7 +47,7 @@ module OrbitApp def setup_module_app module_app = get_module_app module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil? - + module_app.refetch_setting!(self) begin module_app.save(:validate=>false) rescue @@ -59,6 +60,10 @@ module OrbitApp @module_label end + def get_default_widget_fields + return @widget_set.get_fields + end + def get_default_widget if @widget_set.nil? # Init not defining widget return {} @@ -77,32 +82,40 @@ module OrbitApp @front_end_app_pages.nil? ? [] : @front_end_app_pages.to_module_app_format end + def get_widget_by_path(path) + if @widget_set + @widget_set.find_by_path(path) + else + nil + end + end + def get_widgets @widget_set.nil? ? {} : @widget_set.to_module_app_format end def get_categories - @widget_set.get_categories + @widget_set.get_categories rescue [] end def get_tags - @widget_set.get_tags + @widget_set.get_tags rescue [] end - def front_end(&block) + def front_end(&block) #setter for front_end from init @front_end_app_pages = FrontendUtility::AppPageSet.new(&block) end - def side_bar(&block) + def side_bar(&block) #setter for side_bar from init @side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app),&block) end - def personal_plugin(params) + def personal_plugin(params) #setter for personal_plugin from init # TODO 這裡要看是一些檔案是不是都有 Plugin::Registration.new_from_module_app(@name,@base_path,params) end - def widgets(&block) + def widgets(&block) #setter for widget from init # @widgets = WidgetRegisition::WidgetSet.new(&block) @widget_set = WidgetUtility::WidgetSet.new(&block) diff --git a/lib/orbit_app/module/widget.rb b/lib/orbit_app/module/widget.rb index 5c6932bdf..a02a2427c 100644 --- a/lib/orbit_app/module/widget.rb +++ b/lib/orbit_app/module/widget.rb @@ -34,6 +34,12 @@ module OrbitApp define_method(field){|var| instance_variable_set( "@" + field, var)} end + def find_by_path(path) + @widgets.each do |widget| + return widget if widget.name == path + end + end + def get_categories eval(@categories_query) rescue nil end @@ -46,9 +52,17 @@ module OrbitApp @default_widget = DefaultWidget.new(&block) end - def customize_widget(name,label,options ={}) - @widgets << Widget.new(name,label,options) - end + def customize_widget(name,&block) + @widgets << Widget.new(name,&block) + end + + # def customize_widget(name,label,options ={}) + # @widgets << Widget.new(name,label,options) + # end + + # def customize_widget_options_fields_i18n(settings) + # @customize_widget_options_fields_i18n = settings + # end def to_module_app_format hash = {} @@ -57,10 +71,13 @@ module OrbitApp hash end + def get_fields + get_default_widget.get_fields + end + def get_default_widget return @default_widget end - end class DefaultWidget @@ -69,9 +86,16 @@ module OrbitApp def initialize(&block) @query = nil @image = nil + @more_link = {} + @fields = [] block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end + def more_link_to(label_i18n,path_method) + @more_link[:label_i18n] = label_i18n + @more_link[:path_method] = path_method + end + def self.get_interface_args #will need to work with design {:name=>"default_widget",:field=>nil,:label=>'label',:style=>STYLE} @@ -81,6 +105,18 @@ module OrbitApp {:query=>@query,:image=>@image} rescue nil end + def link_field(field_name,setting) + @fields << [field_name,setting,:link] + end + + def field(field_name) + @fields << [field_name,nil,:field] + end + + def get_fields + @fields + end + def query(var) @query = var end @@ -94,19 +130,38 @@ module OrbitApp class Widget attr_reader :name,:default_template,:fields - def initialize(name,label,options ={}) + def initialize(name,&block) @name = name - @fields = options[:fields] - @label = label - @style= options[:style] + @options = {} + block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? + + # @fields = options[:fields] + # @label = label + # @style= options[:style] end - def to_hash - {:name => @name,:fields=>@fields,:label=>@label,:style=>@style} + def widget_i18n(str) # "gallery.widget.widget1" + @widget_i18n = str + end + + def style(ary)# [] + @style = ary + end + + def get_options + @options end - def finalize! + def options(opt_name,*options) # "vertical", + option = options[0] + @options[opt_name] = {:label_i18n=>option[:i18n] , :opts=>option[:options_item]} + # options => :i18n => "gallery.widget_option.vertical",:options_item=>[1, 2] + # :i18n =>"gallery.widget_option.album",:options_item => {"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name} + end + + def to_hash + {:name => @name,:fields=>@fields,:label=>@label,:style=>@style,:i18n=>@widget_i18n} end protected diff --git a/lib/orbit_app/module_app_membership_tools.rb b/lib/orbit_app/module_app_membership_tools.rb new file mode 100644 index 000000000..a7a9a378e --- /dev/null +++ b/lib/orbit_app/module_app_membership_tools.rb @@ -0,0 +1,73 @@ +module OrbitApp + module ModuleAppMembershipTools + 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 + 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 + end +end \ No newline at end of file diff --git a/vendor/built_in_modules/ad_banner/init.rb b/vendor/built_in_modules/ad_banner/init.rb index e4c7f8cc9..4a9aafba2 100644 --- a/vendor/built_in_modules/ad_banner/init.rb +++ b/vendor/built_in_modules/ad_banner/init.rb @@ -1,6 +1,6 @@ module AdBanner OrbitApp.registration "AdBanner",:type=> 'ModuleApp' do - module_label 'ad_banner.ad_banner' + module_label 'miss_module_i18n.ad_banner' base_url File.expand_path File.dirname(__FILE__) # personal_plugin :enable => true,:path=>"panel/ad_banner/plugin/profile",:i18n=>'admin.ad_banner' diff --git a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml index 8b1b61314..995bf2f56 100644 --- a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml @@ -11,6 +11,8 @@ zh_tw: editing_announcement_category: 編輯公告類別 error: no_avilb_cate_for_posting: 公告必需有一個類別才能發送,請與管理員聯絡 + front_end: + bulletins: 請LIN給名字前台頁 new_bulletin_category: 新增公告類別 search: 搜尋公告 update_bulletin_success: 公告已成功更新 diff --git a/vendor/built_in_modules/announcement/init.rb b/vendor/built_in_modules/announcement/init.rb index dad194548..c1174dac3 100644 --- a/vendor/built_in_modules/announcement/init.rb +++ b/vendor/built_in_modules/announcement/init.rb @@ -12,7 +12,9 @@ module Announcement update_info 'some update_info' front_end do - app_page 'bulletins' + app_page 'bulletins' do + frontend_i18n "announcement.front_end.bulletins" + end end category ["BulletinCategory"] @@ -21,13 +23,18 @@ module Announcement default_widget do query 'Bulletin.all' image :image + field :postdate + link_field :title,{:method => 'panel_announcement_front_end_bulletin_path',:args=>:self} + link_field :bulletin_category_with_title,{:method => 'panel_announcement_front_end_bulletins_path',:args=>{:category_id => [:bulletin_category,:id]}} end categories_query 'BulletinCategory.all' tags_query 'AnnouncementTag.all' - customize_widget "index","announcement.widget.index",:fields=>["title","category","postdate"],:style=>["cu_style_1","cu_style_2","cu_style_3","cu_style_4","cu_style_5"] - customize_widget "bulletins_and_web_links","announcement.widget.bulletins_and_web_links" + customize_widget "index" do + widget_i18n "announcement.widget.index" + style ["1","2"] + end # item "index","announcement.widget.index",:default_template=>true,:fields=>["title","category","postdate"] # item "bulletins_and_web_links","announcement.widget.bulletins_and_web_links" end diff --git a/vendor/built_in_modules/archive/config/locales/zh_tw.yml b/vendor/built_in_modules/archive/config/locales/zh_tw.yml index 4ef309e62..807fca2b0 100644 --- a/vendor/built_in_modules/archive/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/archive/config/locales/zh_tw.yml @@ -1,7 +1,9 @@ zh_tw: _locale: 中文 - + archive: + widget: + archive_files: 檔案室Wiget add: 新增 back: 回去 create: 創造 diff --git a/vendor/built_in_modules/archive/init.rb b/vendor/built_in_modules/archive/init.rb index 5efd18f7b..53d574799 100644 --- a/vendor/built_in_modules/archive/init.rb +++ b/vendor/built_in_modules/archive/init.rb @@ -26,7 +26,10 @@ module Archive # categories_query 'BulletinCategory.all' # tags_query 'ArchiveTag.all' - customize_widget "archive_files","archive.widget.archive_files",:style=>[] + customize_widget "archive_files" do + widget_i18n "archive.widget.archive_files" + style [] + end end side_bar do diff --git a/vendor/built_in_modules/gallery/app/models/gallery_category.rb b/vendor/built_in_modules/gallery/app/models/gallery_category.rb index 622ec4a4a..07c5df8c9 100644 --- a/vendor/built_in_modules/gallery/app/models/gallery_category.rb +++ b/vendor/built_in_modules/gallery/app/models/gallery_category.rb @@ -1,17 +1,21 @@ class GalleryCategory - include Mongoid::Document - include Mongoid::Timestamps + include Mongoid::Document + include Mongoid::Timestamps - include OrbitCoreLib::ObjectAuthable + include OrbitCoreLib::ObjectAuthable - ObjectAuthTitlesOptions = %W{new_album} - APP_NAME = "album" + ObjectAuthTitlesOptions = %W{new_album} + APP_NAME = "album" - field :name, localize: true + field :name, localize: true - has_many :gallery_albums, :autosave => true, :dependent => :destroy + has_many :gallery_albums, :autosave => true, :dependent => :destroy - def pp_object - name - end + def title + name + end + + def pp_object + name + end end \ No newline at end of file diff --git a/vendor/built_in_modules/gallery/config/locales/zh_tw.yml b/vendor/built_in_modules/gallery/config/locales/zh_tw.yml index 164c93cc1..33a480aee 100644 --- a/vendor/built_in_modules/gallery/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/gallery/config/locales/zh_tw.yml @@ -23,6 +23,8 @@ zh_tw: edit: 編輯 delete_selected: 刪除選擇項目 del_album?: "要刪除這本相簿嗎?" + front_end: + albums: 相簿前台 album_not_found: 找不到此相簿 pic_not_found: 找不到該照片 save: 儲存 @@ -33,6 +35,8 @@ zh_tw: set_cover: 設為封面 sure?: "你確定嗎?" no_description: 沒有描述 + widget: + widget1: Widget1 widget_option: horizontal: 水平圖片數量 vertical: 垂直圖片數量 diff --git a/vendor/built_in_modules/gallery/init.rb b/vendor/built_in_modules/gallery/init.rb index 3e7fa6339..615d65930 100644 --- a/vendor/built_in_modules/gallery/init.rb +++ b/vendor/built_in_modules/gallery/init.rb @@ -11,7 +11,9 @@ module Gallery update_info 'some update_info' front_end do - app_page 'albums' + app_page 'albums' do + frontend_i18n "gallery.front_end.albums" + end end category ["gallery_categories"] @@ -25,8 +27,17 @@ module Gallery categories_query 'GalleryCategory.all' # tags_query 'GalleryTag.all' - customize_widget "albums","gallery.widget.albums",:fields=>[],:style=>[] - + #* customize_widget "albums","gallery.widget.albums",:fields=>[],:style=>[],:options=>{"widget1"=>{"vertical"=>[1, 2], "horizontal"=>[1, 2, 3, 4, 5, 6], "album_id"=>{"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name}}} + #* customize_widget_options_fields_i18n({"widget1"=>{"vertical"=>"gallery.widget_option.vertical", "horizontal"=>"gallery.widget_option.horizontal", "album_id"=>"gallery.widget_option.album"}} ) + + customize_widget "widget1" do + widget_i18n "gallery.widget.widget1" + style [] + options "vertical",:i18n => "gallery.widget_option.vertical",:options_item=>[1, 2] + options "horizontal",:i18n => "gallery.widget_option.horizontal",:options_item=>[1, 2,3,4,5,6] + options "album_id",:i18n =>"gallery.widget_option.album",:options_item => {"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name} + end + end side_bar do diff --git a/vendor/built_in_modules/miss_module/config/locales/zh_tw.yml b/vendor/built_in_modules/miss_module/config/locales/zh_tw.yml index 18cbc7603..aeea83c6a 100644 --- a/vendor/built_in_modules/miss_module/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/miss_module/config/locales/zh_tw.yml @@ -7,8 +7,8 @@ zh_tw: calendar: 日曆模組 calendars: 日曆 gallery: 相簿 - location: Location - + location: (未命名)Location + ad_banner: 廣告輪播 miss_plugin_i18n: personal_book: Personal Book diff --git a/vendor/built_in_modules/personal_book/init.rb b/vendor/built_in_modules/personal_book/init.rb index b362fedc6..47bff5bd4 100644 --- a/vendor/built_in_modules/personal_book/init.rb +++ b/vendor/built_in_modules/personal_book/init.rb @@ -1,6 +1,6 @@ module PersonalBook OrbitApp.registration "Book",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_book' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_book/plugin/profile",:i18n=>'miss_module_i18n.personal_book' diff --git a/vendor/built_in_modules/personal_diploma/init.rb b/vendor/built_in_modules/personal_diploma/init.rb index 0147cbf88..adf2ce23f 100644 --- a/vendor/built_in_modules/personal_diploma/init.rb +++ b/vendor/built_in_modules/personal_diploma/init.rb @@ -1,6 +1,6 @@ module PersonalDiploma OrbitApp.registration "Diploma",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_diploma' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_diploma/plugin/profile",:i18n=>'miss_plugin_i18n.personal_diploma' diff --git a/vendor/built_in_modules/personal_experience/init.rb b/vendor/built_in_modules/personal_experience/init.rb index 0afedc1ce..b1cc47a28 100644 --- a/vendor/built_in_modules/personal_experience/init.rb +++ b/vendor/built_in_modules/personal_experience/init.rb @@ -1,5 +1,6 @@ module PersonalExperience OrbitApp.registration "Experience",:type=> 'ModuleApp' do + module_label 'miss_plugin_i18n.personal_experience' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_experience/plugin/profile",:i18n=>'miss_plugin_i18n.personal_experience' diff --git a/vendor/built_in_modules/personal_honor/init.rb b/vendor/built_in_modules/personal_honor/init.rb index 7d2de98ab..7c27a3593 100644 --- a/vendor/built_in_modules/personal_honor/init.rb +++ b/vendor/built_in_modules/personal_honor/init.rb @@ -1,6 +1,6 @@ module PersonalHonor OrbitApp.registration "Honor",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_honor' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_honor/plugin/profile",:i18n=>'miss_plugin_i18n.personal_honor' diff --git a/vendor/built_in_modules/personal_journal/init.rb b/vendor/built_in_modules/personal_journal/init.rb index 8fdd17875..42e8bdc3a 100644 --- a/vendor/built_in_modules/personal_journal/init.rb +++ b/vendor/built_in_modules/personal_journal/init.rb @@ -1,6 +1,6 @@ module PersonalJournal OrbitApp.registration "Journal",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_journal' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_journal/plugin/profile",:i18n=>'miss_plugin_i18n.personal_journal' diff --git a/vendor/built_in_modules/personal_lab/init.rb b/vendor/built_in_modules/personal_lab/init.rb index a01aced86..989dc90fb 100644 --- a/vendor/built_in_modules/personal_lab/init.rb +++ b/vendor/built_in_modules/personal_lab/init.rb @@ -1,6 +1,6 @@ module PersonalLab OrbitApp.registration "Lab",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_lab' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_lab/plugin/profile",:i18n=>'miss_plugin_i18n.personal_lab' diff --git a/vendor/built_in_modules/personal_patent/init.rb b/vendor/built_in_modules/personal_patent/init.rb index 7587fff0b..ff12d6392 100644 --- a/vendor/built_in_modules/personal_patent/init.rb +++ b/vendor/built_in_modules/personal_patent/init.rb @@ -1,6 +1,6 @@ module PersonalPatent OrbitApp.registration "Patent",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_patent' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_patent/plugin/profile",:i18n=>'miss_plugin_i18n.personal_patent' diff --git a/vendor/built_in_modules/personal_project/init.rb b/vendor/built_in_modules/personal_project/init.rb index db357d430..b0b8d69e4 100644 --- a/vendor/built_in_modules/personal_project/init.rb +++ b/vendor/built_in_modules/personal_project/init.rb @@ -1,6 +1,6 @@ module PersonalProject OrbitApp.registration "Research Project",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_project' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_project/plugin/profile",:i18n=>'miss_plugin_i18n.personal_project' diff --git a/vendor/built_in_modules/personal_research/init.rb b/vendor/built_in_modules/personal_research/init.rb index 96e8f7a0a..5787cd05b 100644 --- a/vendor/built_in_modules/personal_research/init.rb +++ b/vendor/built_in_modules/personal_research/init.rb @@ -1,6 +1,6 @@ module PersonalResearch OrbitApp.registration "Research",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_research' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_research/plugin/profile",:i18n=>'miss_plugin_i18n.personal_research' diff --git a/vendor/built_in_modules/personal_seminar/init.rb b/vendor/built_in_modules/personal_seminar/init.rb index 5aa57aeb2..b66d9d768 100644 --- a/vendor/built_in_modules/personal_seminar/init.rb +++ b/vendor/built_in_modules/personal_seminar/init.rb @@ -1,6 +1,6 @@ module PersonalSeminar OrbitApp.registration "Seminar",:type=> 'ModuleApp' do - + module_label 'miss_plugin_i18n.personal_seminar' base_url File.expand_path File.dirname(__FILE__) personal_plugin :enable => true,:path=>"panel/personal_seminar/plugin/profile",:i18n=>'miss_plugin_i18n.personal_seminar' diff --git a/vendor/built_in_modules/web_resource/init.rb b/vendor/built_in_modules/web_resource/init.rb index 3362849a2..abbf2332b 100644 --- a/vendor/built_in_modules/web_resource/init.rb +++ b/vendor/built_in_modules/web_resource/init.rb @@ -21,8 +21,9 @@ module WebResource categories_query 'BulletinCategory.all' tags_query 'WebResourceTag.all' - customize_widget "home_list","web_resource.widget.home_list" - + customize_widget "home_list" do + widget_i18n "web_resource.widget.home_list" + end end side_bar do