universal_table/app/helpers/admin/universal_tables_helper.rb

32 lines
869 B
Ruby

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).uniq
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
end