2013-01-04 10:42:25 +00:00
|
|
|
module DefaultWidgetHelper
|
|
|
|
def get_field_header(field)
|
2013-02-18 07:13:31 +00:00
|
|
|
I18n.t("#{@page_part.module_app.key}.default_widget.#{field}")
|
2013-01-04 10:42:25 +00:00
|
|
|
end
|
|
|
|
|
2013-07-16 09:41:22 +00:00
|
|
|
def get_top_hot_class(row_data)
|
|
|
|
class_attr = []
|
|
|
|
class_attr << 'data_is_hot' if( row_data.is_hot? rescue false )
|
|
|
|
class_attr << 'data_is_top' if( row_data.is_top? rescue false)
|
|
|
|
return class_attr.join(" ")
|
|
|
|
end
|
|
|
|
|
2013-02-19 12:42:46 +00:00
|
|
|
def link_to_field(row_data,field, switch, options=nil)
|
2013-01-04 10:42:25 +00:00
|
|
|
method_ary = @page_part.module_app.widget_fields_link_method
|
2013-02-18 09:03:18 +00:00
|
|
|
field = field.to_sym
|
2013-04-03 11:03:16 +00:00
|
|
|
options = options || {}
|
|
|
|
options[:clicked_field_name] = field
|
2013-04-03 10:05:12 +00:00
|
|
|
if(method_ary.has_key?(field) and (switch.to_s == "true"))
|
2013-02-18 09:03:18 +00:00
|
|
|
url = case method_ary[field][:args]
|
2013-01-04 10:42:25 +00:00
|
|
|
when nil # no args
|
2013-03-19 09:14:01 +00:00
|
|
|
get_data_link(method_ary[field][:method], options)
|
2013-01-04 10:42:25 +00:00
|
|
|
when :self # passing self
|
2013-03-19 09:14:01 +00:00
|
|
|
get_data_link(method_ary[field][:method], options,row_data.id)
|
2013-01-04 10:42:25 +00:00
|
|
|
else
|
2013-02-18 09:03:18 +00:00
|
|
|
ary = method_ary[field][:args].clone
|
2013-01-04 10:42:25 +00:00
|
|
|
object_hash = ary.each do |key,val|
|
2013-01-07 04:09:36 +00:00
|
|
|
ary[key]= type_trans_or_to_s(row_data.send(val[0]).send(val[1]))
|
2013-01-04 10:42:25 +00:00
|
|
|
end
|
2013-03-19 09:14:01 +00:00
|
|
|
get_data_link(method_ary[field][:method], options,object_hash)
|
2013-01-04 10:42:25 +00:00
|
|
|
end
|
2013-02-07 13:15:38 +00:00
|
|
|
|
|
|
|
link_to row_data.send(field), url
|
2013-01-04 10:42:25 +00:00
|
|
|
else
|
2013-01-07 04:09:36 +00:00
|
|
|
type_trans_or_to_s(row_data.send(field) )
|
2013-01-04 10:42:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# def get_args_mapping(object,row_hash)
|
|
|
|
# first_hash = row_hash.first
|
|
|
|
|
|
|
|
# # row_data.send(method_ary[field]["args"])
|
|
|
|
# end
|
|
|
|
|
2013-01-07 04:09:36 +00:00
|
|
|
def type_trans_or_to_s(object)
|
|
|
|
case object
|
|
|
|
when Date
|
|
|
|
display_date(object)
|
|
|
|
when DateTime
|
|
|
|
display_date_time(object)
|
|
|
|
when String
|
|
|
|
object
|
|
|
|
else
|
|
|
|
object.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-07 13:15:38 +00:00
|
|
|
def get_data_link(method_entry, options=nil, object = nil)
|
2013-01-07 04:09:36 +00:00
|
|
|
case object
|
2013-02-07 13:15:38 +00:00
|
|
|
when NilClass
|
|
|
|
eval eval("#{method_entry}(#{options})")
|
|
|
|
when BSON::ObjectId
|
2013-03-19 09:14:01 +00:00
|
|
|
object = object.to_s
|
2013-02-23 07:19:51 +00:00
|
|
|
eval("#{method_entry}(#{{:id => object}.merge options})")
|
2013-02-07 13:15:38 +00:00
|
|
|
when Hash
|
|
|
|
eval("#{method_entry}(#{object.merge options})")
|
2013-01-07 04:09:36 +00:00
|
|
|
else
|
2013-02-07 13:15:38 +00:00
|
|
|
''
|
2013-01-07 04:09:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_display(row_data,field_setting)
|
|
|
|
label = row_data.send(field_setting[:method])
|
|
|
|
type_trans_or_to_s(label)
|
|
|
|
end
|
2013-01-04 10:42:25 +00:00
|
|
|
|
|
|
|
def get_row_data(row_data,field)
|
|
|
|
field_is_link = (field[0][1]== 'false' ? false : true )
|
|
|
|
field_setting = {:class=>field[0][1],:method=>field[0][0]}
|
|
|
|
if field_is_link
|
|
|
|
field_link = field[0][1].to_s + '_path'
|
2013-01-07 04:09:36 +00:00
|
|
|
link = link_to(get_display(row_data,field_setting),field_link.send(row_data))
|
2013-01-04 10:42:25 +00:00
|
|
|
content_tag(:span,link,:class=>field_setting[:class])
|
|
|
|
else
|
2013-01-07 04:09:36 +00:00
|
|
|
content_tag(:span,get_display(row_data,field_setting),:class=>field_setting[:class])
|
2013-01-04 10:42:25 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-19 10:39:13 +00:00
|
|
|
|
|
|
|
def get_row_category(row_data)
|
|
|
|
row_data.send("#{row_data.class.to_s.underscore}_category_id") rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_row_tags(row_data)
|
|
|
|
row_data.tagged_ids rescue nil
|
|
|
|
end
|
|
|
|
|
2013-01-04 10:42:25 +00:00
|
|
|
end
|