From 8d7893a67732e6f26881e714704fa2129996ec5d Mon Sep 17 00:00:00 2001 From: Bohung Date: Wed, 7 Apr 2021 20:00:15 +0800 Subject: [PATCH] Add read more position option. --- app/controllers/announcements_controller.rb | 72 +++++++++++++++++++-- config/locales/en.yml | 6 ++ config/locales/zh_tw.yml | 6 ++ lib/announcement/engine.rb | 43 ++++++++---- 4 files changed, 108 insertions(+), 19 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index e4f5ac8..896a02c 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -219,12 +219,16 @@ class AnnouncementsController < ApplicationController $(document).ready(function(){ var first_filter_tab = $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .filter_tab").eq(0); var read_more_url = first_filter_tab.data("read_more"); - if(read_more_url.length != 0) - $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").attr("href",read_more_url) + if(read_more_url.length != 0){ + $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").attr("href",read_more_url); + $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text(first_filter_tab.text()); + } $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .filter_tab").click(function(){ var read_more_url = $(this).data("read_more"); - if(read_more_url.length != 0) - $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").attr("href",read_more_url) + if(read_more_url.length != 0){ + $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").attr("href",read_more_url); + $("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text($(this).text()); + } }) }) @@ -255,7 +259,51 @@ class AnnouncementsController < ApplicationController ' else - extra_html = "" + read_more_text = I18n.t("announcement.more") + if cats.count == 1 && cats[0] != "all" + begin + read_more_text = cats_translations[cats[0]] + rescue + nil + end + end + extra_html = " + + " + end + if (@read_more_option != 0 rescue false) + extra_html += " + + " end { "announcements" => anns, @@ -280,7 +328,9 @@ class AnnouncementsController < ApplicationController def get_tabs_option subpart = OrbitHelper.get_current_widget tab_options = ["not_enable_tabs","enable_tabs_with_categories_include_all","enable_tabs_with_categories"] + read_more_options = ['default','upper_left','lower_left','upper_right','lower_right'] @tab_option = 0 + @read_more_option = 0 if subpart.methods.include? 'select_options'.to_sym ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| @show_options = modile_app.show_options rescue nil @@ -298,6 +348,18 @@ class AnnouncementsController < ApplicationController end end end + if !(@show_options.nil?) && select_option.field_name == @show_options.keys[2].to_s + value = YAML.load(select_option.value) + tmp = value[:en] + I18n.with_locale(:en) do + read_more_options.each_with_index do |option,i| + if tmp == t("announcement.#{option}") + @read_more_option = i + break + end + end + end + end end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 62ac504..dda692e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,6 +3,12 @@ en: feed: Feed import: Import announcement: + read_more_position_options: '"read more" button position' + default: Default + upper_left: Upper left + lower_left: Lower left + upper_right: Upper right + lower_right: Lower right tabs_options: Tabs options not_enable_tabs: Not enable tabs enable_tabs_with_categories_include_all: Enable tabs with categories(include all) diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 34290b8..e2df933 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -3,6 +3,12 @@ zh_tw: feed: 供給 import: 匯入 announcement: + read_more_position_options: '"更多"按鈕的位置' + default: 預設 + upper_left: 左上 + lower_left: 左下 + upper_right: 右上 + lower_right: 右下 tabs_options: 頁籤選項 not_enable_tabs: 無頁籤 enable_tabs_with_categories_include_all: 開啟頁籤(依類別,並包含全部所選類別之頁籤) diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index dcaddfd..4233045 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -7,12 +7,10 @@ module Announcement data = {} key1 = {} key2 = {} - value1 = {} - value2 = {} - value3 = {} - value4 = {} - value5 = {} - value6 = {} + key3 = {} + key1_attr = [] + key2_attr = [] + key3_attr = [] data_item = {} key_item1 = {} key_item2 = {} @@ -22,17 +20,33 @@ module Announcement value_item3 = {} value2_item1 = {} value2_item2 = {} + key1_options = ['small_size','medium_size','orignal_size'] + key2_options = ['not_enable_tabs','enable_tabs_with_categories_include_all','enable_tabs_with_categories'] + key3_options = ['default','upper_left','lower_left','upper_right','lower_right'] + key1_options.each_with_index do |k,i| + key1_attr[i] = {} + end + key2_options.each_with_index do |k,i| + key2_attr[i] = {} + end + key3_options.each_with_index do |k,i| + key3_attr[i] = {} + end translate_data.each do |t_data| v = t_data.values k = t_data.keys[0] key1[k] = v[0]['announcement']['picture_showing_size'] key2[k] = v[0]['announcement']['tabs_options'] - value1[k] = v[0]['announcement']['small_size'] - value2[k] = v[0]['announcement']['medium_size'] - value3[k] = v[0]['announcement']['orignal_size'] - value4[k] = v[0]['announcement']['not_enable_tabs'] - value5[k] = v[0]['announcement']['enable_tabs_with_categories_include_all'] - value6[k] = v[0]['announcement']['enable_tabs_with_categories'] + key3[k] = v[0]['announcement']['read_more_position_options'] + key1_options.each_with_index do |kk,i| + key1_attr[i][k] = v[0]['announcement'][kk] + end + key2_options.each_with_index do |kk,i| + key2_attr[i][k] = v[0]['announcement'][kk] + end + key3_options.each_with_index do |kk,i| + key3_attr[i][k] = v[0]['announcement'][kk] + end key_item1[k] = v[0]['announcement']['showing_back_and_next'] key_item2[k] = v[0]['announcement']['enable_search'] value_item1[k] = v[0]['announcement']['not_show'] @@ -41,8 +55,9 @@ module Announcement value2_item1[k] = v[0]['announcement']['no'] value2_item2[k] = v[0]['announcement']['yes'] end - data[key1] = [value1,value2,value3] - data[key2] = [value4,value5,value6] + data[key1] = key1_attr + data[key2] = key2_attr + data[key3] = key3_attr data_item[key_item1] = [value_item1,value_item2,value_item3] data_item[key_item2] = [value2_item1,value2_item2] require File.expand_path('../../../app/models/anns_cache', __FILE__)