Update frontend

This commit is contained in:
manson 2014-08-01 19:46:28 +08:00
parent 893313741f
commit 774df67db0
2 changed files with 42 additions and 25 deletions

View File

@ -26,32 +26,20 @@ class PersonalDiplomasController < ApplicationController
def show
params = OrbitHelper.params
diploma = Diploma.where(:is_hidden=>false).find_by(uid: params[:uid])
plugin = Diploma.where(:is_hidden=>false).find_by(uid: params[:uid])
{
"school_name" => diploma.school_name,
"country" => diploma.country,
"department" => diploma.department,
"degree" => diploma.degree,
"language" => t(diploma.language),
"keywords" => diploma.keywords,
"start_date" => diploma.start_date,
"end_date" => diploma.end_date,
"duration" => diploma.duration,
"url" => diploma.url,
"note" => diploma.note,
fields_to_show = [
"name",
"school_name",
"duration",
"country",
"department",
"degree",
"url",
"keywords",
"note"
]
"th_school_name" => t("personal_diploma.school_name"),
"th_country" => t("personal_diploma.country"),
"th_department" => t("personal_diploma.department"),
"th_degree" => t("personal_diploma.degree"),
"th_language" => t("personal_diploma.language"),
"th_keywords" => t("personal_diploma.keywords"),
"th_start_date" => t("personal_diploma.start_date"),
"th_end_date" => t("personal_diploma.end_date"),
"th_duration" => t("personal_diploma.duration"),
"th_url" => t("personal_diploma.url"),
"th_note" => t("personal_diploma.note")
}
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
end

View File

@ -37,6 +37,35 @@ class Diploma
[self.school_name,self.department,self.degree].join(' ')
end
def get_plugin_data(fields_to_show)
plugin_datas = []
fields_to_show.each do |field|
plugin_data = self.get_plugin_field_data(field)
next if plugin_data.blank? or plugin_data['value'].blank?
plugin_datas << plugin_data
end
plugin_datas
end
def get_plugin_field_data(field)
case field
when "language"
value = I18n.t(self.language) rescue ""
else
value = self.send(field) rescue ""
end
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value
{
"key"=>field,
"title_class"=>"diploma-#{field.gsub('_','-')}-field",
"value_class"=>"diploma-#{field.gsub('_','-')}-value",
"title"=>I18n.t('personal_diploma.'+field),
"value"=>value
}
end
protected
def add_http