From 774df67db02183f82e0391d89be567a8a35026e8 Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 1 Aug 2014 19:46:28 +0800 Subject: [PATCH] Update frontend --- .../personal_diplomas_controller.rb | 38 +++++++------------ app/models/diploma.rb | 29 ++++++++++++++ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/app/controllers/personal_diplomas_controller.rb b/app/controllers/personal_diplomas_controller.rb index 6dd8557..92c3f7d 100644 --- a/app/controllers/personal_diplomas_controller.rb +++ b/app/controllers/personal_diplomas_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/diploma.rb b/app/models/diploma.rb index eab8cf6..ff47e27 100644 --- a/app/models/diploma.rb +++ b/app/models/diploma.rb @@ -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/) ? "#{value}" : 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