2016-04-10 22:13:01 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const settings = require('../models/settings.js');
|
2016-04-12 23:49:46 +02:00
|
|
|
const EndlessPageView = require('../views/endless_page_view.js');
|
2016-04-10 22:13:01 +02:00
|
|
|
const ManualPageView = require('../views/manual_page_view.js');
|
|
|
|
|
|
|
|
class PageController {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(ctx) {
|
|
|
|
const extendedContext = {
|
|
|
|
clientUrl: ctx.clientUrl,
|
|
|
|
searchQuery: ctx.searchQuery,
|
|
|
|
};
|
|
|
|
|
|
|
|
ctx.headerContext = Object.assign({}, extendedContext);
|
|
|
|
ctx.pageContext = Object.assign({}, extendedContext);
|
2016-04-12 23:49:46 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
if (settings.get().endlessScroll) {
|
|
|
|
this._view = new EndlessPageView(ctx);
|
2016-04-12 23:49:46 +02:00
|
|
|
} else {
|
2016-06-14 10:31:48 +02:00
|
|
|
this._view = new ManualPageView(ctx);
|
2016-04-12 23:49:46 +02:00
|
|
|
}
|
2016-04-10 22:13:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
showSuccess(message) {
|
|
|
|
this._view.showSuccess(message);
|
|
|
|
}
|
2016-06-11 09:59:29 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
showError(message) {
|
|
|
|
this._view.showError(message);
|
2016-04-10 22:13:01 +02:00
|
|
|
}
|
2016-04-12 23:49:46 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
static createHistoryCacheProxy(routerCtx, requestPage) {
|
2016-06-12 22:02:15 +02:00
|
|
|
return page => {
|
|
|
|
if (routerCtx.state.response) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
resolve(routerCtx.state.response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const promise = requestPage(page);
|
|
|
|
promise.then(response => {
|
|
|
|
routerCtx.state.response = response;
|
|
|
|
routerCtx.save();
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
}
|
2016-04-10 22:13:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
module.exports = PageController;
|