96 lines
2.9 KiB
HTML
96 lines
2.9 KiB
HTML
<script>
|
|
StrolchPagingBehavior = {
|
|
|
|
properties: {
|
|
dataObj: {
|
|
type: Object,
|
|
value: {
|
|
data: null,
|
|
offset: 0,
|
|
limit: 20,
|
|
dataSetSize: 0,
|
|
descending: true,
|
|
sortBy: 'id',
|
|
size: 0,
|
|
nextOffset: 0,
|
|
previousOffset: 0,
|
|
lastOffset: 0
|
|
}
|
|
},
|
|
scrollTarget: {
|
|
type: Object,
|
|
value: null
|
|
}
|
|
},
|
|
|
|
_getDefaultObj: function () {
|
|
return {
|
|
data: null,
|
|
offset: 0,
|
|
limit: 20,
|
|
dataSetSize: 0,
|
|
descending: true,
|
|
sortBy: 'id',
|
|
size: 0,
|
|
nextOffset: 0,
|
|
previousOffset: 0,
|
|
lastOffset: 0
|
|
}
|
|
},
|
|
|
|
_hasNext: function (dataObj) {
|
|
return dataObj != null && dataObj.nextOffset > dataObj.offset;
|
|
},
|
|
_hasPrevious: function (dataObj) {
|
|
return dataObj != null && dataObj.previousOffset < dataObj.offset;
|
|
},
|
|
|
|
_getEnd: function (dataObj) {
|
|
if (this._hasNext(dataObj)) return dataObj.nextOffset;
|
|
return dataObj == null ? 0 : dataObj.size;
|
|
},
|
|
|
|
_setLimit: function (e) {
|
|
this.dataObj.limit = parseInt(e.target.textContent.trim());
|
|
this.queryPage();
|
|
},
|
|
|
|
_toFirstPage: function () {
|
|
this.dataObj.offset = 0;
|
|
this.queryPage();
|
|
},
|
|
_toPreviousPage: function () {
|
|
this.dataObj.offset = this.dataObj.previousOffset;
|
|
this.queryPage();
|
|
},
|
|
_toNextPage: function () {
|
|
this.dataObj.offset = this.dataObj.nextOffset;
|
|
this.queryPage();
|
|
},
|
|
_toLastPage: function () {
|
|
this.dataObj.offset = this.dataObj.lastOffset;
|
|
this.queryPage();
|
|
},
|
|
queryPage: function () {
|
|
if (this.ajax == null) {
|
|
alert("Ajax not configured on paging behavior!");
|
|
return;
|
|
}
|
|
this.ajax.params.limit = this.dataObj.limit;
|
|
this.ajax.params.offset = this.dataObj.offset;
|
|
this.ajax.generateRequest();
|
|
this.ajax.addEventListener('response', this);
|
|
},
|
|
handleEvent: function (event) {
|
|
if (event.type !== "response")
|
|
return;
|
|
|
|
this.ajax.removeEventListener('response', this);
|
|
if (this.scrollTarget != null) {
|
|
this.scrollTarget.scrollIntoView({behavior: "smooth", block: "start", inline: "start"});
|
|
} else {
|
|
window.scrollTo({top: 0, left: 0, behavior: "smooth"});
|
|
}
|
|
}
|
|
};
|
|
</script> |