widget link followed by setting

This commit is contained in:
Matt K. Fu 2013-04-03 19:03:16 +08:00
parent 28f0df5da8
commit 3098496083
6 changed files with 22 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 << "'></div>"
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 << "<div class='dymanic_load widget' path='#{url + options}'></div>"
when 'public_r_tag'
ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>"

View File

@ -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, "<div class='dymanic_load widget' path='#{ret}'></div>")
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 << "<orbit_front path='#{url + options}'></div>"
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 << "<orbit_front path='#{url + options}' part_id=#{part.id} class='dymanic_load widget'></orbit_front>"
when 'public_r_tag'