diff --git a/app/assets/javascripts/page_edit.js b/app/assets/javascripts/page_edit.js index 31a7d600..a889f5b2 100644 --- a/app/assets/javascripts/page_edit.js +++ b/app/assets/javascripts/page_edit.js @@ -24,6 +24,10 @@ $("#module_app_list select").live('change', function() { $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widgets'); }); +$("#tag_list select").live('change', function() { + $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_r_tag_options'); +}); + $('.part_kind').live('click', function() { $('.part_kind_partial').hide(); $('#part_' + $(this).attr('value')).show(); diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index bb759403..4558cb03 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -25,7 +25,7 @@ class Admin::PagePartsController < ApplicationController @module_apps = ModuleApp.all(:conditions => {:enable_frontend => true}) @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 + @tag_objects = @r_tag.classify.constantize.all rescue nil case @module_app.key when 'bulletin' @categories = BulletinCategory.all @@ -74,5 +74,13 @@ class Admin::PagePartsController < ApplicationController format.js {} end end + + def reload_r_tag_options + @r_tag = (ModuleApp.find(params[:id]) rescue nil) || params[:id] + @tag_objects = @r_tag.classify.constantize.all rescue nil + respond_to do |format| + format.js {} + end + end end diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 9fe91e86..42f8b775 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -7,7 +7,7 @@ class PagePart field :content field :kind field :public_r_tag - field :public_r_tag_object_id, :type => BSON::ObjectId, :default => nil + field :public_r_tag_object_id, :default => nil field :widget_path has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy 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 3f8170d7..d8422e9d 100644 --- a/app/views/admin/page_parts/_public_r_tag.html.erb +++ b/app/views/admin/page_parts/_public_r_tag.html.erb @@ -1,7 +1,11 @@ - <%= f.select :public_r_tag, LIST[:public_r_tags].collect{|tag| [t(tag), tag]}, :selected => @r_tag %> + <%= 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_object_id, options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %> + <% if @r_tag.eql?('sub_menu') %> + <%= f.select :public_r_tag_object_id, options_for_select([t(:horizontal), t(:vertical)], t(:horizontal)) %> + <% else %> + <%= f.select :public_r_tag_object_id, options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %> + <% end %> \ No newline at end of file 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 new file mode 100644 index 00000000..a2eaf483 --- /dev/null +++ b/app/views/admin/page_parts/reload_r_tag_options.js.erb @@ -0,0 +1,5 @@ +<% if @r_tag.eql?('sub_menu') %> + $('#name_list select').html("<%= j options_for_select(t(:horizontal) => :horizontal, t(:vertical) => :vertical) %>") +<% else %> + $('#name_list select').html("<%= j options_from_collection_for_select(@tag_objects, :id, :title) %>") +<% end %> \ No newline at end of file diff --git a/config/list.yml b/config/list.yml index 9b3a1a96..ef95ba31 100644 --- a/config/list.yml +++ b/config/list.yml @@ -9,6 +9,7 @@ markups: public_r_tags: - ad_banner + - sub_menu page_part_kinds: - text diff --git a/config/routes.rb b/config/routes.rb index 9200492d..7ea7edd8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,6 +77,7 @@ Orbit::Application.routes.draw do resources :page_parts do member do get 'reload_widgets' + get 'reload_r_tag_options' end end resources :purchases do diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 93ea2608..94a968c4 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -106,4 +106,20 @@ module ParserCommon page_menu.swap(fragment) end + # sub_menus + def parse_sub_menus(body = nil, page = nil, id = nil) + body.css('sub_menu').each do |sub_menu| + res = '' + res << "