diff --git a/app/controllers/admin/object_auths_controller.rb b/app/controllers/admin/object_auths_controller.rb index dab659b4..d407d3db 100644 --- a/app/controllers/admin/object_auths_controller.rb +++ b/app/controllers/admin/object_auths_controller.rb @@ -1,5 +1,5 @@ class Admin::ObjectAuthsController < ApplicationController - include OrbitCoreLib::PermissionUnility + include OrbitCoreLib::PermissionUtility layout "new_admin" before_filter :force_order # before_filter :is_admin? ,:only => :index diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index 7e0763ff..33c0dfe8 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -1,5 +1,5 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController - include OrbitCoreLib::PermissionUnility + include OrbitCoreLib::PermissionUtility before_filter :force_order def set_module_app diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index f4672800..a188ce1b 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -28,27 +28,29 @@ class Admin::PagePartsController < ApplicationController @module_app = @part.module_app ? @part.module_app : @module_apps[0] @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_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 - case @module_app.key - when 'announcement' - @categories = BulletinCategory.all - @tags = AnnouncementTag.all - when 'news' - @categories = NewsBulletinCategory.all - @tags = NewsTag.all - when 'web_resource' - @categories = WebLinkCategory.all - @tags = WebResourceTag.all - when 'archive' - @categories = ArchiveFileCategory.all - @tags = ArchiveTag.all - end + # case @module_app.key + # when 'announcement' + # @categories = BulletinCategory.all + # @tags = AnnouncementTag.all + # when 'news' + # @categories = NewsBulletinCategory.all + # @tags = NewsTag.all + # when 'web_resource' + # @categories = WebLinkCategory.all + # @tags = WebResourceTag.all + # when 'archive' + # @categories = ArchiveFileCategory.all + # @tags = ArchiveTag.all + # end end def create @@ -60,7 +62,7 @@ class Admin::PagePartsController < ApplicationController params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type] ) if params[:page_part][:widget_field] params[:page_part][:widget_field_type] = nil - + if @part.update_attributes(params[:page_part]) set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu') flash.now[:notice] = t('update.success.content') @@ -95,7 +97,7 @@ class Admin::PagePartsController < ApplicationController @widget_path = @module_app.widgets.keys[0] if ( @module_app.widgets[0].blank? ) - @widget_style = @module_app.widgets[@widget_path] if ( !@widget_path.blank? ) + @widget_style = @module_app.get_widget_style[@widget_path][:style] unless @widget_path.nil? case @module_app.key when 'announcement' @@ -119,8 +121,9 @@ class Admin::PagePartsController < ApplicationController def reload_widget_styles @module_app = ModuleApp.find(params[:module_app_id]) - @widget_style = @module_app.widgets[params[:id]] - + style_ary = @module_app.get_widget_style[params[:id]] + @widget_style = style_ary[:style] unless style_ary.nil? + respond_to do |format| format.js {} end diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb new file mode 100644 index 00000000..6997840b --- /dev/null +++ b/app/controllers/default_widget_controller.rb @@ -0,0 +1,43 @@ +class DefaultWidgetController< OrbitWidgetController + + def front_end_available(var) + @page_part = PagePart.find params[:part_id] + @page_part.module_app.enable_frontend? + end + + def default_widget + @tag_class = nil + + @default_widget = @page_part.module_app.get_default_widget + @widget_image_field = @default_widget[:image] + data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) + @data = eval(@default_widget[:query]).limit(data_limit).includes(@widget_image_field) + @fields = @page_part.widget_field + + case params[:type] + when "typeA" + @tag_class = 'defulat_widget_typeA' + render "typeA" + when /typeB_/ + @tag_class = "defulat_widget_#{params[:type]}" + render "typeB" + when "typeC" + @tag_class = 'defulat_widget_typeC' + render "typeC" + end + + + + # {"inner"=>"true", + # "category_id"=>"false", + # "tag_id"=>"", + # "page"=>"", + # "search_query"=>"", + # "part_title"=>"", + # "part_id"=>"50ac426f83e75219d20000a7", + # "controller"=>"default_widget", + # "action"=>"default_widget", + # "type"=>"typeA"} + end + +end diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 530415ba..ce6640a8 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -1,41 +1,11 @@ class OrbitBackendController < ApplicationController - #before_filter :setup_vars - #before_filter :set_current_user - - # before_filter {|c| c.front_end_available(@app_title)} - # before_filter :check_user_can_use - include OrbitCoreLib::PermissionUnility + include OrbitCoreLib::AppBackendUtility + include OrbitCoreLib::PermissionUtility include AdminHelper include ApplicationHelper layout 'new_admin' - def setup_vars - @app_title ||= controller_path.split('/')[1].singularize - @module_app ||= ModuleApp.first(conditions: {:key => @app_title} ) - end - - private - - def force_order_for_visitor - setup_vars - set_current_user - end - - - def force_order_for_user - setup_vars - set_current_user - authenticate_user! - check_user_can_use - end - - def check_user_can_use - unless check_permission - #redirect_to polymorphic_path(['panel',@app_title,'back_end','public']) - redirect_to root_url - end - end def get_sorted_and_filtered(object_class, query=nil) objects = get_objects(object_class, query) diff --git a/app/controllers/orbit_frontend_controller.rb b/app/controllers/orbit_frontend_controller.rb index e1be8167..386b8cda 100644 --- a/app/controllers/orbit_frontend_controller.rb +++ b/app/controllers/orbit_frontend_controller.rb @@ -1,3 +1,4 @@ class OrbitFrontendController< OrbitFrontendComponentController + end \ No newline at end of file diff --git a/app/controllers/orbit_widget_controller.rb b/app/controllers/orbit_widget_controller.rb index 47e24fe0..f006cd43 100644 --- a/app/controllers/orbit_widget_controller.rb +++ b/app/controllers/orbit_widget_controller.rb @@ -1,3 +1,4 @@ class OrbitWidgetController< OrbitFrontendComponentController + end \ No newline at end of file diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 120e1245..7cb28b96 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -16,7 +16,7 @@ module AdminHelper end def is_admin? - current_or_guest_user.admin? + current_or_guest_user.admin? rescue false end def is_member? diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 22fb4814..b64ac908 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -1,7 +1,7 @@ class ModuleApp include Mongoid::Document include Mongoid::Timestamps - include OrbitCoreLib::ObjectTokenUnility + include OrbitCoreLib::ObjectTokenUtility field :key field :title @@ -21,9 +21,17 @@ class ModuleApp OrbitApp::Module::Registration.find_by_key(key) end - # %w{label_i18n }.each do |field| - # define_method(field){|var| get_registration.send("get_#{m}") } - # end + %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 def label_i18n reg = get_registration @@ -38,10 +46,20 @@ class ModuleApp !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 - ary = widgets.collect{|k,v| [I18n.t(v["label"]),k]} - ary << [I18n.t('widget.default_widget'),'default_widget']if using_default_widget? + 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 end def is_manager?(user) diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index 6c7405ca..f2ef5c04 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -1,5 +1,5 @@ class ObjectAuth < PrototypeAuth - include OrbitCoreLib::ObjectTokenUnility + include OrbitCoreLib::ObjectTokenUtility validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id] #{ |c| } belongs_to :obj_authable, polymorphic: true after_save :check_user_has_can_access_app diff --git a/app/views/admin/page_parts/reload_widget_styles.js.erb b/app/views/admin/page_parts/reload_widget_styles.js.erb index 41b2ad9c..051108d6 100644 --- a/app/views/admin/page_parts/reload_widget_styles.js.erb +++ b/app/views/admin/page_parts/reload_widget_styles.js.erb @@ -1 +1,5 @@ -$('#widget_style_list select').html("<%= j options_for_select(@module_app.widgets[params[:id]]) %>") +<% if @widget_style.nil? %> + $('#widget_style_list select').html("") +<% else %> + $('#widget_style_list select').html("<%= j options_for_select(@widget_style) %>") +<% end %> diff --git a/app/views/default_widget/typeA.html.erb b/app/views/default_widget/typeA.html.erb new file mode 100644 index 00000000..22422516 --- /dev/null +++ b/app/views/default_widget/typeA.html.erb @@ -0,0 +1,19 @@ +<%= content_tag :div,:class=>@tag_class do%> +