From 18617850e5c15e3e6cbac9562a2e864ba46813fd Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 28 Feb 2012 22:00:05 +0800 Subject: [PATCH] Add categories for all the widgets --- app/controllers/admin/page_parts_controller.rb | 13 ++++++++++++- app/views/admin/page_parts/_module_widget.html.erb | 2 +- .../admin/page_parts/_widget_categories.html.erb | 1 + app/views/admin/page_parts/reload_widgets.js.erb | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/page_parts/_widget_categories.html.erb diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index a6e3314f..bb759403 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -26,7 +26,12 @@ 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 - @categories = BulletinCategory.all + case @module_app.key + when 'bulletin' + @categories = BulletinCategory.all + when 'web_resource' + @categories = WebLinkCategory.all + end end def create @@ -59,6 +64,12 @@ class Admin::PagePartsController < ApplicationController def reload_widgets @module_app = ModuleApp.find(params[:id]) + case @module_app.key + when 'announcement' + @categories = BulletinCategory.all + when 'web_resource' + @categories = WebLinkCategory.all + end respond_to do |format| format.js {} end diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index fd481172..374242df 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -8,5 +8,5 @@ - <%= select 'page_part', 'category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, :selected => @part[:category] %> + <%= render 'widget_categories' %> \ No newline at end of file diff --git a/app/views/admin/page_parts/_widget_categories.html.erb b/app/views/admin/page_parts/_widget_categories.html.erb new file mode 100644 index 00000000..ce037d39 --- /dev/null +++ b/app/views/admin/page_parts/_widget_categories.html.erb @@ -0,0 +1 @@ + <%= select 'page_part', 'category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, :selected => (@part ? @part[:category] : nil) if @categories && @categories.size > 0 %> \ 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 646d4274..67e7589d 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -1 +1,2 @@ -$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|widget| [widget.humanize, widget]}) %>") \ No newline at end of file +$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|widget| [widget.humanize, widget]}) %>") +$('#widget_category').html("<%= j render 'widget_categories' %>") \ No newline at end of file