personal-diploma/app/controllers/personal_diplomas_controlle...

111 lines
2.9 KiB
Ruby
Raw Normal View History

2014-07-03 04:52:47 +00:00
class PersonalDiplomasController < ApplicationController
def index
2022-07-26 11:09:38 +00:00
diplomas = Diploma.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
2017-02-24 09:58:40 +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 = [
"name",
"duration",
"school_name",
"degree"
]
end
2014-07-03 04:52:47 +00:00
diploma_list = diplomas.collect do |diploma|
{
2014-10-03 06:12:35 +00:00
"member" => (diploma.member_profile.name rescue ""),
2014-07-03 04:52:47 +00:00
"duration" => diploma.duration,
"school_name" => diploma.school_name,
"degree" => diploma.degree,
"link_to_show" => OrbitHelper.url_to_show(diploma.to_param)
}
end
2017-02-24 09:58:40 +00:00
diploma_list = []
diplomas.each do |diploma|
t = []
fields_to_show.each do |fs|
case fs
when "name"
t << {"value" => (diploma.member_profile.name rescue "")}
when "degree"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(diploma.to_param)}' target='_blank'>" + (diploma.send(fs) rescue "") + "</a>"}
when "start_date"
t << {"value" => (diploma.start_date.strftime("%Y/%m/%d") rescue "")}
when "end_date"
t << {"value" => (diploma.end_date.strftime("%Y/%m/%d") rescue "")}
else
t << {"value" => diploma.send(fs)}
end
end
diploma_list << {"diploma_list" => t}
end
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "degree"
headers << {
"head-title" => t("personal_diploma.#{fs}"),
"col" => col
}
end
2014-07-03 04:52:47 +00:00
{
2017-02-24 10:03:10 +00:00
"personal_diplomas" => diploma_list,
2017-02-24 09:58:40 +00:00
"headers" => headers,
"extras" => {"widget-title" => t("module_name.personal_diploma")},
2014-07-18 06:32:13 +00:00
"total_pages" => diplomas.total_pages
2014-07-03 04:52:47 +00:00
}
end
def show
params = OrbitHelper.params
2022-10-24 08:19:51 +00:00
plugin = Diploma.where(:is_hidden=>false).find_by(uid: params[:uid].to_s)
2014-07-03 04:52:47 +00:00
2014-08-01 11:46:28 +00:00
fields_to_show = [
"name",
"school_name",
"duration",
"country",
"department",
"degree",
2015-01-09 07:42:05 +00:00
"url"
2014-08-01 11:46:28 +00:00
]
2014-07-03 04:52:47 +00:00
2014-08-01 11:46:28 +00:00
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
2014-07-03 04:52:47 +00:00
end
2017-02-24 09:19:49 +00:00
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = [
"name",
"school_name",
"duration",
"country",
"department",
"degree",
2017-02-24 09:58:40 +00:00
"language",
"keywords",
"start_date",
"end_date",
"note",
2017-02-24 09:19:49 +00:00
"url"
]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_diploma.#{fs}"), fs]}
@default_fields_to_show = [
2017-02-24 09:58:40 +00:00
"name",
"school_name",
"duration",
"country",
"department",
"degree",
"url"
2017-02-24 09:19:49 +00:00
]
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:52:47 +00:00
end