diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index 09326600b..3ab9c18c0 100644 --- a/app/assets/javascripts/page_edit.js.erb +++ b/app/assets/javascripts/page_edit.js.erb @@ -2,12 +2,6 @@ function get_part_id(){ return $(".edit_page_part,.edit_page").attr("action").split('/').pop(); } -function get_object_path(){ - a = window.location.href.split('/'); - a.pop(); - return a.join('/'); -} - $("div.editable").live("mouseenter mouseleave", function (event) { $(this).children('.edit_link').toggle(); }); @@ -31,11 +25,11 @@ $("#page_design").live('change', function() { // }); $("#module_app_list select").live('change', function() { - $.getScript(get_object_path() + '/reload_after_module_changed?module_app_id='+$(this).val()); //?part_id=' + get_part_id()); + $.getScript($(this).attr('rel') + '?module_app_id='+$(this).val()); //?part_id=' + get_part_id()); }); $("#widget_list select,#frontend_list select").live('change', function() { - $.getScript(get_object_path() +'/reload_after_list_changed?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() );//+ '&part_id=' + get_part_id()); }); $("#tag_list select").live('change', function() { @@ -43,7 +37,7 @@ $("#tag_list select").live('change', function() { }); $("select.widget_field_select").live('change', function() { - $.getScript(get_object_path() + '/reload_after_widget_field_changed?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()); }); $('.part_kind').live('click', function() { diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index dae0bcb2e..ed1374ccf 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -56,10 +56,9 @@ class Admin::PagePartsController < OrbitBackendController def update @part = PagePart.find(params[:id]) - params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type],params[:page_part][:widget_field_is_link] ) if params[:page_part][:widget_field] - - params[:page_part][:widget_field_type] = nil - params[:page_part][:widget_field_is_link] = nil + + # 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 @@ -73,8 +72,7 @@ class Admin::PagePartsController < OrbitBackendController params[:page_part][:category] = [] end - params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank? - + # 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]) set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu') flash.now[:notice] = t('update.success.content') diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index a48728451..7d6de9975 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -14,6 +14,7 @@ helper Admin::PagePartsHelper @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) @designs = Design.all.entries @design = Design.first end @@ -76,10 +77,10 @@ helper Admin::PagePartsHelper @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] = 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 + # 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] = [] @@ -89,7 +90,7 @@ helper Admin::PagePartsHelper params[:page][:category] = [] end - params[:page][:frontend_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page][:frontend_field].blank? + # 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]) @@ -132,6 +133,9 @@ helper Admin::PagePartsHelper @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 @@ -177,7 +181,7 @@ helper Admin::PagePartsHelper def reload_widget_field @index = params[:field_seri].to_i - @item = Page.find params[:id] + @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? diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index 601da3cd8..afe26f80e 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -12,43 +12,42 @@ module Admin::PagePartsHelper 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 when Page - admin_pages_path + reload_after_list_changed_admin_pages_path when PagePart - admin_page_parts_path + reload_after_list_changed_admin_page_part_path end end - def link_to_field_switch(i,object_name,field_name,local_item=nil,prefill_value=nil) #link_to_field is for showing - local_item = @part if local_item.nil? && @part - local_item = @item if local_item.nil? && @item - res = '' - choosen_value = prefill_value || (local_item[field_name][i][0] rescue nil) - - if choosen_value - choosen_field_is_link = (@module_app.widget_fields.select{|t| t[0].to_s==choosen_value}.first)[2]==:link - else - choosen_field_is_link = false - end + def link_to_field_switch( i ,object_name,field_name,local_item=nil,assign_field_name_value=nil) #link_to_field is for showing + field_is_checked = nil + local_item = case + when local_item.nil? && @part + @part + when local_item.nil? && @item + @item + end + field_is_checked = local_item.default_widget_field_sat_to_link?(i) + res = hidden_field_tag "#{object_name}[#{field_name}][][sat_to_link]", 'false' - if choosen_field_is_link - value = case local_item - when Page - local_item[:frontend_field][i][2] rescue false - when PagePart - local_item[:widget_field][i][2] rescue false - end + unless field_is_checked.nil? and assign_field_name_value.nil? + origin_field = nil - res = label_tag '' do - check_box_tag("#{object_name}[#{field_name}_is_link][]", "true", value) + I18n.t("default_widget.field_is_link") - end - else # choosen_field_not_link - res = hidden_field_tag "#{object_name}[#{field_name}_is_link][]", 'false' - end # of if choosen_field_is_link + origin_field = @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 + + res = label_tag '' do + check_box_tag("#{object_name}[#{field_name}][][sat_to_link]", "true", field_is_checked) + I18n.t("default_widget.field_is_link") + end + else # choosen_field_not_link + return res + end # of if choosen_field_is_link + else + return res + end end def widget_field_options(i,local_item=nil) @@ -59,25 +58,24 @@ module Admin::PagePartsHelper label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}") [label, widget_field[0]] end - case local_item when Page - options_for_select(options, (local_item[:frontend_field][i][0] if (local_item && !local_item[:frontend_field].blank? && !local_item[:frontend_field][i].blank?)) ) + options_for_select(options, (local_item.frontend_field_name[i] if(local_item) )) when PagePart - options_for_select(options, (local_item[:widget_field][i][0] if (local_item && !local_item[:widget_field].blank? && !local_item[:widget_field][i].blank?)) ) + options_for_select(options, (local_item.widget_field_name[i] if(local_item) )) end end - def widget_fiield_type_options(i,local_item=nil) + def widget_fiield_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 case local_item when Page - options_for_select(options, (local_item[:frontend_field][i][1] if (local_item && !local_item[:frontend_field].blank? && !local_item[:frontend_field][i].blank?)) ) + options_for_select(options, (local_item.frontend_class[i] if (local_item) )) when PagePart - options_for_select(options, (local_item[:widget_field][i][1] if (local_item && !local_item[:widget_field].blank? && !local_item[:widget_field][i].blank?)) ) + options_for_select(options, (local_item.widget_class[i] if (local_item) )) end end diff --git a/app/models/page.rb b/app/models/page.rb index be9c02e77..91a76de8c 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -14,7 +14,12 @@ class Page < Item field :page_title, localize: true field :frontend_style - field :frontend_field , :type => Array + field :frontend_field , :type => Array,:default => [] + + field :frontend_field_name , :type => Array,:default => [] + field :frontend_class , :type => Array,:default => [] + field :frontend_sat_to_link , :type => Array,:default => [] + field :frontend_data_count belongs_to :design @@ -32,6 +37,29 @@ class Page < Item self.save end + def default_widget_field_sat_to_link?(i) + case frontend_sat_to_link[i] + when 'true' + true + when 'false' + false + else + nil + end + end + + def default_widget_field_name + return frontend_field_name + end + + def frontend_field=(settings) + settings.each_with_index do |setting,index| + self.frontend_field_name[index] = setting["field_name"] + self.frontend_class[index] = setting["class"] + self.frontend_sat_to_link[index] = setting["sat_to_link"] + end + end + protected def create_parts diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 4b0d4a8c7..c9e54eed1 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -1,5 +1,4 @@ class PagePart - include Mongoid::Document include Mongoid::Timestamps @@ -15,7 +14,12 @@ class PagePart field :tag, type: Array,:default => [] field :widget_style - field :widget_field , :type => Array + field :widget_field , :type => Array,:default => [] + + field :widget_field_name , :type => Array,:default => [] + field :widget_class , :type => Array,:default => [] + field :widget_sat_to_link , :type => Array,:default => [] + field :widget_options ,:type=>Hash field :widget_data_count @@ -25,15 +29,28 @@ class PagePart before_save :delete_empty_widget_field after_save :update_parent - # def module_app - # if self[:module_app] - # self[:module_app] - # elsif self[:kind] == 'module_widget' - # self.page.module_app - # else - # nil - # end - # end + def default_widget_field_sat_to_link?(i) + case widget_sat_to_link[i] + when 'true' + true + when 'false' + false + else + nil + end + end + + def default_widget_field_name + return widget_field_name + end + + def widget_field=(settings) + settings.each_with_index do |setting,index| + self.widget_field_name[index] = setting["field_name"] + self.widget_class[index] = setting["class"] + self.widget_sat_to_link[index] = setting["sat_to_link"] + end + end protected 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 3e7d2689e..1cc31024e 100644 --- a/app/views/admin/page_parts/_default_widget_setting.html.erb +++ b/app/views/admin/page_parts/_default_widget_setting.html.erb @@ -2,9 +2,11 @@ <% when PagePart %> <% object_name = 'page_part' %> <% field_name = 'widget_field' %> + <% reload_rel = reload_after_widget_field_changed_admin_page_part_path %> <% when Page %> <% object_name = 'page' %> <% field_name = 'frontend_field' %> + <% reload_rel = reload_after_widget_field_changed_admin_pages_path %> <% end %>
<%= submit_tag t(:delete_) %> diff --git a/app/views/admin/pages/reload_front_end_setting.js.erb b/app/views/admin/pages/reload_front_end_setting.js.erb index ea5cb3367..521f0ce6d 100644 --- a/app/views/admin/pages/reload_front_end_setting.js.erb +++ b/app/views/admin/pages/reload_front_end_setting.js.erb @@ -1,8 +1,6 @@ <% if show_default_widget_setting_panel %> - // $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@page} %>"); - - $('#frontend_setting').html("<%= j render :partial => 'admin/page_parts/default_widget_style_panel',:locals=>{:object=>@page} %>"); - $('#frontend_setting').append("<%= j render :partial => 'admin/page_parts/default_widget_setting',:locals=>{:object=>@page} %>"); + $('#frontend_setting').html("<%= j render :partial => 'admin/page_parts/default_widget_style_panel',:locals=>{:object=>@item} %>"); + $('#frontend_setting').append("<%= j render :partial => 'admin/page_parts/default_widget_setting',:locals=>{:object=>@item} %>"); <% else %> $('#frontend_setting').html("<%= j render :partial => 'custom_frontend_setting' %>"); <% end %> \ No newline at end of file diff --git a/app/views/admin/pages/reload_frontend_pages.js.erb b/app/views/admin/pages/reload_frontend_pages.js.erb index f262a7530..d5e99459d 100644 --- a/app/views/admin/pages/reload_frontend_pages.js.erb +++ b/app/views/admin/pages/reload_frontend_pages.js.erb @@ -1,12 +1,12 @@ <% if @module_app %> - $('#app_page_category').html("<%= j render :partial => 'admin/page_parts/widget_data_source_category' ,:locals=>{:object=>@page}%>"); - $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@page} %>"); - $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>(@page.frontend_data_count rescue nil)} %>"); + $('#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? %> - $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, @app_frontend_urls.first)) %>"); - <%else %> - $('#app_page_url').html("<%= t('default_widget.no_support_setting')%>"); + <% 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}) %>"); + <% else %> + $('#app_page_url').html("