Add new Accordion list template with expanded setting feature.

This commit is contained in:
BoHung Chiu 2022-04-08 11:20:21 +08:00
parent 32855e3ff3
commit 2226d59446
9 changed files with 205 additions and 106 deletions

View File

@ -1,4 +1,8 @@
class ArchivesController < ApplicationController
def self.custom_widget_data
ac = ActionController::Base.new
ac.render_to_string("archives/custom_widget_data",:locals=>{:@custom_data_field=>@custom_data_field,:@field_name=>@field_name})
end
#avoid the categories to be not in the ArchiveCategory
def serve_cmap
serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__)
@ -9,8 +13,17 @@ class ArchivesController < ApplicationController
end
end
def index
page = OrbitHelper.page rescue nil
unless page
page = Page.where(url:params['url']).first
end
params = OrbitHelper.params
@@total_pages = 1
in_class = ""
custom_data_field = page.custom_data_field rescue nil
if custom_data_field && custom_data_field["expanded"] == "yes"
in_class = "in"
end
cats_last = []
sort_order = (ArchiveSortOrder.first['sort_order'] rescue false) ? 1 : -1 #Order with ascending
if !params['title'].nil?
@ -313,7 +326,8 @@ class ArchivesController < ApplicationController
"date-head" => I18n.t("archive.updated_at"),
"title-head" => I18n.t(:name),
"description-head"=>I18n.t("archive.description"),
"file-head" =>I18n.t("archive.download_file")
"file-head" =>I18n.t("archive.download_file"),
"in_class" => in_class
}
}
end

View File

@ -0,0 +1,20 @@
<% active_expanded = @custom_data_field[:expanded] rescue nil %>
<div class="control-group input-content hide archive_expanded">
<label class="control-label muted" for="custom_expanded"><%=t("archive.expanded")%> :</label>
<div class="controls">
<%= select_tag("#{@field_name}[custom_data_field][expanded]", options_for_select(["yes","no"].map{|opt| [t("archive.#{opt}"),opt]},active_expanded),{:id=>"custom_expanded"})%>
</div>
</div>
<script type="text/javascript">
if($("#page_layout").val() == "archive_index12"){
$(".archive_expanded").addClass("show").removeClass("hide");
}
$("#page_layout").change(function(){
var value = $(this).val();
if(value == "archive_index12"){
$(".archive_expanded").addClass("show").removeClass("hide");
}else{
$(".archive_expanded").removeClass("show").addClass("hide");
}
})
</script>

View File

@ -1,2 +1,8 @@
<%= render_view %>
<% data = action_data %>
<% if data["categories"].length == 1 %>
<script>
$("#main-content .panel-collapse").addClass("in");
</script>
<% end %>
<%= create_pagination(ArchivesController.get_total_pages).html_safe %>

View File

@ -3,6 +3,8 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "archive/version"
require 'json'
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
env_pwd = ENV['PWD']
app_path = File.expand_path(__dir__)
template_path = env_pwd + '/app/templates'
@ -13,7 +15,7 @@ all_template.each do |folder|
next unless File.exist?("#{folder}modules/archive/info.json")
info_json_file = "#{folder}modules/archive/info.json"
info_json = JSON.parse(File.read(info_json_file))
check_files = ["archive_index7.html.erb","archive_index8.html.erb","archive_index9.html.erb","archive_index10.html.erb","archive_index11.html.erb"]
check_files = ["archive_index7.html.erb","archive_index8.html.erb","archive_index9.html.erb","archive_index10.html.erb","archive_index11.html.erb","archive_index12.html.erb"]
old_file_infos = [
{
"filename" => "archive_index7",
@ -72,6 +74,14 @@ all_template.each do |folder|
"en" => "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)"
},
"thumbnail" => "ar9.png"
},
{
"filename" => "archive_index12",
"name" => {
"zh_tw" => "12. 手風琴式列表 - 有下拉 ( 模組標題, 類別標題, 檔案名稱, 下載連結 )",
"en" => "12. Accordion list - with drop down (widget-title, category, filename, download link)"
},
"thumbnail" => "ar2.png"
}
]
flags = []
@ -93,7 +103,7 @@ all_template.each do |folder|
end
flags << flag
end
force_update_files = ["archive_index1.html.erb","archive_index3.html.erb"]
force_update_files = ["archive_index1.html.erb","archive_index3.html.erb","archive_index12.html.erb"]
puts "updating archive index page"
if flags.select{|flag| flag }.count != 0
flags.each_with_index do |flag,i|
@ -117,6 +127,7 @@ all_template.each do |folder|
end
end
end
end
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "archive"

View File

@ -2,6 +2,7 @@ en:
restful_actions:
categories_order: Categories Order
archive:
expanded: Expanded
other: Other
serial_number: "Serial Number"
url_text: "URL Text"

View File

@ -2,6 +2,7 @@ zh_tw:
restful_actions:
categories_order: 類別排序
archive:
expanded: 展開的
other: 其他
serial_number: "編號"
url_text: "連結文字"

View File

@ -16,7 +16,7 @@ module Archive
module_label "archive.archive"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget","group_by_category"]
widget_settings [{"data_count"=>30}]
widget_settings [{"data_count"=>30,"enable_custom_widget_data"=>true}]
models_to_cache [:archive_file]
taggable "ArchiveFile"
categorizable

View File

@ -0,0 +1,38 @@
<div class="i-archive index-archive-2">
<h3 class="i-archive-title">
<span>{{page-title}}</span>
</h3>
<div class="panel-group" id="index-archive-group" data-list="categories" data-level="0">
<div class="panel panel-default">
<div class="panel-heading" style="padding: 0.625em 0.9375em;">
<h4 class="panel-title">
<i class="fa fa-file-text" aria-hidden="true"></i>
<a data-toggle="collapse" data-parent="#index-archive-group" href="#collapse" class="collapsed" style="padding: 0;display: inline-block;">
{{category-title}}
<i class="fa fa-chevron-down" aria-hidden="true"></i>
</a>
</h4>
</div>
<div id="collapse" class="panel-collapse collapse {{in_class}}">
<div class="panel-body">
<dl class="dl-horizontal i-archive-item-group" data-list="archives" data-level="1">
<dt class="i-archive-item-list">
<sapn class="i-archive-item-title">{{archive-title}}</span>
<span data-list="statuses" data-level="2">
<span class="label status {{status-class}}">{{status}}</span>
</span>
</dt>
<dl class="i-archive-files-list" data-list="files" data-level="2">
<dd>
<a href="{{file-url}}" class="i-archive-files-item" target="_blank">{{file-name}}</a>
<span class="label label-primary">{{file-type}}</span>
</dd>
</dl>
</dl>
</div>
</div>
</div>
{{link_to_edit}}
</div>
</div>

View File

@ -87,6 +87,14 @@
"en" : "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)"
},
"thumbnail" : "ar9.png"
},
{
"filename" : "archive_index12",
"name" : {
"zh_tw" : "12. 手風琴式列表 - 有下拉 ( 模組標題, 類別標題, 檔案名稱, 下載連結 )",
"en" : "12. Accordion list - with drop down (widget-title, category, filename, download link)"
},
"thumbnail" : "ar2.png"
}
],
"widgets" : [