fix for backend and added frontend support

This commit is contained in:
rulingcom 2025-05-19 21:33:33 +08:00
parent de407b718f
commit afb146abb9
5 changed files with 116 additions and 58 deletions

View File

@ -686,6 +686,7 @@ class CurationsController < ApplicationController
end
announcement = CurationPost.where(:uid => uid).first if announcement.nil?
return nil if announcement.nil?
return {} if (announcement.category.disable rescue false)
@bulletin = announcement
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/curations/#{announcement.id.to_s}/edit" : ""
@ -701,8 +702,34 @@ class CurationsController < ApplicationController
return {}
end
end
return {} if (announcement.category.disable rescue false)
module_app = ModuleApp.find_by_key("universal_table")
sections = []
sections = announcement.curation_post_sections.map do |section|
if section.section_type == "universal_table"
entries = section.get_table_entries.map do |entry|
{
"uid" => entry.uid,
"type" => section.section_type,
"url_to_show" => OrbitHelper.cal_url_to_show(module_app, entry),
"text" => entry.column_entries.first.text
}
end
{
"section" => section.title,
"entries" => entries,
"text" => ""
}
elsif section.section_type == "text"
{
"section" => section.title,
"entries" => [],
"uid" => "",
"type" => section.section_type,
"url_to_show" => "",
"text" => section.text.html_safe
}
end
end
if !announcement.deadline.nil? && announcement.deadline < Time.now
return {
@ -819,6 +846,7 @@ class CurationsController < ApplicationController
"tags" => tags,
"bulletin_files" => files,
"bulletin_links" => links,
"sections" => sections,
"data" => {
"title" => announcement.title,
"subtitle_ann" => subtitle_ann,

View File

@ -758,55 +758,66 @@
}
})
<% if defined? UniversalTable %>
var selectedUTable = null;
var select2Options = {
maximumSelectionSize: 10,
minimumResultsForSearch: Infinity,
multiple: true,
minimumInputLength: 2,
placeholder: "<%= t("curation.search_entries") %>",
ajax: {
type: 'get',
url: "",
allowClear: true,
dataType: 'json',
delay: 250,
data: function (term) {
var query = {
q: term
}
return query;
var selectedUTable = null;
var select2Options = {
maximumSelectionSize: 10,
minimumResultsForSearch: Infinity,
multiple: true,
minimumInputLength: 2,
placeholder: "<%= t("curation.search_entries") %>",
ajax: {
type: 'get',
url: "",
allowClear: true,
dataType: 'json',
delay: 250,
data: function (term) {
var query = {
q: term
}
return query;
},
results: function(data, page) {
return {
results: data
};
},
cache: true
},
results: function(data, page) {
return {
results: data
};
},
cache: true
},
formatResult: function(i) {
return '<div>' + i.text + '</div>';
}, // Formats results in drop down
formatSelection: function(i) {
return '<div>' + i.text + '</div>';
}, //Formats result that is selected
escapeMarkup: function(m) {
return m;
} // we do not want to escape markup since we are displaying html in results
}
$(document).on('change', '.section_type_ut select', function(){
var parent = $(this).parents(".curation_section");
if($(this).val()){
selectedUTable = $(this).val();
parent.find(".section_type_ut_entries").show();
select2Options.ajax.url = "/admin/universal_tables/get_entries?uid=" + selectedUTable;
parent.find('.section_type_ut_entries input.select2').select2(select2Options);
}else{
parent.find(".section_type_ut_entries").hide();
parent.find('.section_type_ut_entries input.select2').select2('destroy');
formatResult: function(i) {
return '<div>' + i.text + '</div>';
}, // Formats results in drop down
formatSelection: function(i) {
return '<div>' + i.text + '</div>';
}, //Formats result that is selected
escapeMarkup: function(m) {
return m;
} // we do not want to escape markup since we are displaying html in results
}
})
$(document).on('change', '.section_type_ut select', function(){
var parent = $(this).parents(".curation_section");
if($(this).val()){
selectedUTable = $(this).val();
parent.find(".section_type_ut_entries").show();
select2Options.ajax.url = "/admin/universal_tables/get_entries?uid=" + selectedUTable;
parent.find('.section_type_ut_entries input.select2').select2(select2Options);
}else{
parent.find(".section_type_ut_entries").hide();
parent.find('.section_type_ut_entries input.select2').select2('destroy');
}
})
$('.select2').each(function () {
const data = $(this).data('value');
if (data) {
$(this).select2({
data: data,
multiple: true,
width: '100%'
}).val(data.map(i => i.id)).trigger('change');
} else {
$(this).select2({ multiple: true, width: '100%' });
}
});
<% end %>
$("#enable_sub_annc").click(function(){

View File

@ -42,7 +42,7 @@
class: 'form-control' %>
</span>
<span class="tab-content section_type_text" style="display:none">
<span class="tab-content section_type_text" style="<%= !form_section_post.new_record? && form_section_post.section_type == 'text' ? '' : 'display:none' %>">
<span class="add-on"><%= t("curation.text") %></span>
<% @site_in_use_locales.each_with_index do |locale, i| %>
<span class="tab-pane fade <%= ( i == 0 ) ? "in active" : '' %> <%= locale %>">
@ -53,18 +53,27 @@
<% end %>
</span>
<% if defined? UniversalTable %>
<span class="tab-content section_type_ut" style="display:none">
<span class="tab-content section_type_ut" style="<%= !form_section_post.new_record? && form_section_post.section_type == 'universal_table' ? '' : 'display:none' %>">
<span class="add-on"><%= t("curation.tables") %></span>
<%= f.select :universal_table, UTable.all.map { |table| [table.title, table.uid] },
{ include_blank: t("curation.please_select") },
class: 'form-control' %>
</span>
<span class="tab-content section_type_ut_entries" style="display:none">
<span class="add-on"><%= t("curation.table_entries") %></span>
<%= f.text_field :table_entries, :class => "select2" %>
</span>
<% if !form_section_post.new_record? && form_section_post.section_type == "universal_table" %>
<%
tbData = form_section_post.get_table_entries.map{|tb| {id: tb.id.to_s, text: tb.column_entries.first.text}}
%>
<span class="tab-content section_type_ut_entries">
<span class="add-on"><%= t("curation.table_entries") %></span>
<%= f.text_field :table_entries, :class => "select2", data: { value: tbData } %>
</span>
<% else %>
<span class="tab-content section_type_ut_entries" style="display:none">
<span class="add-on"><%= t("curation.table_entries") %></span>
<%= f.text_field :table_entries, :class => "select2" %>
</span>
<% end %>
<% end %>
<% if form_section_post.new_record? %>
<span class="delete_link add-on btn" title="<%= t(:delete_) %>">
<a class="icon-trash"></a>

View File

@ -70,7 +70,6 @@
}
</style>
<% end %>
<% if @show_back_and_next_flag==1 %>
<%= content %>
<% end %>
@ -182,4 +181,4 @@
<%= t('curation.send_comment') %>
</button>
</div>
<% end rescue nil %>
<% end rescue nil %>

View File

@ -40,6 +40,17 @@
<div class="s-annc__subtitle">{{subtitle_ann}}</div>
<div class="s-annc__post-body">{{body}}</div>
</section>
<div data-list="sections" data-level="0">
<div class="{{type}}">
<div>{{section}}</div>
<ul class="universal-table" data-list="entries" data-level="1">
<li>
<div><a href="{{url_to_show}}">{{text}}</a></div>
</li>
</ul>
<div class="text">{{text}}</div>
</div>
</div>
<div id="sub_anncs_list">{{sub_anncs_text}}</div>
<ul class="s-annc__related-wrap list-unstyled no-print">
<li class="s-annc__related-file">