module Admin::OlympiamanagementsHelper
def create_pagination(page=1,fields=ClassSettingFields.all,extra_params="")
page = 1 if page == 0
per_page_num = 10.0
all_page_num = (fields.count / per_page_num).ceil
pagination = '
'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'
'+
((page == 1) ? '- ['+t('olympiamanagement.prev_page')+']
' : '- ['+t('olympiamanagement.prev_page')+']
')
if all_page_num > 7
if page <= (all_page_num / 2)
if page <= 7
(1..page).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
else
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
pagination +='- ...
'
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
end
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
pagination +='- ...
'
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
else
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
pagination +='- ...
'
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
if all_page_num - page <= 7
(page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
else
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
pagination +='- ...
'
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
end
end
else
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '- ['+page_num.to_s+']
' : '- '+page_num.to_s+'
')}
end
pagination += (((page==all_page_num) ? '- ['+t('olympiamanagement.next_page')+']
' : '- ['+t('olympiamanagement.next_page')+']
')+'
')
end
end