universal_table/app/helpers/admin/universal_tables_helper.rb

44 lines
1.3 KiB
Ruby
Raw Normal View History

module Admin::UniversalTablesHelper
def format_date(date, format, for_editing=false)
case format
when "yyyy/MM/dd hh:mm"
f = "%Y/%m/%d %H:%M"
when "yyyy/MM/dd"
f = "%Y/%m/%d"
when "yyyy/MM"
f = "%Y/%m"
when "yyyy"
f = "%Y"
f = "%Y/%m" if for_editing
end
d = date.strftime(f) rescue ""
return d
end
def render_unique_texts(f,column,i)
select_values = column.column_entries.distinct(:text)
select = "<select id='#{column.key}_#{i}'>"
s = {"en" => "", "zh_tw" => ""}
select = select + "<option class='muted' value='#{s.to_json.html_safe}'>---------------Select---------------</option>"
select_values.each do |sv|
select = select + "<option value='#{sv.to_json.html_safe}'>#{sv[I18n.locale]}</option>"
end
select = select + "</select>"
"<div class='select-holder'> <span>Or</span> " + select + "</div>"
end
2022-02-25 06:49:00 +00:00
def render_unique_number(f,column,i)
select_values = column.column_entries.distinct(:number)
2022-02-25 06:49:00 +00:00
select = "<select id='#{column.key}_#{i}'>"
s = ""
select = select + "<option class='muted' value='#{s}'>---------------Select---------------</option>"
select_values.each do |sv|
select = select + "<option value='#{sv}'>#{sv}</option>"
end
select = select + "</select>"
"<div class='select-holder'> <span>Or</span> " + select + "</div>"
end
end