fix error

This commit is contained in:
chiu 2022-10-14 22:33:04 +08:00
parent 8a9c8fc17f
commit e5c79ad013
3 changed files with 50 additions and 45 deletions

View File

@ -154,8 +154,7 @@ class Admin::AsksController < OrbitAdminController
@categories = @module_app.categories.enabled.sort_by{|category| (((@module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)} @categories = @module_app.categories.enabled.sort_by{|category| (((@module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
@filter_fields = filter_fields(@categories) @filter_fields = filter_fields(@categories)
# 列表欄位 # 列表欄位
@table_fields_default_fields = @ask_list_setting.default_fields.select{|f| @ask_setting.default_setting[f].nil? || @ask_setting.default_setting[f] } @table_fields = @ask_list_setting.default_fields.select{|f| @ask_setting.default_setting[f].nil? || @ask_setting.default_setting[f] }
@table_fields = @table_fields_default_fields.map{|v| ['title'].include?(v) ? v : "ask.#{v}"}
if @category_id.present? if @category_id.present?
ask_setting = AskCategorySetting.where(:category_id=>@category_id).first ask_setting = AskCategorySetting.where(:category_id=>@category_id).first
tmp = ask_setting.custom_fields tmp = ask_setting.custom_fields

View File

@ -67,7 +67,7 @@ class AskSetting
self.default_setting_required[k] self.default_setting_required[k]
end end
def default_field_name(k,locale=I18n.locale.to_s,use_checkbox_trans=false) def default_field_name(k,locale=I18n.locale.to_s,use_checkbox_trans=false)
I18n.with_locale(locale){ (use_checkbox_trans && ['agree_show','agree_usage'].include?(k.to_s)) ? I18n.t("ask.#{k}_checkbox") : I18n.t("mongoid.attributes.ask_question.#{k}")} I18n.with_locale(locale){ (use_checkbox_trans && ['agree_show','agree_usage'].include?(k.to_s)) ? I18n.t("ask.#{k}_checkbox") : ['serial_number','situation','ip'].include?(k) ? I18n.t("ask.#{k}") : I18n.t("mongoid.attributes.ask_question.#{k}")}
end end
def field_name_translations(k) def field_name_translations(k)

View File

@ -170,8 +170,7 @@
<tr class="sort-header"> <tr class="sort-header">
<th style="width: 1em;"></th> <th style="width: 1em;"></th>
<% @table_fields.each do |f| %> <% @table_fields.each do |f| %>
<% tmp = f.to_s.gsub(/ask\./,'') %> <%= ask_thead(f, @ask_setting.field_name(f)) %>
<%= thead(f) %>
<% end %> <% end %>
<% @table_ext_fields.each do |f, v| %> <% @table_ext_fields.each do |f, v| %>
<%= ask_thead(f, v['field'][I18n.locale.to_s]) %> <%= ask_thead(f, v['field'][I18n.locale.to_s]) %>
@ -189,53 +188,60 @@
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
last_serial_number = @ask_setting.last_serial_number last_serial_number = @ask_setting.last_serial_number
display_length = [last_serial_number.to_s.length + 1, 4].max display_length = [last_serial_number.to_s.length + 1, 4].max
edit_button_display_index = @table_fields.count > 3 ? 2 : @table_fields.count
%> %>
<% @askquestions.each do |b| %> <% @askquestions.each do |b| %>
<tr> <tr>
<% is_editable = can_edit_or_delete?(b) %> <% is_editable = can_edit_or_delete?(b)
ask_show_url = Page.where(:module=>'ask').first.url rescue nil
edit_button_can_show = true
%>
<% content_for :edit_button do %>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if is_editable %>
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/asks/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/print" target="_blank"><%= t('ask.print') %></a></li>
</ul>
</div>
<% end %>
<td><% if is_editable %><input type="checkbox" class="batch_select" data-id="<%= b.id %>"><% end %></td> <td><% if is_editable %><input type="checkbox" class="batch_select" data-id="<%= b.id %>"><% end %></td>
<% @table_fields_default_fields.each do |f| %> <% @table_fields.each_with_index do |f,i| %>
<% case f %>
<% when 'serial_number' %>
<td><%= b.get_serial_number(last_serial_number, display_length) %></td>
<% when 'situation' %>
<td> <td>
<span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span> <% case f %>
</td> <% when 'serial_number' %>
<% when 'ask_category_id' %> <%= b.get_serial_number(last_serial_number, display_length) %>
<td> <% when 'situation' %>
<%= b.category.title rescue 'category not set' %> <span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span>
<div class="quick-edit"> <% when 'ask_category_id' %>
<ul class="nav nav-pills"> <%= b.category.title rescue 'category not set' %>
<% if is_editable %> <% when 'sex' %>
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li> <%= ['male','female'].include?(sex.to_s) ? t("mongoid.attributes.ask_question.#{sex}") : '' %>
<li><a href="#" class="delete text-error" rel="/admin/asks/<%=b.id.to_s%>"><%= t(:delete_) %></a></li> <% when 'mail' %>
<% end %> <%= b.mail %>
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/print" target="_blank"><%= t('ask.print') %></a></li> <% when 'title' %>
</ul> <% if b.situation == 'is_published' %>
</div> <%= link_to b.title, (ask_show_url ? (ask_show_url+"?item=#{b.id}") : "javascript:alert('#{t('ask.no_index_page')}')") %>
</td> <% else %>
<% when 'title' %> <%= b.title %>
<td> <% end %>
<% if b.situation == 'is_published' %> <% when 'name' %>
<%= link_to b.title,((Page.where(:module=>'ask').first.url+"?item=#{b.id}") rescue "javascript:alert('#{t('ask.no_index_page')}')") %> <%= b.name %>
<% else %> <% when 'phone' %>
<%= b.title %> <%= b.phone %>
<% when 'appointment' %>
<%= b.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %>
<% when 'created_at' %>
<%= b.created_at.strftime("%Y-%m-%d %H:%M") rescue nil %>
<% when 'ip' %>
<%= b.ip %>
<% end %>
<% if edit_button_display_index == i %>
<%= yield :edit_button %>
<% end %> <% end %>
</td> </td>
<% when 'name' %>
<td>
<%= b.name %>
</td>
<% when 'phone' %>
<td><%= b.phone %></td>
<% when 'appointment' %>
<td><%= b.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<% when 'created_at' %>
<td><%= b.created_at.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<% when 'ip' %>
<td><%= b.ip %></td>
<% end %>
<% end %> <% end %>
<% @table_ext_fields.each do |f, v| %> <% @table_ext_fields.each do |f, v| %>
<td> <td>