2012-12-03 10:52:36 +00:00
|
|
|
class DefaultWidgetController< OrbitWidgetController
|
|
|
|
|
|
|
|
def front_end_available(var)
|
2013-01-21 08:56:37 +00:00
|
|
|
@page_part = case params[:item_type]
|
|
|
|
when "page"
|
|
|
|
Page.find params[:page_id]
|
|
|
|
when "page_part"
|
|
|
|
PagePart.find params[:part_id]
|
|
|
|
end
|
2012-12-03 10:52:36 +00:00
|
|
|
@page_part.module_app.enable_frontend?
|
|
|
|
end
|
|
|
|
|
2013-02-06 11:51:53 +00:00
|
|
|
def query_for_default_widget
|
|
|
|
ori_class_name = @default_widget["query"].split('.')[0]
|
|
|
|
result = nil
|
|
|
|
if !params["tag_id"].blank?
|
|
|
|
@tag = Tag.find(params["tag_id"]) rescue nil
|
|
|
|
if params["category_id"].blank?
|
2013-02-07 09:57:36 +00:00
|
|
|
result = @tag.send(ori_class_name.downcase.pluralize).desc(:created_at)
|
2013-02-06 11:51:53 +00:00
|
|
|
else
|
2013-02-07 09:57:36 +00:00
|
|
|
result = @tag.send(ori_class_name.downcase.pluralize).where(get_category_field_name(ori_class_name) => params['category_id']).desc(:created_at)
|
2013-02-06 11:51:53 +00:00
|
|
|
end
|
|
|
|
elsif params["category_id"].blank?
|
2013-02-07 09:57:36 +00:00
|
|
|
result = eval(@default_widget["query"]).desc(:created_at)
|
2013-02-06 11:51:53 +00:00
|
|
|
else
|
2013-02-07 09:57:36 +00:00
|
|
|
result = eval("#{ori_class_name}.where(get_category_field_name(ori_class_name) => params['category_id'])").desc(:created_at)
|
2013-02-06 11:51:53 +00:00
|
|
|
end
|
2013-02-07 09:57:36 +00:00
|
|
|
result.available_for_lang(I18n.locale).can_display.desc(:created_at)
|
2013-02-06 11:51:53 +00:00
|
|
|
end
|
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
def default_widget
|
2013-02-05 08:34:22 +00:00
|
|
|
if !params[:id].blank?
|
2013-02-06 10:20:45 +00:00
|
|
|
redirect_to eval("#{@page_part.module_app.widget_fields_link_method['title']['method']}('#{params[:id]}', {inner: #{params[:inner] || true}})")
|
2013-02-05 08:34:22 +00:00
|
|
|
else
|
|
|
|
@tag_class = nil
|
2012-12-03 10:52:36 +00:00
|
|
|
|
2013-02-05 08:34:22 +00:00
|
|
|
@default_widget = @page_part.module_app.get_default_widget
|
|
|
|
@widget_image_field = @default_widget["image"] || @default_widget[:image]
|
2013-02-06 10:20:45 +00:00
|
|
|
case @page_part
|
2013-02-05 08:34:22 +00:00
|
|
|
when Page
|
|
|
|
@fields = @page_part.frontend_field
|
2013-02-06 10:20:45 +00:00
|
|
|
@data_limit = @page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3)
|
|
|
|
@paginate = true
|
|
|
|
@page_id = @page_part.id
|
2013-02-05 08:34:22 +00:00
|
|
|
when PagePart
|
|
|
|
@fields = @page_part.widget_field
|
2013-02-06 10:20:45 +00:00
|
|
|
@data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
2013-02-05 08:34:22 +00:00
|
|
|
end
|
2013-02-06 10:20:45 +00:00
|
|
|
if @paginate
|
|
|
|
@data = eval(@default_widget["query"]).includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at)
|
|
|
|
else
|
|
|
|
@data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at)
|
|
|
|
end
|
2013-02-05 08:34:22 +00:00
|
|
|
case params[:type]
|
|
|
|
when "typeA"
|
|
|
|
@tag_class = 'default_widget_typeA'
|
2013-02-06 10:20:45 +00:00
|
|
|
@partial = "typeA"
|
2013-02-05 08:34:22 +00:00
|
|
|
when /typeB_/
|
|
|
|
@tag_class = "default_widget_#{params[:type]}"
|
2013-02-06 10:20:45 +00:00
|
|
|
@partial = "typeB"
|
2013-02-05 08:34:22 +00:00
|
|
|
when "typeC"
|
|
|
|
@tag_class = 'default_widget_typeC'
|
2013-02-06 10:20:45 +00:00
|
|
|
@partial = "typeC"
|
2013-02-05 08:34:22 +00:00
|
|
|
end
|
2013-01-21 08:56:37 +00:00
|
|
|
end
|
2012-12-03 10:52:36 +00:00
|
|
|
end
|
|
|
|
|
2013-02-06 12:28:06 +00:00
|
|
|
def get_category_field_name(ori_class_name)
|
|
|
|
ori_class_name = ori_class_name.constantize
|
|
|
|
ori_class_name.fields.each_key do |key|
|
|
|
|
return key if key.include?('category_id')
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
2012-12-03 10:52:36 +00:00
|
|
|
end
|