Skip to content

Commit

Permalink
page retention on requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lasky committed Mar 18, 2016
1 parent 0823ec6 commit dbc4873
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/shared/js/ajaxpageplugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
query:true,
body:false,
pageType:"offset",
countPath:""
countPath:"",
stampPage:true,
},config);
this.name = name;
};
Expand All @@ -47,6 +48,10 @@
if (opts.enabled) {
ajaxOpts = _getParamBase(ajaxOpts);
var page = opts.pageType === "offset" ? opts.page * opts.pageSize : opts.page;
if (opts.stampPage) {
ajaxOpts._page = opts.page
ajaxOpts._pageSize = opts.pageSize;
}

if (opts.url) {
if (opts.pageName) {
Expand Down Expand Up @@ -74,7 +79,20 @@
responseHandler:function(response) {

if (this.config.enabled && this.config.countPath) {
response.count = DataUtils.getValuePath("response." + this.config.countPath, response);
response.count = DataUtils.getPathValue("response." + this.config.countPath, response);
}

if (this.config.enabled && this.config.stampPage) {
var _page = DataUtils.getPathValue('instance.options._page', response);
var _pageSize = DataUtils.getPathValue('instance.options._pageSize', response);
var meta = DataUtils.getPathValue('marshalled.meta', response);
if (meta) {
meta._page = _page;
meta._pageSize = _pageSize;
} else {
response._page = _page;
response._pageSize = _pageSize;
}
}

return response;
Expand Down
1 change: 1 addition & 0 deletions src/shared/js/request.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
this.progress = options.progress;
this.requestMarshaller = options.requestMarshaller;
this.responseMarshaller = options.responseMarshaller;
this.options = options;

this.defer = {};
this.xhr = new XMLHttpRequest();
Expand Down
32 changes: 32 additions & 0 deletions test/lib_ajaxpageplugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,38 @@
result2.query[0].value.should.equal(2);
});

it("should be able to stamp the page data into the response", function() {
var pg1 = new StrandLib.AjaxPagePlugin({
enabled:true,
pageType:"index",
page:2,
stampPage:true
});
var result0 = pg1.requestHandler({body:{}});
result0.query[0].value.should.equal(2);
var result1 = pg1.responseHandler({
result:{},
instance:{
options:{
_page:1,
_pageSize:1}
},
marshalled:{meta:{}}});
result1.marshalled.meta._page.should.equal(1);
result1.marshalled.meta._pageSize.should.equal(1);
var result2 = pg1.responseHandler({
result:{},
instance:{
options:{
_page:1,
_pageSize:1}
},
});
result2._page.should.equal(1);
result2._pageSize.should.equal(1);

});

it("should stop when disabled", function() {
//disabled is default for paging since only collections need it
var pg = new StrandLib.AjaxPagePlugin();
Expand Down

0 comments on commit dbc4873

Please sign in to comment.