From 3476237fa77af33afdaca99fe3efb97bd80a436a Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Mon, 1 Apr 2013 17:06:10 +0800 Subject: [PATCH 1/2] solved conflicts --- app/assets/javascripts/page_edit.js.erb | 32 +-- .../admin/page_parts_controller.rb | 129 +++++------ app/controllers/admin/pages_controller.rb | 209 ++++++++++-------- app/controllers/default_widget_controller.rb | 9 +- .../admin/frontend_widget_interface.rb | 59 +++++ app/helpers/admin/page_parts_helper.rb | 42 ++-- app/models/module_app.rb | 7 +- app/models/page.rb | 5 +- .../admin/module_apps/_app_selector.html.erb | 2 +- .../_custom_widget_setting.html.erb | 6 +- .../_default_widget_setting.html.erb | 4 +- .../_default_widget_style_panel.html.erb | 10 +- .../admin/page_parts/_module_widget.html.erb | 5 +- .../page_parts/_widget_ext_options.html.erb | 6 +- .../page_parts/reload_widget_field.js.erb | 2 +- .../admin/page_parts/reload_widgets.js.erb | 4 +- .../pages/_custom_frontend_setting.html.erb | 2 +- .../admin/pages/_data_count_field.html.erb | 2 +- app/views/admin/pages/_form.html.erb | 14 +- .../admin/pages/_frontend_fields.html.erb | 2 +- .../admin/pages/reload_frontend_pages.js.erb | 8 +- .../admin/pages/reload_widget_field.js.erb | 2 +- app/views/default_widget/_typeA.html.erb | 8 +- app/views/default_widget/_typeB.html.erb | 4 +- app/views/default_widget/_typeC.html.erb | 4 +- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + config/mongoid.yml | 2 +- 28 files changed, 316 insertions(+), 265 deletions(-) create mode 100644 app/helpers/admin/frontend_widget_interface.rb diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index 3ab9c18c0..f2b8722f0 100644 --- a/app/assets/javascripts/page_edit.js.erb +++ b/app/assets/javascripts/page_edit.js.erb @@ -1,5 +1,10 @@ -function get_part_id(){ - return $(".edit_page_part,.edit_page").attr("action").split('/').pop(); +function append_id(){ + if ($("#object_id").length == 1) { + return "&id="+$("#object_id").val(); + } + else{ + return ''; + }; } $("div.editable").live("mouseenter mouseleave", function (event) { @@ -7,37 +12,24 @@ $("div.editable").live("mouseenter mouseleave", function (event) { }); $("#page_design").live('change', function() { - $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_themes'); + $.getScript($(this).attr('rel') + '?design_id=' + $(this).val() + append_id()); }); -// $("#page_module_app_id").live('change', function() { -// var app_id = $(this).val(); -// if(app_id!=''){ -// $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_after_module_changed',function(data, textStatus){ -// if(textStatus == 'success'){ -// $(this).after(data); -// } -// }); -// } -// else{ -// $("#app_page_url").children().remove(); -// } -// }); $("#module_app_list select").live('change', function() { - $.getScript($(this).attr('rel') + '?module_app_id='+$(this).val()); //?part_id=' + get_part_id()); + $.getScript($(this).attr('rel') + '?module_app_id='+$(this).val() + append_id()); }); $("#widget_list select,#frontend_list select").live('change', function() { - $.getScript($(this).attr('rel') +'?frontend=' + $(this).val() + '&module_app_id=' + $("#module_app_list select").val() );//+ '&part_id=' + get_part_id()); + $.getScript($(this).attr('rel') +'?frontend=' + $(this).val() + '&module_app_id=' + $("#module_app_list select").val() + append_id() ); }); $("#tag_list select").live('change', function() { - $.getScript($(this).attr('rel') + '?type=' + $(this).val()); + $.getScript($(this).attr('rel') + '?type=' + $(this).val() + append_id() ); }); $("select.widget_field_select").live('change', function() { - $.getScript($(this).attr('rel') + '?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri')+ '&module_app_id=' +$("#page_module_app_id,page_part_module_app_id").val()); + $.getScript($(this).attr('rel') + '?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri')+ '&module_app_id=' +$("#page_module_app_id,page_part_module_app_id").val() + append_id() ); }); $('.part_kind').live('click', function() { diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index ed1374ccf..d4f439c9b 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -1,7 +1,6 @@ class Admin::PagePartsController < OrbitBackendController - + include Admin::FrontendWidgetInterface layout "site_editor" - before_filter :authenticate_user! before_filter :is_admin? before_filter :set_current_item @@ -18,59 +17,75 @@ class Admin::PagePartsController < OrbitBackendController end end - def new - - end def edit @part = PagePart.find(params[:id]) - @module_apps = ModuleApp.where(:key.in=>OrbitApp::Module::WidgetUtility.all.keys).order_by(:title, :asc) - @module_app = @part.module_app ? @part.module_app : nil - @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 - 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 - + @module_apps = ModuleApp.for_widget_select + @categories = nil + @tags = nil + @page_frontend_data_counts = nil + # @frontend_styles = nil - 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 + @selected={ + :module_app=> @part.module_app ? @part.module_app : nil, + :app_frontend_url=> @part.widget_path, #@module_apps.first + :category=>nil, #fetch by method: get_categories_and_tags + :tag=>nil, #fetch by method: get_categories_and_tags + :page_frontend_data_count=>nil, + :frontend_style => nil, + :widget_path=> nil + } + @selected[:widget_path] = @part.widget_path ? @part.widget_path : (@selected[:module_app].widgets.keys[0] rescue nil) + get_categories_and_tags + get_frontend_data_count + @app_frontend_urls = get_app_frontend_urls end - def create + def reload_widgets + @part = PagePart.find params[:id] + @selected={ + :module_app=> ModuleApp.find(params["module_app_id"]) + } + get_categories_and_tags + get_frontend_data_count + @selected[:app_frontend_url] = @selected[:module_app].has_default_widget? ? 'default_widget' : @selected[:module_app].widget_options.first.name + end + + def reload_widget_styles + @part = PagePart.find(params[:id]) + @selected={ + :module_app=> ModuleApp.find(params["module_app_id"]), + :app_frontend_url=> params["frontend"], #@module_apps.first + :category=>nil, #fetch by method: get_categories_and_tags + :tag=>nil, #fetch by method: get_categories_and_tags + :page_frontend_data_count=>nil, + :frontend_style => nil, + :widget_path=> nil + } + get_categories_and_tags + get_frontend_data_count + end + + def reload_widget_field + @index = params[:field_seri].to_i + @part = PagePart.find(params[:id]) + @selected = { + :module_app=> ModuleApp.find(params["module_app_id"]), + :default_widget_field=>params[:widget_field_value] + } end def update @part = PagePart.find(params[:id]) - # params[:page_part][:widget_field_type] = nil - # params[:page_part][:widget_field_is_link] = nil - if params[:page_part][:module_app].blank? - params[:page_part][:module_app] = nil - end - - if params[:page_part][:tag].nil? || params[:page_part][:tag].include?("nil") - params[:page_part][:tag] = [] - end - - if params[:page_part][:category].nil? || params[:page_part][:category].include?("nil") - params[:page_part][:category] = [] - end + clean_tags_and_category_params # params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank? if @part.update_attributes(params[:page_part]) @@ -101,41 +116,6 @@ class Admin::PagePartsController < OrbitBackendController redirect_to admin_items_url( :parent_id => @item.parent_id ) end - def reload_widget_field - @index = params[:field_seri].to_i - @part = PagePart.find params[:id] - @choosen_field = params[:widget_field_value] - @module_app = @part.module_app - @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil? - end - - def reload_widgets - @part = PagePart.find params[:id] - @module_app = ModuleApp.find(params[:module_app_id]) rescue nil - @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? ) - - @part.widget_path = @module_app.widgets.first if( @module_app) - respond_to do |format| - format.js {} - end - end - - def reload_widget_styles - @module_app = ModuleApp.find(params[:module_app_id]) - - @part = PagePart.find params[:id] - @user_choose =@widget_path= params[:frontend] - @widget_style = @module_app.widgets[@widget_path] - - - respond_to do |format| - format.js {} - end - end - def reload_r_tag_options @part = PagePart.find params[:id] @r_tag = params[:type] @@ -146,6 +126,11 @@ class Admin::PagePartsController < OrbitBackendController end protected + def get_app_frontend_urls + @selected[:module_app] ? @selected[:module_app].widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} : [] + # has_old_value = @selected[:module_app].app_pages[@selected[:app_frontend_url]] + # @frontend_styles = has_old_value ? has_old_value["style"] : (@selected[:module_app].app_pages.first[1]["style"] rescue nil) + end def set_children_sub_menu(part) part.page.children.each do |child| diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 7d6de9975..424a3ae42 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -1,5 +1,6 @@ class Admin::PagesController < Admin::ItemsController helper Admin::PagePartsHelper +include Admin::FrontendWidgetInterface def show @item = Page.find(params[:id]) respond_to do |format| @@ -13,40 +14,123 @@ helper Admin::PagePartsHelper def new @item = Page.new @item.parent = Item.find(params[:parent_id]) rescue nil - @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys) - @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) + # @apps = ModuleApp.for_frontend_select + @designs = Design.all.entries - @design = Design.first + @themes = Design.first.themes + @module_apps = ModuleApp.for_frontend_select + @app_frontend_urls = nil + @categories = nil + @tags = nil + @page_frontend_data_counts = nil + @frontend_styles = nil + @selected={ + :design => @designs.first, + :theme=> @themes.first, + :module_app=>nil,#@module_apps.first + :app_frontend_url=> nil, #@module_apps.first + :category=>nil, + :tag=>nil, + :page_frontend_data_count=>nil, + :frontend_style => nil + } end def edit @item = Page.find(params[:id]) - @user_choose = @item.app_frontend_url - @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys) - @module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) - + @designs = Design.all.entries - @design = @item.design ? @item.design : @designs.first + @themes = @item.design ? @item.design.themes : @designs.first.themes + @module_apps = ModuleApp.for_frontend_select + @categories = nil + @tags = nil + @page_frontend_data_counts = nil + @frontend_styles = nil - if @item.module_app - @app_frontend_urls = [] - setup_app_frontend_and_style - @app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if @item.module_app.has_default_widget? + @selected={ + :design => @item.design || @designs.first, + :theme=> @item.theme, + :module_app=>@item.module_app,#@module_apps.first + :app_frontend_url=> @item.app_frontend_url, #@module_apps.first + :category=>nil, #fetch by method: get_categories_and_tags + :tag=>nil, #fetch by method: get_categories_and_tags + :page_frontend_data_count=>nil, + :frontend_style => nil + } + @app_frontend_urls = @item.module_app ? select_array_for_app_frontend_urls(@item.module_app.app_pages) : nil + get_categories_and_tags + get_frontend_data_count + end - @module_app = @item.module_app - @frontend_path = @item.app_frontend_url - - if @module_app && @module_app.widgets && @module_app.widgets.any?{|b| b.class == Array} - @frontend_style = @module_app.widgets[@frontend_path] if !@frontend_path.blank? && !@module_app.widgets.blank? - end - get_categories_and_tags - - else - @module_app = @module_apps[0] + def reload_themes + design = Design.find(params[:design_id]) + @themes = design.themes + respond_to do |format| + format.js {} end end + def reload_frontend_pages + @item = Page.find(params[:id]) rescue Page.new + @selected={ + :design => nil, + :theme=> nil, + :module_app=>(ModuleApp.find(params[:module_app_id]) rescue nil), + :app_frontend_url=> @item.app_frontend_url || 'default_widget', #@module_apps.first + :category=>nil, #fetch by method: get_categories_and_tags + :tag=>nil, #fetch by method: get_categories_and_tags + :page_frontend_data_count=>nil, + :frontend_style => nil + } + @app_frontend_urls = @selected[:module_app] ? select_array_for_app_frontend_urls(@selected[:module_app].app_pages) : nil + + get_categories_and_tags + get_frontend_data_count + get_frontend_styles + + respond_to do |format| + format.js {} + end + end + + + def reload_front_end_setting + @item = Page.find(params[:id]) rescue Page.new + + @categories = nil + @tags = nil + @page_frontend_data_counts = nil + + @selected={ + # :design => @item.design || @designs.first, + # :theme=> @item.theme, + :module_app=>ModuleApp.find(params[:module_app_id]), + :app_frontend_url=> params[:frontend] , + :category=>nil, #fetch by method: get_categories_and_tags + :tag=>nil, #fetch by method: get_categories_and_tags + :page_frontend_data_count=>nil, + :frontend_style => nil + } + @app_frontend_urls = @selected[:module_app].nil? ? nil : @selected[:module_app].app_pages.each{|name,data| [I18n.t(data["i18n"]),name]} + @frontend_styles = @selected[:module_app].app_pages[params["frontend"]]["style"] rescue nil + + end + + + def reload_widget_field + @index = params[:field_seri].to_i + @item = Page.find(params[:id]) rescue Page.new + @selected = { + :module_app=> (@item.module_app || ModuleApp.find(params[:module_app_id]) ), + :default_widget_field=>params[:widget_field_value] + } + # @choosen_field = params[:widget_field_value] + # @module_app = @item.module_app + # @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil? + end + def create + clean_tags_and_category_params @item = Page.new(params[:page]) if @item.module_app && @item.module_app.key == 'page_content' @@ -63,7 +147,6 @@ helper Admin::PagePartsHelper end else flash.now[:error] = t('create.error.page') - @apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys) @designs = Design.all.entries @design = Design.first render :action => "new" @@ -71,27 +154,12 @@ helper Admin::PagePartsHelper end def update + clean_tags_and_category_params @item = Page.find(params[:id]) if @item.module_app && @item.module_app.key == 'page_content' && @item.page_contexts.blank? @item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id ) end - - # params[:page][:frontend_field] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type], params[:page][:frontend_field_is_link] ) if params[:page][:frontend_field] - - # params[:page][:frontend_field_type] = nil - # params[:page][:frontend_field_is_link] = nil - - if params[:page][:tag].nil? || params[:page][:tag].include?("nil") - params[:page][:tag] = [] - end - - if params[:page][:category].nil? || params[:page][:category].include?("nil") - params[:page][:category] = [] - end - - # params[:page][:frontend_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page][:frontend_field].blank? - if @item.update_attributes(params[:page]) flash[:notice] = t('update.success.page') @@ -126,65 +194,10 @@ helper Admin::PagePartsHelper end end - def reload_front_end_setting - @item = Page.find params[:id] rescue nil - @module_app = ModuleApp.find params[:module_app_id] - @user_choose = params[:frontend] #choosen frontend + protected - @app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages.each{|name,data| [I18n.t(data["i18n"]),name]} - @frontend_styles = @module_app.app_pages[params["frontend"]]["style"] rescue nil - # ======= - # @chosen_frontend = @user_choose = params[:frontend] - # >>>>>>> Stashed changes - end - - def get_categories_and_tags - unless @module_app.nil? - @categories = @module_app.get_categories - @tags = @module_app.get_tags - end + def get_frontend_styles + has_old_value = @selected[:module_app].app_pages[@selected[:app_frontend_url]] + @frontend_styles = has_old_value ? has_old_value["style"] : (@selected[:module_app].app_pages.first[1]["style"] rescue nil) end - - def setup_app_frontend_and_style - if @module_app.nil? - @item.module_app.app_pages.each{|name,data| @app_frontend_urls << [I18n.t(data["i18n"]),name]} - @frontend_styles = @item.module_app.app_pages[@item.frontend_style]["style"] if @frontend_styles.nil? && @item && @item.module_app.app_pages[@item.frontend_style] - @frontend_styles = @item.module_app.app_pages.first[1]["style"] if @frontend_styles.nil? && @item - else - @module_app.app_pages.each{|name,data| @app_frontend_urls << [I18n.t(data["i18n"]),name]} - @frontend_styles = @module_app.app_pages[params["frontend"]]["style"] rescue nil - @frontend_styles = @module_app.app_pages.first[1]["style"] if @frontend_styles.nil? - end - end - - def reload_frontend_pages - @item = Page.find params[:id] rescue nil - @module_app = ModuleApp.find(params[:module_app_id]) rescue nil - @app_frontend_urls = [] - setup_app_frontend_and_style - @app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if(@module_app && @module_app.has_default_widget?) - - get_categories_and_tags - - respond_to do |format| - format.js {} - end - end - - def reload_themes - @design = Design.find(params[:id]) - @themes = @design.themes - respond_to do |format| - format.js {} - end - end - - def reload_widget_field - @index = params[:field_seri].to_i - @item = params.has_key?(:id) ? Page.find(params[:id] ) : Page.new - @choosen_field = params[:widget_field_value] - @module_app = @page.module_app - @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil? - end - end diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index 8983084af..7fcab3d2b 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -48,11 +48,18 @@ class DefaultWidgetController< OrbitWidgetController @widget_image_field = @default_widget["image"] || @default_widget[:image] case @page_part when Page - @fields = @page_part.frontend_field + @frontend_field_names = @page_part.frontend_field_name + @frontend_classes = @page_part.frontend_class + @frontend_sat_to_links = @page_part.frontend_sat_to_link + @data_limit = @page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3) @paginate = true @page_id = @page_part.id when PagePart + @frontend_field_names = @page_part.widget_field_name + @frontend_classes = @page_part.widget_class + @frontend_sat_to_links = @page_part.widget_sat_to_link + @fields = @page_part.widget_field @data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) end diff --git a/app/helpers/admin/frontend_widget_interface.rb b/app/helpers/admin/frontend_widget_interface.rb new file mode 100644 index 000000000..66061ae8c --- /dev/null +++ b/app/helpers/admin/frontend_widget_interface.rb @@ -0,0 +1,59 @@ +module Admin::FrontendWidgetInterface + +protected + def get_categories_and_tags + unless @selected[:module_app].nil? + @categories = @selected[:module_app].get_categories + @tags = @selected[:module_app].get_tags + end + end + + def get_frontend_data_count + local_item = set_local_item + @page_frontend_data_counts = @selected[:module_app].get_registration.get_data_count rescue [] + @selected[:page_frontend_data_count] = case local_item + when PagePart + local_item.widget_data_count + when Page + local_item.frontend_data_count + end + end + + def clean_tags_and_category_params + field_name = set_field_name + + if self.class==Admin::PagePartsController and params[field_name][:module_app].blank? + params[field_name][:module_app] = nil + end + if params[field_name][:tag].nil? || params[:page][:tag].include?("nil") + params[field_name][:tag] = [] + end + + if params[field_name][:category].nil? || params[:page][:category].include?("nil") + params[field_name][:category] = [] + end + end #of clean_tags_and_category_params + + def set_local_item + local_item = @part + local_item = @item if local_item.nil? && @item + local_item + end + + def set_field_name + case self.class.to_s + when "Admin::PagesController" + return "page" + when "Admin::PagePartsController" + return "page_part" + end # of case + end + + def select_array_for_app_frontend_urls(hash) + ary = hash.collect{|name,data| [I18n.t(data["i18n"]),name]} + ary << [I18n.t('default_widget.name'),'default_widget'] if @selected[:module_app] and @selected[:module_app].has_default_widget? + ary + end + + +end \ No newline at end of file diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index afe26f80e..4d78ef4c9 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -1,7 +1,8 @@ module Admin::PagePartsHelper + include Admin::FrontendWidgetInterface def support_link - url_method = @module_app.get_default_widget[:url_method] + url_method = @selected[:module_app].get_default_widget[:url_method] unless url_method.nil? res = "Link:" res << select_tag( "page_part[widget_field_is_link][]", options_for_select([["NotLink",false],["Link1",url_method]])) @@ -9,10 +10,8 @@ module Admin::PagePartsHelper end end - def get_widget_field_rel(local_item=nil) - local_item = @part if local_item.nil? && @part - local_item = @item if local_item.nil? && @item - case local_item + def get_widget_field_rel + case set_local_item when Page reload_after_list_changed_admin_pages_path when PagePart @@ -35,7 +34,7 @@ module Admin::PagePartsHelper unless field_is_checked.nil? and assign_field_name_value.nil? origin_field = nil - origin_field = @module_app.widget_fields.select{|t| t.first.to_s==(assign_field_name_value || local_item.default_widget_field_name[i])}.first + origin_field = @selected[:module_app].widget_fields.select{|t| t.first.to_s==(assign_field_name_value || local_item.default_widget_field_name[i])}.first if origin_field and origin_field[2]==:link #choosen_field_is_link @@ -51,11 +50,10 @@ module Admin::PagePartsHelper end def widget_field_options(i,local_item=nil) - local_item = @part if local_item.nil? && @part - local_item = @item if local_item.nil? && @item + local_item = set_local_item - options = @module_app.widget_fields.collect do |widget_field| - label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}") + options = @selected[:module_app].widget_fields.collect do |widget_field| + label = I18n.t("#{@selected[:module_app].key}.default_widget.#{widget_field[0]}") [label, widget_field[0]] end case local_item @@ -66,11 +64,9 @@ module Admin::PagePartsHelper end end - def widget_fiield_class_options(i,local_item=nil) + def widget_field_class_options(i,local_item=nil) options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]} - local_item = @part if local_item.nil? && @part - local_item = @item if local_item.nil? && @item - + local_item = set_local_item case local_item when Page options_for_select(options, (local_item.frontend_class[i] if (local_item) )) @@ -115,12 +111,8 @@ module Admin::PagePartsHelper end def nil_checkbox_button(part,tag_or_cate) - field_name = case part - when PagePart - 'page_part' - when Page - 'page' - end + field_name = set_field_name + content_tag :label,:class=>"radio inline" do op = check_box_tag("#{field_name}[#{tag_or_cate}][]", 'nil' , eval("#{tag_or_cate}_checked_value(part,'')"),:class=>'select_all') op << I18n.t("default_widget.no_value") @@ -128,12 +120,8 @@ module Admin::PagePartsHelper end def nil_radio_button(part,tag_or_cate) - field_name = case part - when PagePart - 'page_part' - when Page - 'page' - end + field_name = set_field_name + content_tag :label,:class=>"radio inline" do op = radio_button(field_name, tag_or_cate, '' , :checked => eval("#{tag_or_cate}_checked_value(part,'')")) op << I18n.t("default_widget.no_value") @@ -141,7 +129,7 @@ module Admin::PagePartsHelper end def show_default_widget_setting_panel - @module_app && @module_app.has_default_widget? && (!@user_choose.nil? && @user_choose== 'default_widget') #&& @part.widget_path == 'default_widget' + @selected[:module_app] && @selected[:module_app].has_default_widget? && (@selected[:app_frontend_url]== 'default_widget') end def show_custom_widget_setting_panel diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 5aa5a11d5..d185b50c8 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -19,11 +19,10 @@ class ModuleApp self[:widgets] = reg.get_widgets end - - # def app_pages - # get_registration.get_app_pages - # end + scope :for_frontend_select,where(:key.in => OrbitApp::Module::FrontendUtility.all.keys).excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) + scope :for_widget_select,where(:key.in=>OrbitApp::Module::WidgetUtility.all.keys).order_by(:title, :asc) + scope :standard_sorting ,order_by(:title, :asc) def enable_frontend? self[:enable_frontend] diff --git a/app/models/page.rb b/app/models/page.rb index 91a76de8c..b2947ca8b 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -7,7 +7,7 @@ class Page < Item field :content, localize: true field :app_frontend_url - field :theme_id, :type => BSON::ObjectId, :default => nil + # field :theme_id, :type => BSON::ObjectId, :default => nil field :category,type: Array, :default => [] field :tag, type: Array,:default => [] field :view_count, :type => Integer, :default => 0 @@ -21,7 +21,8 @@ class Page < Item field :frontend_sat_to_link , :type => Array,:default => [] field :frontend_data_count - + + belongs_to :theme belongs_to :design belongs_to :module_app has_many :page_parts, :dependent => :destroy diff --git a/app/views/admin/module_apps/_app_selector.html.erb b/app/views/admin/module_apps/_app_selector.html.erb index 60cf2d6fa..7ce95e051 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.module_name, t.id] }, {:include_blank => true} ,{:rel => admin_module_apps_path } %> +<%= f.select :module_app_id, @module_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 998b5853c..7a3838e68 100644 --- a/app/views/admin/page_parts/_custom_widget_setting.html.erb +++ b/app/views/admin/page_parts/_custom_widget_setting.html.erb @@ -3,14 +3,14 @@ <%= t("default_widget.select_widget_style") %>
- <% if @module_app.nil? || @module_app.widgets.nil? || (@module_app.widgets[@widget_path].blank? rescue true) %> + <% if @selected[:module_app].nil? || @selected[:module_app].widgets.nil? || (@selected[:module_app].widgets[@selected[:app_frontend_url]].blank? rescue true) || @selected[:module_app].widgets[@selected[:app_frontend_url]]["style"].nil? %> <%= t("default_widget.no_support_setting")%> <%else%> - <%= select('page_part', 'widget_style', @module_app.widgets[@widget_path]["style"]) %> + <%= select('page_part', 'widget_style', @selected[:module_app].widgets[@selected[:app_frontend_url]]["style"]) %> <% end %>
- <% if(@module_app && @module_app.widget_options(@widget_path)) %> + <% if(@selected[:module_app] && @selected[:module_app].widget_options(@selected[:app_frontend_url])) %>
diff --git a/app/views/admin/page_parts/_default_widget_setting.html.erb b/app/views/admin/page_parts/_default_widget_setting.html.erb index 1cc31024e..2bb780892 100644 --- a/app/views/admin/page_parts/_default_widget_setting.html.erb +++ b/app/views/admin/page_parts/_default_widget_setting.html.erb @@ -27,14 +27,14 @@
-<% @module_app.widget_fields.each_with_index do |widget_field, i| %> +<% @selected[:module_app].widget_fields.each_with_index do |widget_field, i| %>
<%= i+1 %> <%= select_tag "#{object_name}[#{field_name}][][field_name]", widget_field_options(i), :include_blank => true ,:class=>'widget_field_select',:field_seri => i ,:id=>"#{object_name}_#{field_name}_#{i}",:rel=>reload_rel%> - <%= select_tag "#{object_name}[#{field_name}][][class]", widget_fiield_class_options(i), :include_blank => true %>
+ <%= select_tag "#{object_name}[#{field_name}][][class]", widget_field_class_options(i), :include_blank => true %>
<%= link_to_field_switch(i,object_name,field_name) %> diff --git a/app/views/admin/page_parts/_default_widget_style_panel.html.erb b/app/views/admin/page_parts/_default_widget_style_panel.html.erb index f4eb8ed2a..13892655e 100644 --- a/app/views/admin/page_parts/_default_widget_style_panel.html.erb +++ b/app/views/admin/page_parts/_default_widget_style_panel.html.erb @@ -12,7 +12,7 @@
    - <% if @module_app.get_default_widget["enabled_styles"].include?("typeA") %> + <% if @selected[:module_app].get_default_widget["enabled_styles"].include?("typeA") %>
  • <% end %> - <% if @module_app.get_default_widget["enabled_styles"].include?("typeB_style2") %> + <% if @selected[:module_app].get_default_widget["enabled_styles"].include?("typeB_style2") %>
  • <% end %> - <% if @module_app.get_default_widget["enabled_styles"].include?("typeB_style3") %> + <% if @selected[:module_app].get_default_widget["enabled_styles"].include?("typeB_style3") %>
  • <% end %> - <% if @module_app.get_default_widget["enabled_styles"].include?("typeB_style4") %> + <% if @selected[:module_app].get_default_widget["enabled_styles"].include?("typeB_style4") %>
  • <% end %> - <% if @module_app.get_default_widget["enabled_styles"].include?("typeC") %> + <% if @selected[:module_app].get_default_widget["enabled_styles"].include?("typeC") %>
  • - <%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :module_name, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => reload_after_module_changed_admin_page_part_path,:id=>"page_module_app_id"} %> + <%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :module_name, :selected => (@selected[:module_app].id rescue nil)), {:include_blank => true }, {:rel => reload_after_module_changed_admin_page_part_path,:id=>"page_module_app_id"} %>
@@ -26,7 +26,8 @@ <%= t "default_widget.select_widget_path" %>
- <%= f.select :widget_path, @module_app ? @module_app.widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} : [], {}, { :selected => @part.widget_path, :rel => get_widget_field_rel } %> + <%#= @module_app ? @module_app.widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} %> + <%= f.select :widget_path, @app_frontend_urls , {}, { :selected => @selected[:app_frontend_url], :rel => get_widget_field_rel } %>
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 6985939bb..1a9202253 100644 --- a/app/views/admin/page_parts/_widget_ext_options.html.erb +++ b/app/views/admin/page_parts/_widget_ext_options.html.erb @@ -1,4 +1,7 @@ - <% @module_app.widget_options(@widget_path).get_options.each do |key,settings| %> +<% if (not(@selected[:module_app].widget_options(@selected[:app_frontend_url]).blank?) and @selected[:app_frontend_url]!='default_widget')%> + + + <% @selected[:module_app].widget_options(@selected[:app_frontend_url]).get_options.each do |key,settings| %> <% options = settings[:opts] %> <%= label_tag(t(settings[:label_i18n]))%> <% case options%> @@ -12,3 +15,4 @@ <% end %> +<% end %> diff --git a/app/views/admin/page_parts/reload_widget_field.js.erb b/app/views/admin/page_parts/reload_widget_field.js.erb index ae8d75f22..bb44377e3 100644 --- a/app/views/admin/page_parts/reload_widget_field.js.erb +++ b/app/views/admin/page_parts/reload_widget_field.js.erb @@ -1 +1 @@ -$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page_part','widget_field',nil,@choosen_field) %>"); \ No newline at end of file +$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page_part','widget_field',nil,@selected[:default_widget_field]) %>"); \ No newline at end of file diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb index 4e1621678..c6b4ea70c 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| [I18n.t(v['i18n']),k]},@part.widget_path) %>"); +<% if @selected[:module_app]%> + $('#widget_list select').html("<%= j options_for_select(@selected[: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} %>"); $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page_part[widget_data_count]',:field_value=>@part.widget_data_count } %>"); diff --git a/app/views/admin/pages/_custom_frontend_setting.html.erb b/app/views/admin/pages/_custom_frontend_setting.html.erb index 07c89e5b6..98ded6019 100644 --- a/app/views/admin/pages/_custom_frontend_setting.html.erb +++ b/app/views/admin/pages/_custom_frontend_setting.html.erb @@ -4,7 +4,7 @@
<% if @frontend_styles%> - <%= select('page', 'frontend_style', @frontend_styles) %> + <%= select('page', 'frontend_style', @frontend_styles,{:selected => @selected[:frontend_style]}) %> <% else %> <%= t("default_widget.no_support_setting")%> <% end %> diff --git a/app/views/admin/pages/_data_count_field.html.erb b/app/views/admin/pages/_data_count_field.html.erb index 1934b0670..725b5c000 100644 --- a/app/views/admin/pages/_data_count_field.html.erb +++ b/app/views/admin/pages/_data_count_field.html.erb @@ -2,5 +2,5 @@ <%= t("default_widget.widget_data_count") %>
- <%= select_tag(field_name,options_for_select((@module_app.get_registration.get_data_count rescue []),field_value )) %> + <%= select_tag(field_name,options_for_select(@page_frontend_data_counts||[],field_value )) %>
\ No newline at end of file diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index eb4691d7b..0411162ad 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -1,13 +1,13 @@ <%= f.error_messages %> <%= f.hidden_field :parent, :value => (@item.parent.id rescue nil) %> - +<%= f.hidden_field :id, :value => (@item.id),:id=>"object_id" %>
<%= f.label :name, '*'+t(:name), :class => 'control-label' %>
<%= f.text_field :name, :class => 'text input-xlarge' %> - 請輸入數字或英文,不可使用空白 + <%= I18n.t("front_page.name_field_helper") %>
@@ -27,14 +27,14 @@
<%= f.label :name, t(:template_name), :class => 'control-label' %>
- <%= f.collection_select :design, @designs, :id, :title, {:selected => @design.id}, {:rel => reload_themes_admin_pages_path} %> + <%= f.collection_select :design, @designs, :id, :title, {:selected => (@selected[:design].id rescue nil) }, {:rel => reload_themes_admin_pages_path} %>
<%= f.label :name, t(:theme), :class => 'control-label' %>
- <%= f.select :theme_id, @design.themes.collect { |t| [t.name.capitalize, t.id] }, :include_blank => true %> + <%= f.select :theme_id, @themes.collect { |t| [t.name.capitalize, t.id] }, {:include_blank => true, :selected=>(@selected[:theme].id rescue nil) } %>
@@ -42,14 +42,14 @@
<%= f.label '',t("default_widget.select_module_app"), :class => 'control-label' %>
- <%= f.select :module_app_id, options_from_collection_for_select(@module_apps, :id, :module_name, :selected => (@module_app.id rescue nil)), {:include_blank => true }, {:rel => reload_after_module_changed_admin_pages_path,:id=>"page_module_app_id"} %> + <%= f.select :module_app_id, options_from_collection_for_select(@module_apps, :id, :module_name, :selected =>(@selected[:module_app].id rescue nil)), {:include_blank => true }, {:rel => reload_after_module_changed_admin_pages_path,:id=>"page_module_app_id"} %>
<%= f.label '', t("front_page.select_app_url"), :class => 'control-label' %>
- <%= select('page','app_frontend_url', @app_frontend_urls || [],{}, {:selected => (@item.app_frontend_url || 'default_widget'),:rel => reload_after_list_changed_admin_pages_path}) rescue ''%> + <%= select('page','app_frontend_url', @app_frontend_urls || [], {:selected => @selected[:app_frontend_url],:rel => reload_after_list_changed_admin_pages_path}) rescue ''%>
@@ -67,7 +67,7 @@
- <%= render :partial=>'data_count_field',:locals=>{:field_name=>"page[frontend_data_count]",:field_value=>@item.frontend_data_count} %> + <%= render :partial=>'data_count_field',:locals=>{:field_name=>"page[frontend_data_count]",:field_value=>@selected[:page_frontend_data_count]} %>
diff --git a/app/views/admin/pages/_frontend_fields.html.erb b/app/views/admin/pages/_frontend_fields.html.erb index 88cb0c608..07ff80d23 100644 --- a/app/views/admin/pages/_frontend_fields.html.erb +++ b/app/views/admin/pages/_frontend_fields.html.erb @@ -4,7 +4,7 @@ <% @module_app.widget_fields.each_with_index do |frontend_field, i| %> <%= i+1 %> <%= select_tag "page[frontend_field][]",widget_field_options(i,@item) , :include_blank => true %> - <%= select_tag "page[frontend_field_type][]", widget_fiield_class_options(i,@item), :include_blank => true %>
+ <%= select_tag "page[frontend_field_type][]", widget_field_class_options(i,@item), :include_blank => true %>
<% end %> <% end %> diff --git a/app/views/admin/pages/reload_frontend_pages.js.erb b/app/views/admin/pages/reload_frontend_pages.js.erb index d5e99459d..2b7856c57 100644 --- a/app/views/admin/pages/reload_frontend_pages.js.erb +++ b/app/views/admin/pages/reload_frontend_pages.js.erb @@ -1,16 +1,16 @@ -<% if @module_app %> +<% if @selected[:module_app] %> $('#app_page_category').html("<%= j render :partial => 'admin/page_parts/widget_data_source_category' ,:locals=>{:object=>@item}%>"); $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@item} %>"); $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>(@item.frontend_data_count rescue nil)} %>"); - <% if !@module_app.app_pages.blank? or @module_app.has_default_widget? %> - $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, (@item.app_frontend_url || 'default_widget')),{},{:rel => reload_after_list_changed_admin_pages_path}) %>"); + <% if !@selected[:module_app].app_pages.blank? or @selected[:module_app].has_default_widget? %> + $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, @selected[:app_frontend_url]),{},{:rel => reload_after_list_changed_admin_pages_path}) %>"); <% else %> $('#app_page_url').html("
<%= t('default_widget.no_support_setting')%>
"); <% end %> <% if @app_frontend_urls.first =='default_widget' %> - $('#app_page_frontend_style').html("<%= escape_javascript(select 'page', 'frontend_style', @module_app.widgets[@frontend_path]) if !@frontend_path.blank? %>"); + $('#app_page_frontend_style').html("<%= escape_javascript(select 'page', 'frontend_style', @selected[:module_app].widgets[@selected[:app_frontend_url]]) %>"); <% else %> $('#app_page_frontend_style').html("<%= t('default_widget.no_support_setting')%>"); <% end %> diff --git a/app/views/admin/pages/reload_widget_field.js.erb b/app/views/admin/pages/reload_widget_field.js.erb index 0f6bd1f7b..993125c24 100644 --- a/app/views/admin/pages/reload_widget_field.js.erb +++ b/app/views/admin/pages/reload_widget_field.js.erb @@ -1 +1 @@ -$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page','frontend_field',nil,@choosen_field) %>"); \ No newline at end of file +$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page','frontend_field',nil,@selected[:default_widget_field]) %>"); \ No newline at end of file diff --git a/app/views/default_widget/_typeA.html.erb b/app/views/default_widget/_typeA.html.erb index 423024840..d419554d4 100644 --- a/app/views/default_widget/_typeA.html.erb +++ b/app/views/default_widget/_typeA.html.erb @@ -3,15 +3,15 @@ - <% @fields.each do |field|%> - + <% @frontend_field_names.each_with_index do |field,index|%> + <%= content_tag(:th,content_tag(:span,get_field_header(field),:class=>@frontend_classes[index]))unless field.blank?%> <% end %> <% @data.each do |row_data| %> - <% @fields.each do |field|%> - + <% @frontend_field_names.each_with_index do |field,index|%> + <%= content_tag(:td,content_tag(:span,link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s}),:class=>@frontend_classes[index]))unless field.blank?%> <% end %> <% end %> diff --git a/app/views/default_widget/_typeB.html.erb b/app/views/default_widget/_typeB.html.erb index ff2b8bdde..e5808c3a8 100644 --- a/app/views/default_widget/_typeB.html.erb +++ b/app/views/default_widget/_typeB.html.erb @@ -6,8 +6,8 @@ <%= image_tag row_data.send(@widget_image_field)%>
- <% @fields.each do |field|%> - <%= content_tag(:span,link_to_field(row_data,field[0], field[2], {orig_page: @page_id.to_s}),:class=>field[1])%> + <% @frontend_field_names.each_with_index do |field,index|%> + <%= content_tag(:span,link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s}),:class=>@frontend_classes[index]) unless field.blank?%> <% end %>
<% end %> diff --git a/app/views/default_widget/_typeC.html.erb b/app/views/default_widget/_typeC.html.erb index 24729b088..ca246df22 100644 --- a/app/views/default_widget/_typeC.html.erb +++ b/app/views/default_widget/_typeC.html.erb @@ -5,8 +5,8 @@
    <% @data.each do |row_data| %> <%= content_tag(:li) do %> - <% @fields.each do |field|%> - <%= content_tag(:span, link_to_field(row_data,field[0], field[2], {orig_page: @page_id.to_s}),:class=>field[1])%> + <% @frontend_field_names.each_with_index do |field,index|%> + <%= content_tag(:span, link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s}),:class=>@frontend_classes[index]) unless field.blank?%> <% end %> <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 98a80e58c..2814657fd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -209,6 +209,7 @@ en: forgot_password: Forgot your password? frequency: Frequency front_page: + name_field_helper: Can not be blank select_app_url: is_published: menu_enable_lang: diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a12331f9e..58532538e 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -209,6 +209,7 @@ zh_tw: forgot_password: 忘記密碼? frequency: 頻率 front_page: + name_field_helper: 請輸入數字或英文,不可使用空白 select_app_url: 模組前台樣式 is_published: 是否公開 menu_enable_lang: 選單啓用語系 diff --git a/config/mongoid.yml b/config/mongoid.yml index ac9bf5577..2fa55a361 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -1,5 +1,5 @@ defaults: &defaults - host: 192.168.1.105 + host: localhost # slaves: # - host: slave1.local port: 27017 From 20bdeb3c2d55f6c0404ae604108c4c23c3d4aa67 Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Tue, 2 Apr 2013 18:39:46 +0800 Subject: [PATCH 2/2] fix widget and fronted setting interface. checked with Spen --- app/assets/javascripts/inc/update_cates_and_tags.js | 4 ++-- app/controllers/admin/page_parts_controller.rb | 2 +- app/controllers/admin/pages_controller.rb | 3 +-- app/helpers/admin/frontend_widget_interface.rb | 5 ++--- app/helpers/admin/page_parts_helper.rb | 1 - app/models/module_app.rb | 11 +++++++++-- .../page_parts/_default_widget_style_panel.html.erb | 1 - app/views/admin/page_parts/reload_widgets.js.erb | 4 ++-- app/views/admin/pages/reload_frontend_pages.js.erb | 6 +++--- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/inc/update_cates_and_tags.js b/app/assets/javascripts/inc/update_cates_and_tags.js index 223cd8d73..229273c18 100644 --- a/app/assets/javascripts/inc/update_cates_and_tags.js +++ b/app/assets/javascripts/inc/update_cates_and_tags.js @@ -2,11 +2,11 @@ function update_cates_and_tags() { $('.select_option,.select_all').removeAttr('disabled'); $(".select_all:checked").each(function( obj ) { - $(this).parent().siblings('label').find('.select_option').attr('disabled',true); + // $(this).parent().siblings('label').find('.select_option').attr('disabled',"disabled"); $(this).parent().siblings('label').find('.select_option').removeAttr('checked'); }); $(".select_option:checked").each(function( obj ) { - $(this).parent().siblings('label').find('.select_all').attr('disabled',true); + // $(this).parent().siblings('label').find('.select_all').attr('disabled',"disabled"); $(this).parent().siblings('label').find('.select_all').removeAttr('checked'); }); } diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index d4f439c9b..de212e50f 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -31,7 +31,7 @@ class Admin::PagePartsController < OrbitBackendController @selected={ :module_app=> @part.module_app ? @part.module_app : nil, - :app_frontend_url=> @part.widget_path, #@module_apps.first + :app_frontend_url=> @part.widget_path || "default_widget", #@module_apps.first :category=>nil, #fetch by method: get_categories_and_tags :tag=>nil, #fetch by method: get_categories_and_tags :page_frontend_data_count=>nil, diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 424a3ae42..837994e99 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -121,7 +121,7 @@ include Admin::FrontendWidgetInterface @index = params[:field_seri].to_i @item = Page.find(params[:id]) rescue Page.new @selected = { - :module_app=> (@item.module_app || ModuleApp.find(params[:module_app_id]) ), + :module_app=> (ModuleApp.find(params[:module_app_id]) || @item.module_app ), :default_widget_field=>params[:widget_field_value] } # @choosen_field = params[:widget_field_value] @@ -160,7 +160,6 @@ include Admin::FrontendWidgetInterface if @item.module_app && @item.module_app.key == 'page_content' && @item.page_contexts.blank? @item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id ) end - if @item.update_attributes(params[:page]) flash[:notice] = t('update.success.page') respond_to do |format| diff --git a/app/helpers/admin/frontend_widget_interface.rb b/app/helpers/admin/frontend_widget_interface.rb index 66061ae8c..a9efe45be 100644 --- a/app/helpers/admin/frontend_widget_interface.rb +++ b/app/helpers/admin/frontend_widget_interface.rb @@ -21,15 +21,14 @@ protected def clean_tags_and_category_params field_name = set_field_name - if self.class==Admin::PagePartsController and params[field_name][:module_app].blank? params[field_name][:module_app] = nil end - if params[field_name][:tag].nil? || params[:page][:tag].include?("nil") + if params[field_name][:tag].nil? || params[field_name][:tag].include?("nil") params[field_name][:tag] = [] end - if params[field_name][:category].nil? || params[:page][:category].include?("nil") + if params[field_name][:category].nil? || params[field_name][:category].include?("nil") params[field_name][:category] = [] end end #of clean_tags_and_category_params diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index 4d78ef4c9..59eb99718 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -33,7 +33,6 @@ module Admin::PagePartsHelper unless field_is_checked.nil? and assign_field_name_value.nil? origin_field = nil - origin_field = @selected[:module_app].widget_fields.select{|t| t.first.to_s==(assign_field_name_value || local_item.default_widget_field_name[i])}.first if origin_field and origin_field[2]==:link #choosen_field_is_link diff --git a/app/models/module_app.rb b/app/models/module_app.rb index d185b50c8..80b216136 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -20,10 +20,17 @@ class ModuleApp end - scope :for_frontend_select,where(:key.in => OrbitApp::Module::FrontendUtility.all.keys).excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) - scope :for_widget_select,where(:key.in=>OrbitApp::Module::WidgetUtility.all.keys).order_by(:title, :asc) + # scope :for_frontend_select, scope :standard_sorting ,order_by(:title, :asc) + def self.for_widget_select + where(:key.in=>OrbitApp::Module::WidgetUtility.all.keys).order_by(:title, :asc) + end + + def self.for_frontend_select + where(:key.in => OrbitApp::Module::FrontendUtility.all.keys).excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc) + end + def enable_frontend? self[:enable_frontend] end diff --git a/app/views/admin/page_parts/_default_widget_style_panel.html.erb b/app/views/admin/page_parts/_default_widget_style_panel.html.erb index 13892655e..1c1d9ba8e 100644 --- a/app/views/admin/page_parts/_default_widget_style_panel.html.erb +++ b/app/views/admin/page_parts/_default_widget_style_panel.html.erb @@ -5,7 +5,6 @@ <% when PagePart %> <% field_name = "page_part[widget_style]" %> <% end %> -
<%= content_tag(:span,get_field_header(field[0]),:class=>field[1])%>
<%= content_tag(:span,link_to_field(row_data,field[0], field[2], {orig_page: @page_id.to_s}),:class=>field[1])%>