From cf8d20dc84a192eb70afaae4fd988e5d2e7c7003 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 14 May 2012 00:33:52 +0800 Subject: [PATCH] Add category and tag to pages --- app/controllers/admin/module_apps_controller.rb | 12 +++++++++++- app/controllers/admin/pages_controller.rb | 3 +++ app/models/page.rb | 2 ++ .../admin/module_apps/reload_frontend_pages.js.erb | 3 ++- app/views/admin/pages/_form.html.erb | 3 +++ lib/parsers/parser_common.rb | 6 ++++-- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb index c6a8d2b2..1393bf32 100644 --- a/app/controllers/admin/module_apps_controller.rb +++ b/app/controllers/admin/module_apps_controller.rb @@ -11,7 +11,17 @@ class Admin::ModuleAppsController < ApplicationController def reload_frontend_pages @module_app = ModuleApp.find(params[:id]) - @categories = @module_app.key.eql?('announcement') ? BulletinCategory.all : nil + case @module_app.key + when 'announcement' + @categories = BulletinCategory.all + @tags = AnnouncementTag.all + when 'news' + @categories = NewsBulletinCategory.all + @tags = NewsTag.all + when 'web_resource' + @categories = WebLinkCategory.all + @tags = WebResourceTag.all + end respond_to do |format| format.js {} end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 71153a14..44bda4aa 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -35,10 +35,13 @@ class Admin::PagesController < ApplicationController case @item.module_app.key when 'announcement' @categories = BulletinCategory.all + @tags = AnnouncementTag.all when 'news' @categories = NewsBulletinCategory.all + @tags = NewsTag.all when 'web_resource' @categories = WebLinkCategory.all + @tags = WebResourceTag.all end else @categories = nil diff --git a/app/models/page.rb b/app/models/page.rb index 0378b688..4bcb49a6 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -3,6 +3,8 @@ class Page < Item field :content field :app_frontend_url field :theme_id, :type => BSON::ObjectId, :default => nil + field :category + field :tag belongs_to :design belongs_to :module_app diff --git a/app/views/admin/module_apps/reload_frontend_pages.js.erb b/app/views/admin/module_apps/reload_frontend_pages.js.erb index 3feb17cf..2fc90b8e 100644 --- a/app/views/admin/module_apps/reload_frontend_pages.js.erb +++ b/app/views/admin/module_apps/reload_frontend_pages.js.erb @@ -1,2 +1,3 @@ $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', @module_app.app_pages) %>"); -$('#app_page_category').html("<%= escape_javascript(select 'page', 'category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}) if @categories %>"); \ No newline at end of file +$('#app_page_category').html("<%= j (select 'page', 'category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, {:include_blank => true}) if @categories %>"); +$('#app_page_tag').html("<%= j (select 'page', 'tag', @tags.collect{|tag| [tag[I18n.locale], tag.id]}, {:include_blank => true}) if @tags %>"); \ 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 36e6e008..eff3e4df 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -45,6 +45,9 @@ <%= select('page','category', @categories.collect{|category| [category.i18n_variable[I18n.locale], category.id]}, :selected => @item[:category], :include_blank => true ) rescue ''%> + + <%= select('page','tag', @tags.collect{|tag| [tag[I18n.locale], tag.id]}, :selected => @item[:tag], :include_blank => true ) rescue ''%> + diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 4afa586c..d727e68c 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -164,10 +164,12 @@ module ParserCommon public_r_tags = [] body.css('.page_content').each do |content| ret = '' + category = params[:category_id].blank? ? page[:category] : params[:category_id] + tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id] if (content["main"] == "true" && !page.module_app.nil?) ret << "
" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil @@ -183,7 +185,7 @@ module ParserCommon ret << part.i18n_variable[I18n.locale] rescue '' when 'module_widget' url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" - options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : params[:category_id]}&tag_id=#{!part[:tag].blank? ? part[:tag] : params[:tag_id]}&page=#{params[:page]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}" + options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}" ret << "
" when 'public_r_tag' ret << ""