orbit-announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb

163 lines
6.4 KiB
Ruby
Raw Normal View History

2014-01-14 11:54:35 +00:00
class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
def initialize
super
@app_title = 'announcement'
end
# GET /bulletins
# GET /bulletins.xml
# def index
# @part = PagePart.find(params[:part_id])
# if @part.widget_data_count
# @page_num = @part.widget_data_count
# else
# @page_num = 4
# end
# num_of_fields = @part.widget_field_name.reject(&:empty?).length
# widget_field_names = @part.widget_field_name.reject(&:empty?)
# widget_classes = @part.widget_class.reject(&:empty?)
# @widget_fields = []
# if @part.widget_field_name
# num_of_fields.times do |index|
# @widget_fields << [widget_field_names[index], widget_classes[index]]
# end
# end
# @title = @part.title_translations[I18n.locale.to_s]
# @widget_style = @part.widget_style
# @category_id = @part.category
# date_now = Time.now
# if !params[:category_id].blank? && !params[:tag_id].blank?
# @posts = Bulletin.available_for_lang(I18n.locale).can_display.where(:category_id.in => params[:category_id], :tagged_ids.in => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
# elsif !params[:category_id].blank?
# @posts = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:category_id.in => params[:category_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
# elsif !params[:tag_id].blank?
# @posts = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids.in => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
# else
# @posts = Bulletin.all.available_for_lang(I18n.locale).can_display.desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
# end
# @categories = @module_app.categories.enabled
# end
def bulletins_list_and_pic
if params[:widget_data_count]
@page_num = params[:widget_data_count];
else
@page_num = 4;
end
@title = params[:part_title]
date_now = Time.now
if !params[:category_id].blank?
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(@page_num )
@current_category = BulletinCategory.from_id(params[:category_id]) rescue nil
elsif !params[:tag_id].blank?
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => params[:tag_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num)
else
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(@page_num )
end
@categories = @module_app.categories.enabled
end
def bulletins_and_web_links
@part = PagePart.find(params[:part_id]) if !params[:part_id].blank?
@title = @part.title_translations[I18n.locale.to_s]
if !@part.blank? and @part.widget_data_count
@page_num = @part.widget_data_count
else
@page_num = 5
end
date_now = Time.now
if !params[:tag_id].blank?
@tags = Tag.any_in(:_id => params[:tag_id]).asc(:created_at)
elsif params[:tag_id].blank? and !@part.tag.blank?
@tags = Tag.any_in(:_id => @part.tag).asc(:created_at)
else
@ModuleApp_b = ModuleApp.first(:conditions => {:key=>'announcement'})
@tags = Tag.where(:module_tag_id => @ModuleApp_b.id).asc(:created_at)
end
@selected_tag = Tag.find(params[:id]).first rescue @tags[0]
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => @selected_tag.id.to_s, :is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, :postdate).page(params[:page]).per(@page_num) rescue nil
if @part.widget_style == 'bulletins_and_links'
@ModuleApp_w = ModuleApp.first(:conditions => {:key=>'web_resource'})
@link_module_tag = ModuleTag.first(:conditions => {:name => @selected_tag.name, :module_app_id => @ModuleApp_w.id})
if !@link_module_tag.blank?
@link_selected_tag = Tag.first(:conditions => {:name => @selected_tag.name, :tag_lease_id => @link_module_tag.id})
else
@link_selected_tag = @link_module_tag
end
@web_links = WebLink.where(:tagged_ids => @link_selected_tag.id.to_s, :is_hidden => false).desc(:is_top,:created_at).available_for_lang(I18n.locale).page(params[:page]).per(@page_num) rescue nil
end
end
def reload_bulletins
@part = PagePart.find(params[:part_id]) if !params[:part_id].blank?
@title = @part.title_translations[I18n.locale.to_s]
if !@part.blank? and @part.widget_data_count
@page_num = @part.widget_data_count
else
@page_num = 5
end
date_now = Time.now
@selected_tag = Tag.find(params[:tag_id]).first
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => @selected_tag.id.to_s, :is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, :postdate).page(params[:page]).per(@page_num) rescue nil
end
def reload_web_links
@part = PagePart.find(params[:part_id]) if !params[:part_id].blank?
if !@part.blank? and @part.widget_data_count
@page_num = @part.widget_data_count
else
@page_num = 5
end
date_now = Time.now
@selected_tag = Tag.find(params[:tag_id]).first
@ModuleApp = ModuleApp.first(:conditions => {:key=>'web_resource'})
@link_selected_tag = Tag.first(:conditions => {:name => @selected_tag.name, :module_tag_id => @ModuleApp.id})
@web_links = WebLink.where(:tagged_ids => @link_selected_tag.id.to_s, :is_hidden => false).desc(:is_top,:created_at).available_for_lang(I18n.locale).page(params[:page]).per(@page_num) rescue nil
end
def bulletins_side_bar
@tags_and_class = @module_app.sorted_tags_for_cloud
@categories = @module_app.categories.enabled
end
def bulletins_search_block
@part = PagePart.find params[:part_id]
end
end