2019-09-14 19:03:38 +00:00
|
|
|
const Pages = {
|
|
|
|
oninit: function(vnode) {
|
2022-07-20 00:33:06 +00:00
|
|
|
this.onbeforeupdate(vnode)
|
|
|
|
},
|
|
|
|
|
|
|
|
onbeforeupdate: function(vnode) {
|
|
|
|
this.total = vnode.attrs.total
|
|
|
|
this.currentPage = vnode.attrs.page
|
|
|
|
this.perPage = vnode.attrs.perPage || 10
|
|
|
|
this.maxPage = this.total / this.perPage + 1
|
2019-09-14 19:03:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
view: function(vnode) {
|
2022-07-20 00:33:06 +00:00
|
|
|
if (this.total <= this.perPage) return null
|
2019-09-14 19:03:38 +00:00
|
|
|
return m('pages', [
|
2022-07-20 00:33:06 +00:00
|
|
|
this.currentPage > 1
|
|
|
|
? [
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: vnode.attrs.base,
|
|
|
|
}, 'First'),
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: vnode.attrs.base + (this.currentPage > 2
|
|
|
|
? '?page=' + (this.currentPage - 1)
|
|
|
|
: ''
|
|
|
|
),
|
|
|
|
}, 'Previous'),
|
|
|
|
]
|
2019-09-14 19:03:38 +00:00
|
|
|
: m('div'),
|
2022-07-20 00:33:06 +00:00
|
|
|
m('div', 'Page ' + this.currentPage),
|
|
|
|
this.currentPage < this.maxPage
|
|
|
|
? [
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: vnode.attrs.base + '?page=' + (this.currentPage + 1),
|
|
|
|
}, 'Next'),
|
|
|
|
m(m.route.Link, {
|
|
|
|
href: vnode.attrs.base + '?page=' + this.maxPage,
|
|
|
|
}, 'Last')
|
|
|
|
]
|
2019-09-14 19:03:38 +00:00
|
|
|
: m('div'),
|
|
|
|
])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Pages
|