From 52b22f3f453e27a2c55280ca35d4e1b78f5406dc Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 1 Aug 2014 19:47:43 +0800 Subject: [PATCH] Update frontend --- app/controllers/personal_honors_controller.rb | 32 +++++++----------- app/models/honor.rb | 33 +++++++++++++++++++ config/locales/en.yml | 2 ++ config/locales/zh_tw.yml | 2 ++ 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/app/controllers/personal_honors_controller.rb b/app/controllers/personal_honors_controller.rb index b0ef06c..e06cfb4 100644 --- a/app/controllers/personal_honors_controller.rb +++ b/app/controllers/personal_honors_controller.rb @@ -26,26 +26,18 @@ class PersonalHonorsController < ApplicationController def show params = OrbitHelper.params - honor = Honor.where(:is_hidden=>false).find_by(uid: params[:uid]) + plugin = Honor.where(:is_hidden=>false).find_by(uid: params[:uid]) + fields_to_show = [ + "award_name", + "honoree", + "awarding_unit", + "year", + "honor_type", + "keywords", + "url", + "note" + ] - { - "year" => honor.year, - "honor_type" => honor.honor_type.title, - "award_name" => honor.award_name, - "awarding_unit" => honor.awarding_unit, - "language" => t(honor.language), - "keywords" => honor.keywords, - "url" => honor.url, - "note" => honor.note, - - "th_year" => t("personal_honor.year"), - "th_honor_type" => t("personal_honor.honor_category"), - "th_award_name" => t("personal_honor.award_name"), - "th_awarding_unit" => t("personal_honor.awarding_unit"), - "th_language" => t("personal_honor.language"), - "th_keywords" => t("personal_honor.keywords"), - "th_url" => t("personal_honor.url"), - "th_note" => t("personal_honor.note") - } + {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} end end \ No newline at end of file diff --git a/app/models/honor.rb b/app/models/honor.rb index 6f39ad1..a1486d6 100644 --- a/app/models/honor.rb +++ b/app/models/honor.rb @@ -26,6 +26,39 @@ class Honor self.award_name+' '+self.awarding_unit 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 "honoree" + value = self.member_profile.name + when "language" + value = I18n.t(self.language) rescue "" + when "honor_type" + value = self.honor_type.title rescue "" + else + value = self.send(field) rescue "" + end + + value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{value}" : value + + { + "key"=>field, + "title_class"=>"honor-#{field.gsub('_','-')}-field", + "value_class"=>"honor-#{field.gsub('_','-')}-value", + "title"=>I18n.t('personal_honor.'+field), + "value"=>value + } + end + protected def add_http diff --git a/config/locales/en.yml b/config/locales/en.yml index 2a51361..acab000 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,8 +8,10 @@ en: award_name : "Award Name" awarding_unit : "Awarding Unit" honor_category : "Honor Category" + honor_type: "Honor Category" extracted_chapters : "Extracted Chapters" publishers : "Publishers" + honoree: "Honoree" authors : "Authors" tags : "Tags" year : "Year" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index ded4bf8..b98684c 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -8,6 +8,8 @@ zh_tw: award_name : "獎項名稱" awarding_unit : "頒獎單位" honor_category : "類別" + honor_type: "類別" + honoree: "受獎人" authors : "作者" tags : "領域" year : "年度"