Add all tabs setting.

Edit read more text and url.
This commit is contained in:
BoHung Chiu 2021-04-08 11:46:02 +08:00
parent 8d7893a677
commit 1900dada0a
5 changed files with 84 additions and 11 deletions

View File

@ -69,10 +69,10 @@ class AnnouncementsController < ApplicationController
params = OrbitHelper.params
page = Page.where(url:params['url']).first
@annc_page_title = nil
if params['category'] != page.categories
if (params['category'] != page.categories rescue true)
@annc_page_title = Category.find(Array(params['category']).first).title rescue nil
end
print params['category']
{
"announcements" => anns,
"extras" => {
@ -148,6 +148,9 @@ class AnnouncementsController < ApplicationController
if @tab_option == 1
cats = ["all"] + cats
anns = anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
if @all_setting_option == 0
anns = anns.deep_dup.map{|a| a["category"] = "All";a}[0...OrbitHelper.widget_data_count] + anns
end
end
cats = cats.uniq
cats_translations = cats.map{|cat_id|
@ -160,20 +163,37 @@ class AnnouncementsController < ApplicationController
}.to_h
cats_relations = cats_translations.map{|cat_id,t|
if cat_id == "all"
if @all_setting_option == 0
t = "All"
else
t = "all"
end
end
[cat_id,t]
}.to_h
page = Page.where(:page_id=> subpart.read_more_page_id).first rescue nil
page = Page.where(:module => "announcement").first rescue nil if page.nil?
all_cats = cats.dup
all_cats.delete "all"
if all_cats.count == 0
all_cats = ["all"]
end
if @tab_option != 0
OrbitHelper.set_widget_title(OrbitHelper.widget_title +
"<div style=\"clear: both;\"></div>" +
"<ul class=\"nav_tabs_filter\">" +
cats.map.with_index{|cat,i|
read_more_url = "/#{I18n.locale.to_s + page.url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>cat}.to_param if read_more_url != ""
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" data-read_more=\"#{read_more_url}\" data-category=\"#{cats_relations[cat]}\">#{cats_translations[cat]}</li>"
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
read_more_text = I18n.t("announcement.more")
if cat != "all"
begin
read_more_text = I18n.t("announcement.more_") + cats_translations[cat]
rescue
nil
end
end
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-category=\"#{cats_relations[cat]}\">#{cats_translations[cat]}</li>"
}.join("") +
"</ul>"
)
@ -221,13 +241,13 @@ class AnnouncementsController < ApplicationController
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);
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text(first_filter_tab.text());
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text(first_filter_tab.data("read_more_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);
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text($(this).text());
$("[data-subpart-id=\"'+subpart.id.to_s+'\"] .w-annc__more").text($(this).data("read_more_text"));
}
})
})
@ -262,7 +282,7 @@ class AnnouncementsController < ApplicationController
read_more_text = I18n.t("announcement.more")
if cats.count == 1 && cats[0] != "all"
begin
read_more_text = cats_translations[cats[0]]
read_more_text = I18n.t("announcement.more_") + cats_translations[cats[0]]
rescue
nil
end
@ -305,6 +325,25 @@ class AnnouncementsController < ApplicationController
</script>
"
end
extra_after_html = ""
if @all_setting_option == 0 && @tab_option == 1
max_all_count = [OrbitHelper.widget_data_count,anns.count / 2].min
extra_after_html = "
<script>
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] [data-list] [data-category]\").css(\"display\",\"none\");
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] [data-list] [data-category]:lt(#{max_all_count})\").css(\"display\",\"\");
</script>
"
end
read_more_url = "/#{I18n.locale.to_s + page.url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>all_cats}.to_param if read_more_url != ""
if @tab_option == 0
extra_after_html += "
<script>
$(\"[data-subpart-id=\\\"#{subpart.id}\\\"] .w-annc__more\").attr(\"href\",\"#{read_more_url}\");
</script>
"
end
{
"announcements" => anns,
"extras" => {
@ -319,9 +358,10 @@ class AnnouncementsController < ApplicationController
"category-head" => t('announcement.table.category'),
"link-head" => t('announcement.table.link'),
"file-head" => t('announcement.table.file'),
"read_more" => ("/#{I18n.locale.to_s + page.url}" rescue ""),
"read_more" => read_more_url,
"read_more_text" => "read more",
"extra_brefore_html" => extra_html
"extra_brefore_html" => extra_html,
"extra_after_html" => extra_after_html
}
}
end
@ -329,8 +369,10 @@ class AnnouncementsController < ApplicationController
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']
all_setting_options = ['the_same_as_data_count','display_all_in_other_tabs']
@tab_option = 0
@read_more_option = 0
@all_setting_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
@ -360,6 +402,18 @@ class AnnouncementsController < ApplicationController
end
end
end
if !(@show_options.nil?) && select_option.field_name == @show_options.keys[3].to_s
value = YAML.load(select_option.value)
tmp = value[:en]
I18n.with_locale(:en) do
all_setting_options.each_with_index do |option,i|
if tmp == t("announcement.#{option}")
@all_setting_option = i
break
end
end
end
end
end
end
end

View File

@ -198,7 +198,7 @@ module AnnouncementsHelper
else
tags = page.tags
tags = params[:tags] if params[:tags].present?
categories = params['category']=='all' ? (page.categories || []) : ([Category.find(params['category'])] rescue (page.categories || []))
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
categories = ["all"] if params[:tags].present?
end
if !params["source"].present?

View File

@ -3,6 +3,9 @@ en:
feed: Feed
import: Import
announcement:
all_tabs_setting: '"All" tab setting'
the_same_as_data_count: The same as data count
display_all_in_other_tabs: Display all contents in other tabs
read_more_position_options: '"read more" button position'
default: Default
upper_left: Upper left
@ -121,6 +124,7 @@ en:
index: Index
search: Search
more: More
more_: 'More '
email_reminder: Email Reminder
activate_email_reminder: Activate Email Reminder
email_sentdate: Email Time

View File

@ -3,6 +3,9 @@ zh_tw:
feed: 供給
import: 匯入
announcement:
all_tabs_setting: '"全部"頁籤設定'
the_same_as_data_count: 與Data count相同
display_all_in_other_tabs: 顯示在其他頁籤的全部內容
read_more_position_options: '"更多"按鈕的位置'
default: 預設
upper_left: 左上
@ -124,6 +127,7 @@ zh_tw:
index: 索引
search: 搜尋
more: 更多+
more_: 更多
email_reminder: 寄送提醒
activate_email_reminder: 開啟寄送提醒
email_sentdate: 寄送時間

View File

@ -8,9 +8,11 @@ module Announcement
key1 = {}
key2 = {}
key3 = {}
key4 = {}
key1_attr = []
key2_attr = []
key3_attr = []
key4_attr = []
data_item = {}
key_item1 = {}
key_item2 = {}
@ -23,6 +25,7 @@ module Announcement
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']
key4_options = ['the_same_as_data_count','display_all_in_other_tabs']
key1_options.each_with_index do |k,i|
key1_attr[i] = {}
end
@ -32,12 +35,16 @@ module Announcement
key3_options.each_with_index do |k,i|
key3_attr[i] = {}
end
key4_options.each_with_index do |k,i|
key4_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']
key3[k] = v[0]['announcement']['read_more_position_options']
key4[k] = v[0]['announcement']['all_tabs_setting']
key1_options.each_with_index do |kk,i|
key1_attr[i][k] = v[0]['announcement'][kk]
end
@ -47,6 +54,9 @@ module Announcement
key3_options.each_with_index do |kk,i|
key3_attr[i][k] = v[0]['announcement'][kk]
end
key4_options.each_with_index do |kk,i|
key4_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']
@ -58,6 +68,7 @@ module Announcement
data[key1] = key1_attr
data[key2] = key2_attr
data[key3] = key3_attr
data[key4] = key4_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__)