From 3098496083a33304f402f2bbefd53d0db7628b35 Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Wed, 3 Apr 2013 19:03:16 +0800 Subject: [PATCH] widget link followed by setting --- app/controllers/application_controller.rb | 4 ++-- app/controllers/default_widget_controller.rb | 3 ++- app/controllers/pages_controller.rb | 9 +++++++-- app/helpers/default_widget_helper.rb | 2 ++ lib/parsers/parser_common.rb | 4 ++-- lib/parsers/parser_front_end.rb | 10 +++++++--- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 573b19143..7bcd90e03 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -101,10 +101,10 @@ class ApplicationController < ActionController::Base end # Render the page - def render_page + def render_page(args=nil) if @item respond_to do |format| - format.html { render :text => parse_page_content(@item), :layout => 'page_layout' } + format.html { render :text => parse_page_content(@item,args), :layout => 'page_layout' } format.rss { render_main_rss } format.mobile { redirect_to mobile_path(:app => params[:app]) } end diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index c8b4eddd9..47505dc10 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -41,7 +41,8 @@ class DefaultWidgetController< OrbitWidgetController def default_widget if !params[:id].blank? - redirect_to eval("#{@page_part.module_app.widget_fields_link_method[:title][:method]}('#{params[:id]}', {inner: #{params[:inner] || true}})") + clicked_field_name = params["clicked_field_name"].to_sym + redirect_to eval("#{@page_part.module_app.widget_fields_link_method[clicked_field_name][:method]}('#{params[:id]}', {inner: #{params[:inner] || true}})") else @tag_class = nil @default_widget = @page_part.module_app.get_default_widget diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 123922a17..058b18432 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -14,14 +14,18 @@ class PagesController < ApplicationController end end - def show + def show #begin @item = Item.first(:conditions => {:path => params[:page_name]}) if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) impressionist(@item) case @item.class.to_s when 'Page' - render_page unless save_from_no_lang_for_page + if params[:clicked_field_name] + render_page({"clicked_field_name"=>params["clicked_field_name"]}) unless save_from_no_lang_for_page + else + render_page unless save_from_no_lang_for_page + end when 'Link' redirect_to(@item[:url]) unless save_from_no_lang_for_page end @@ -54,6 +58,7 @@ class PagesController < ApplicationController options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank? options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank? options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank? + options << "#{options.blank? ? '?' : '&'}clicked_field_name=#{params[:clicked_field_name]}" unless params[:clicked_field_name].blank? redirect_to(url + options) unless save_from_no_lang_for_page end diff --git a/app/helpers/default_widget_helper.rb b/app/helpers/default_widget_helper.rb index c0f55452f..32fccb209 100644 --- a/app/helpers/default_widget_helper.rb +++ b/app/helpers/default_widget_helper.rb @@ -6,6 +6,8 @@ module DefaultWidgetHelper def link_to_field(row_data,field, switch, options=nil) method_ary = @page_part.module_app.widget_fields_link_method field = field.to_sym + options = options || {} + options[:clicked_field_name] = field if(method_ary.has_key?(field) and (switch.to_s == "true")) url = case method_ary[field][:args] when nil # no args diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index d2f8b7b20..044f9b9aa 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -242,7 +242,7 @@ module ParserCommon categories_str = "&#{categories_str}" unless categories_str.blank? tags_str = "&#{tags_str}" unless tags_str.blank? - ret << "?inner=true&page_id=#{page.id}#{categories_str}#{tags_str}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}&item_type=page" + ret << "?inner=true&page_id=#{page.id}#{categories_str}#{tags_str}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&clicked_field_name=#{params[:clicked_field_name]}&name=#{params[:name]}&item_type=page" ret << "'>" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil @@ -270,7 +270,7 @@ module ParserCommon categories_str = "&#{categories_str}" unless categories_str.blank? tags_str = "&#{tags_str}" unless tags_str.blank? - options = "&part_id=#{part.id}#{categories_str}#{tags_str}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part" + options = "&part_id=#{part.id}#{categories_str}#{tags_str}&page=#{params[:page]}&search_query=#{params[:search_query]}&clicked_field_name=#{params[:clicked_field_name]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part" ret << "
" when 'public_r_tag' ret << "" diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index ff463f815..43c70b0d6 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -18,7 +18,7 @@ module ParserFrontEnd i18n end - def parse_page_content(page) + def parse_page_content(page,args=nil) tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id] category = params[:category_id].blank? ? page[:category] : params[:category_id] body = Nokogiri::HTML(page.content) @@ -29,6 +29,10 @@ module ParserFrontEnd ret = '' part = PagePart.find(front['part_id']) if front['part_id'] ret << eval("\"#{front['path']}\"") rescue '' + + args.each do |arg,index| + ret << (ret.include?("?") ? "&#{index}=arg": "?#{index}=arg" ) + end if args fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") end front.swap(fragment) @@ -125,7 +129,7 @@ module ParserFrontEnd categories_str = "&#{categories_str}" unless categories_str.blank? tags_str = "&#{tags_str}" unless tags_str.blank? - options = "&page_id=\#{page.id}#{categories_str}#{tags_str}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page" + options = "&page_id=\#{page.id}#{categories_str}#{tags_str}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&name=\#{params[:name]}&item_type=page" ret << "" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil @@ -148,7 +152,7 @@ module ParserFrontEnd categories_str = "&#{categories_str}" unless categories_str.blank? tags_str = "&#{tags_str}" unless tags_str.blank? - options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part" + options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part" ret << "" when 'public_r_tag'