personal-honor/app/controllers/personal_honors_controller.rb

105 lines
2.8 KiB
Ruby
Raw Normal View History

2014-07-03 04:53:38 +00:00
class PersonalHonorsController < ApplicationController
def index
2016-03-21 11:02:08 +00:00
params = OrbitHelper.params
2014-07-18 07:03:24 +00:00
honors = Honor.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
2016-03-21 11:02:08 +00:00
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
if fields_to_show.blank?
fields_to_show = [
"honor_type",
"year",
"award_name",
"authors",
"awarding_unit"
]
end
honor_list = []
honors.each do |honor|
t = []
fields_to_show.each do |fs|
case fs
when "award_name"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(honor.to_param)}'>" + (honor.send(fs) rescue "") + "</a>"}
when "honor_type"
t << {"value" => (honor.send("honor_type").title rescue "")}
when "authors"
t << {"value" => (honor.send(:member_profile).name rescue "")}
else
t << {"value" => (honor.send(fs) rescue "")}
end
end
honor_list << {"personal_honors" => t}
end
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "award_name"
header = fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")
headers << {
"head-title" => header,
"col" => col
2014-07-03 04:53:38 +00:00
}
end
2016-03-21 11:02:08 +00:00
2014-07-03 04:53:38 +00:00
{
"honors" => honor_list,
2016-03-21 11:02:08 +00:00
"extras" => {"widget-title" => t("module_name.personal_honor")},
"headers" => headers,
2014-07-18 07:03:24 +00:00
"total_pages" => honors.total_pages
2014-07-03 04:53:38 +00:00
}
end
def show
params = OrbitHelper.params
2014-08-01 11:47:43 +00:00
plugin = Honor.where(:is_hidden=>false).find_by(uid: params[:uid])
fields_to_show = [
2015-01-09 07:44:32 +00:00
"year",
"honor_type",
2014-08-01 11:47:43 +00:00
"award_name",
2016-04-05 18:09:04 +00:00
"award_date",
"country",
2014-08-01 11:47:43 +00:00
"honoree",
"awarding_unit",
"keywords",
"url",
"note"
]
2014-07-03 04:53:38 +00:00
2014-08-01 11:47:43 +00:00
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
2014-07-03 04:53:38 +00:00
end
2016-03-21 11:02:08 +00:00
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = [
"year",
"award_name",
"awarding_unit",
"honor_type",
2016-04-05 18:09:04 +00:00
"award_date",
"country",
2016-03-21 11:02:08 +00:00
"keywords",
"url",
"note",
"authors",
"award_winner"
]
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]}
@default_fields_to_show = [
"honor_type",
"year",
"award_name",
"authors",
"awarding_unit"
]
render :layout => false
end
def save_index_fields
page = Page.find(params[:page_id]) rescue nil
page.custom_array_field = params[:keys]
page.save
render :json => {"success" => true}.to_json
end
2014-07-03 04:53:38 +00:00
end