From caac9191ce7eba6451157df22670a51704728081 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 23 Feb 2013 16:52:37 +0800 Subject: [PATCH] Fix public_r_tag selection --- app/assets/javascripts/page_edit.js.erb | 2 +- app/controllers/admin/page_parts_controller.rb | 3 ++- app/views/admin/page_parts/_public_r_tag.html.erb | 2 +- app/views/admin/page_parts/reload_r_tag_options.js.erb | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index b7771692..2585961a 100644 --- a/app/assets/javascripts/page_edit.js.erb +++ b/app/assets/javascripts/page_edit.js.erb @@ -39,7 +39,7 @@ $("#widget_list select,#frontend_list select").live('change', function() { }); $("#tag_list select").live('change', function() { - $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_r_tag_options'); + $.getScript($(this).attr('rel') + '?type=' + $(this).val()); }); $("select.widget_field_select").live('change', function() { diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index d591dd83..3487d12e 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -126,7 +126,8 @@ class Admin::PagePartsController < ApplicationController end def reload_r_tag_options - @r_tag = (ModuleApp.find(params[:id]) rescue nil) || params[:id] + @part = PagePart.find params[:id] + @r_tag = params[:type] @tag_objects = @r_tag.classify.constantize.all rescue nil respond_to do |format| format.js {} diff --git a/app/views/admin/page_parts/_public_r_tag.html.erb b/app/views/admin/page_parts/_public_r_tag.html.erb index 9a3ce984..3ceed4ca 100644 --- a/app/views/admin/page_parts/_public_r_tag.html.erb +++ b/app/views/admin/page_parts/_public_r_tag.html.erb @@ -1,5 +1,5 @@ - <%= f.select :public_r_tag, LIST[:public_r_tags].collect{|tag| [t(tag), tag]}, {:selected => @r_tag}, {:rel => admin_page_parts_path} %> + <%= f.select :public_r_tag, LIST[:public_r_tags].collect{|tag| [t(tag), tag]}, {:selected => @r_tag}, {:rel => reload_r_tag_options_admin_page_part_path(@part)} %> diff --git a/app/views/admin/page_parts/reload_r_tag_options.js.erb b/app/views/admin/page_parts/reload_r_tag_options.js.erb index 550d6127..ff6a5381 100644 --- a/app/views/admin/page_parts/reload_r_tag_options.js.erb +++ b/app/views/admin/page_parts/reload_r_tag_options.js.erb @@ -1,5 +1,8 @@ <% if @r_tag.eql?('sub_menu') %> // $('#name_list select').html("<%= j options_for_select(t(:horizontal) => :horizontal, t(:vertical) => :vertical) %>") + $('#name_list').html("<%= j hidden_field_tag 'page_part[public_r_tag_object_id]', :value => @part.page.id %>") +<% elsif @tag_objects %> + $('#name_list').html("<%= j select_tag 'page_part[public_r_tag_object_id]', options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %>") <% else %> - $('#name_list select').html("<%= j options_from_collection_for_select(@tag_objects, :id, :title) %>") + $('#name_list').empty() <% end %> \ No newline at end of file