2016-11-02 20:54:04 -04:00
|
|
|
/* global Vue, gl */
|
2016-11-08 16:57:16 -05:00
|
|
|
/* eslint-disable no-param-reassign, no-plusplus */
|
2016-11-02 20:54:04 -04:00
|
|
|
|
|
|
|
((gl) => {
|
|
|
|
gl.VueGlPagination = Vue.extend({
|
|
|
|
props: [
|
|
|
|
'changepage',
|
2016-11-03 00:41:51 -04:00
|
|
|
'count',
|
2016-11-03 13:20:15 -04:00
|
|
|
'pagenum',
|
2016-11-02 20:54:04 -04:00
|
|
|
],
|
2016-11-03 00:41:51 -04:00
|
|
|
computed: {
|
2016-11-08 17:03:25 -05:00
|
|
|
last() {
|
2016-11-10 14:46:29 -05:00
|
|
|
return Math.ceil(+this.count / 30);
|
2016-11-08 17:03:25 -05:00
|
|
|
},
|
2016-11-08 14:23:29 -05:00
|
|
|
getItems() {
|
2016-11-08 16:59:20 -05:00
|
|
|
const total = +this.last;
|
2016-11-08 16:57:16 -05:00
|
|
|
const page = +this.pagenum;
|
2016-11-08 14:23:29 -05:00
|
|
|
const items = [];
|
|
|
|
|
2016-11-08 16:59:20 -05:00
|
|
|
if (page > 1) items.push({ title: '<< First', where: 1 });
|
2016-11-08 16:57:16 -05:00
|
|
|
|
|
|
|
if (page > 1) {
|
|
|
|
items.push({ title: 'Prev', where: page - 1 });
|
|
|
|
} else {
|
|
|
|
items.push({ title: 'Prev', where: page - 1, disabled: true });
|
|
|
|
}
|
2016-11-08 14:23:29 -05:00
|
|
|
|
2016-11-08 16:59:20 -05:00
|
|
|
if (page > 6) items.push({ title: '...', separator: true });
|
2016-11-08 14:23:29 -05:00
|
|
|
|
2016-11-08 16:57:16 -05:00
|
|
|
const start = Math.max(page - 4, 1);
|
|
|
|
const end = Math.min(page + 4, total);
|
2016-11-08 16:23:16 -05:00
|
|
|
|
2016-11-08 16:57:16 -05:00
|
|
|
for (let i = start; i <= end; i++) {
|
|
|
|
const isActive = i === page;
|
|
|
|
items.push({ title: i, active: isActive, where: i });
|
|
|
|
}
|
2016-11-08 16:23:16 -05:00
|
|
|
|
2016-11-08 16:59:20 -05:00
|
|
|
if (total - page > 4) items.push({ title: '...', separator: true });
|
2016-11-08 16:57:16 -05:00
|
|
|
|
|
|
|
if (page === total) {
|
|
|
|
items.push({ title: 'Next', where: page + 1, disabled: true });
|
|
|
|
} else if (total - page >= 1) {
|
|
|
|
items.push({ title: 'Next', where: page + 1 });
|
|
|
|
}
|
|
|
|
|
2016-11-08 16:59:20 -05:00
|
|
|
if (total - page >= 1) items.push({ title: 'Last >>', where: total });
|
2016-11-08 14:23:29 -05:00
|
|
|
|
|
|
|
return items;
|
2016-11-03 13:20:15 -04:00
|
|
|
},
|
2016-11-03 00:41:51 -04:00
|
|
|
},
|
2016-11-02 20:54:04 -04:00
|
|
|
template: `
|
|
|
|
<div class="gl-pagination">
|
2016-11-08 16:57:16 -05:00
|
|
|
<ul class="pagination clearfix" v-for='item in getItems'>
|
2016-11-08 16:23:16 -05:00
|
|
|
<li
|
2016-11-08 16:57:16 -05:00
|
|
|
:class='{
|
|
|
|
separator: item.separator,
|
|
|
|
active: item.active,
|
|
|
|
disabled: item.disabled
|
|
|
|
}'
|
2016-11-08 16:23:16 -05:00
|
|
|
>
|
2016-11-08 16:57:16 -05:00
|
|
|
<span
|
|
|
|
@click="changepage($event, item.where)"
|
|
|
|
>
|
|
|
|
{{item.title}}
|
|
|
|
</span>
|
2016-11-08 16:23:16 -05:00
|
|
|
</li>
|
2016-11-02 20:54:04 -04:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
})(window.gl || (window.gl = {}));
|