nfp_sites/nfp_moe/app/paginator.js
2022-08-18 09:59:48 +00:00

39 lines
1 KiB
JavaScript

const Paginator = {
view: function(vnode) {
let total = vnode.attrs.total
let currentPage = vnode.attrs.page
let perPage = vnode.attrs.perPage || 10
let maxPage = total / perPage + 1
if (total <= perPage) return null
return m('paginator', [
currentPage > 1
? [
m(m.route.Link, {
href: vnode.attrs.base,
}, 'First'),
m(m.route.Link, {
href: vnode.attrs.base + (currentPage > 2
? '?page=' + (currentPage - 1)
: ''
),
}, 'Previous'),
]
: [ m('div'), m('div')],
m('div', 'Page ' + currentPage),
currentPage < maxPage
? [
m(m.route.Link, {
href: vnode.attrs.base + '?page=' + (currentPage + 1),
}, 'Next'),
m(m.route.Link, {
href: vnode.attrs.base + '?page=' + maxPage,
}, 'Last')
]
: [ m('div'), m('div')],
])
},
}
module.exports = Paginator