From 4ae829994936941ac80cca3edc02f19c77de7ae5 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Sun, 13 May 2012 22:35:00 +0800 Subject: [PATCH] Add custom title to widgets Fix pagination conflict with main_content and widgets --- app/controllers/pages_controller.rb | 2 +- app/models/page_part.rb | 20 ++++++++++++++++++- .../admin/page_parts/_module_widget.html.erb | 11 ++++++++++ lib/parsers/parser_common.rb | 5 +++-- .../front_end/bulletins_controller.rb | 6 +++--- .../widget/bulletins_controller.rb | 2 +- .../front_end/bulletins/index.html.erb | 2 +- .../widget/bulletins/_index.html.erb | 8 ++------ .../front_end/news_bulletins_controller.rb | 6 +++--- .../news/widget/news_bulletins_controller.rb | 1 + .../front_end/news_bulletins/index.html.erb | 2 +- .../widget/news_bulletins/_index.html.erb | 10 ++-------- .../widget/web_links_controller.rb | 1 + .../widget/web_links/home_list.html.erb | 4 +++- 14 files changed, 52 insertions(+), 28 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index c4a571dd..45299450 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -34,7 +34,7 @@ class PagesController < ApplicationController def index_from_link url = "/#{@item.path}" options = '' - options << "?page=#{params[:page]}" unless params[:page].blank? + options << "?page_main=#{params[:page_main]}" unless params[:page_main].blank? options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank? options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank? redirect_to url + options diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 8bb1bc72..52eafdf3 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -11,9 +11,27 @@ class PagePart field :public_r_tag_option, :default => nil field :widget_path - has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + has_one :i18n_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy belongs_to :page belongs_to :module_app + before_save :set_key + + def i18n_variable + @i18n_variable ||= I18nVariable.first(:conditions => {:key => 'i18n_variable', :language_value_id => self.id, :language_value_type => self.class}) rescue nil + end + + def title + @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil + end + + protected + + def set_key + title.key = 'title' if title && (title.key.blank? rescue true) + i18n_variable.key = 'i18n_variable' if i18n_variable && (i18n_variable.key.blank? rescue true) + end + end \ No newline at end of file diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 3f81a5ae..1a1dd63c 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -1,3 +1,14 @@ +
+ <%= f.fields_for :title, @part.title do |f| %> + <% @site_valid_locales.each do |locale| %> +

+ <%= f.label :locale, "#{t('admin.title')} #{I18nVariable.from_locale(locale)}" %> + <%= f.text_field locale %> +

+ <% end %> +<% end %> +
+ <%= f.select :module_app, options_from_collection_for_select(@module_apps, :id, :title, :selected => @module_app.id), {}, {:rel => admin_page_parts_path} %> diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index f9dd868a..b9c56642 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -167,10 +167,11 @@ module ParserCommon 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 + part_title = part.title[I18n.locale] rescue nil if edit ret << "
" if part ret << "