44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
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)
|
|
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
|
|
|
|
def render_unique_number(f,column,i)
|
|
select_values = column.column_entries.distinct(:number)
|
|
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
|