fix link for default widget

This commit is contained in:
Fu Matthew 2013-02-18 17:03:18 +08:00
parent a6f6dc271c
commit 3a13ab4634
6 changed files with 28 additions and 10 deletions

View File

@ -23,7 +23,7 @@ class DefaultWidgetController< OrbitWidgetController
@fields = @page_part.widget_field
@page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
end
@data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field)
@data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field).desc(:created_at)
case params[:type]
when "typeA"
@tag_class = 'default_widget_typeA'

View File

@ -3,20 +3,21 @@ module DefaultWidgetHelper
I18n.t("#{@page_part.module_app.key}.default_widget.#{field}")
end
def link_to_field(row_data,field)
def link_to_field(row_data,field,switch)
method_ary = @page_part.module_app.widget_fields_link_method
if method_ary.has_key? field
url = case method_ary[field]["args"]
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])
when :self # passing self
get_data_link(method_ary[field]['method'],row_data.id)
get_data_link(method_ary[field][:method],row_data.id)
else
ary = method_ary[field]["args"].clone
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],object_hash)
end
link_to row_data.send(field),url

View File

@ -98,7 +98,8 @@ class ModuleApp
end
def widget_fields_link_method
raise 'Need to link with OrbitApp [type: Hash]'
get_registration.get_link_methods
# raise 'Need to link with OrbitApp [type: Hash]'
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]),:class=>field[1])%></td>
<td><%= content_tag(:span,link_to_field(row_data,field[0],field[2]),:class=>field[1])%></td>
<% end %>
</tr>
<% end %>

View File

@ -64,6 +64,10 @@ module OrbitApp
return @widget_set.get_fields
end
def get_link_methods
return @widget_set.get_link_methods
end
def get_default_widget
if @widget_set.nil? # Init not defining widget
return {}

View File

@ -75,6 +75,10 @@ module OrbitApp
get_default_widget.get_fields
end
def get_link_methods
get_default_widget.get_link_methods
end
def get_default_widget
return @default_widget
end
@ -117,6 +121,10 @@ module OrbitApp
@fields
end
def get_link_methods
return flatten_hashes(@fields.select{|t| t[2]==:link}.map{|t| Hash[t[0].to_sym,t[1]] })
end
def query(var)
@query = var
end
@ -125,6 +133,10 @@ module OrbitApp
@image = var
end
def flatten_hashes(ary)
Hash[*ary.map(&:to_a).flatten]
end
end
class Widget