2020-01-29 11:26:44 +00:00
|
|
|
module Admin::OlympiamanagementsHelper
|
2020-03-11 09:54:43 +00:00
|
|
|
def create_pagination_olympia(page=1,fields=ClassSettingFields.all,extra_params="")
|
2020-01-29 11:26:44 +00:00
|
|
|
page = 1 if page == 0
|
2020-01-31 10:52:53 +00:00
|
|
|
per_page_num = 10.0
|
|
|
|
all_page_num = (fields.count / per_page_num).ceil
|
2020-02-04 11:24:13 +00:00
|
|
|
all_page_num = 1 if all_page_num == 0
|
2020-01-29 11:26:44 +00:00
|
|
|
pagination = '<div class="PageDetails">'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'<ol class="PageList">'+
|
2020-01-31 10:52:53 +00:00
|
|
|
((page == 1) ? '<li>['+t('olympiamanagement.prev_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page-1).to_s+'"> ['+t('olympiamanagement.prev_page')+'] </a></li>')
|
|
|
|
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) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
else
|
|
|
|
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
pagination +='<li>...</li>'
|
|
|
|
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
end
|
|
|
|
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
pagination +='<li>...</li>'
|
|
|
|
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
else
|
|
|
|
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
pagination +='<li>...</li>'
|
|
|
|
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
if all_page_num - page <= 7
|
|
|
|
(page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
else
|
|
|
|
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
pagination +='<li>...</li>'
|
|
|
|
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
|
|
|
|
end
|
|
|
|
pagination += (((page==all_page_num) ? '<li>['+t('olympiamanagement.next_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page+1).to_s+'"> ['+t('olympiamanagement.next_page')+'] </a></li>')+'</ol></div>')
|
2020-01-29 11:26:44 +00:00
|
|
|
end
|
|
|
|
end
|