Fix links in default widget

This commit is contained in:
chris 2013-02-07 21:15:38 +08:00
parent 6324233f58
commit 6d1f919bb7
6 changed files with 23 additions and 17 deletions

View File

@ -76,9 +76,10 @@ class PagesController < ApplicationController
elsif !params[:tag_id].blank?
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], tag: params[:tag_id]).any_in(category: [nil,'']).first
end
@item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
@item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
end
raise PageError,'Missing Frontend Page' if @item.nil?
end

View File

@ -3,24 +3,24 @@ module DefaultWidgetHelper
I18n.t("#{@page_part.module_app.key}.default_widget.#{field}")
end
def link_to_field(row_data,field,switch)
def link_to_field(row_data,field, options=nil, switch)
method_ary = @page_part.module_app.widget_fields_link_method
field = field.to_sym
if(method_ary.has_key?(field) and (switch == "true"))
url = case method_ary[field][:args]
when nil # no args
get_data_link(method_ary[field][:method])
get_data_link(method_ary[field]["method"], options)
when :self # passing self
get_data_link(method_ary[field][:method],row_data.id)
get_data_link(method_ary[field]['method'], options,row_data.id)
else
ary = method_ary[field][:args].clone
object_hash = ary.each do |key,val|
ary[key]= type_trans_or_to_s(row_data.send(val[0]).send(val[1]))
end
get_data_link(method_ary[field][:method],object_hash)
get_data_link(method_ary[field]['method'], options,object_hash)
end
link_to row_data.send(field),url
link_to row_data.send(field), url
else
type_trans_or_to_s(row_data.send(field) )
end
@ -45,13 +45,17 @@ module DefaultWidgetHelper
end
end
def get_data_link(method_entry,object = nil)
def get_data_link(method_entry, options=nil, object = nil)
case object
when nil
eval method_entry
when NilClass
eval eval("#{method_entry}(#{options})")
when BSON::ObjectId
object = "'#{object.to_s}'"
eval("#{method_entry}(#{object}, #{options})")
when Hash
eval("#{method_entry}(#{object.merge options})")
else
object = "'#{object.to_s}'" if object.class == BSON::ObjectId
eval("#{method_entry}(#{object})" )
''
end
end

View File

@ -11,7 +11,7 @@
<% @data.each do |row_data| %>
<tr>
<% @fields.each do |field|%>
<td><%= content_tag(:span,link_to_field(row_data,field[0],field[2]),:class=>field[1])%></td>
<td><%= content_tag(:span,link_to_field(row_data,field[0], orig_page: @page_id.to_s, field[2]),:class=>field[1])%></td>
<% end %>
</tr>
<% end %>

View File

@ -7,7 +7,7 @@
</div>
<div class="wrap">
<% @fields.each do |field|%>
<%= content_tag(:span,link_to_field(row_data,field[0]),:class=>field[1])%>
<%= content_tag(:span,link_to_field(row_data,field[0], orig_page: @page_id.to_s, field[2]),:class=>field[1])%>
<% end %>
</div>
<% end %>

View File

@ -6,7 +6,7 @@
<% @data.each do |row_data| %>
<%= content_tag(:li) do %>
<% @fields.each do |field|%>
<%= content_tag(:span,link_to_field(row_data,field[0]),:class=>field[1])%>
<%= content_tag(:span, link_to_field(row_data,field[0], orig_page: @page_id.to_s, field[2]),:class=>field[1])%>
<% end %>
<% end %>
<% end %>

View File

@ -20,6 +20,7 @@ module ParserFrontEnd
def parse_page_content(page)
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)
body.css('orbit_front').each do |front|
if front['value']
@ -119,7 +120,7 @@ module ParserFrontEnd
end
options = "&page_id=#{page.id}&category_id=\#{page[:category]}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page"
options = "&page_id=#{page.id}&category_id=\#{category}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&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
@ -136,7 +137,7 @@ module ParserFrontEnd
else
"/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
end
options = "&part_id=\#{part.id}&category_id=\#{part[:category]}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&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}&category_id=\#{part[:category]}&tag_id=\#{part[:tag]}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&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'