2014-09-11 13:59:12 +02:00
|
|
|
var App = App || {};
|
|
|
|
|
2014-09-29 18:11:21 +02:00
|
|
|
App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) {
|
2014-09-11 13:59:12 +02:00
|
|
|
|
2014-09-17 22:37:49 +02:00
|
|
|
var lastContentPresenter = null;
|
|
|
|
var $spinner;
|
|
|
|
var spinnerTimeout;
|
2014-09-11 13:59:12 +02:00
|
|
|
|
|
|
|
function init() {
|
2014-09-17 22:37:49 +02:00
|
|
|
initPresenter(topNavigationPresenter, [], function() {});
|
|
|
|
$spinner = jQuery('body').find('#wait');
|
2014-09-11 13:59:12 +02:00
|
|
|
}
|
|
|
|
|
2014-09-17 22:37:49 +02:00
|
|
|
function initPresenter(presenter, args, loaded) {
|
|
|
|
presenter.init.call(presenter, args, loaded);
|
2014-09-11 13:59:12 +02:00
|
|
|
}
|
|
|
|
|
2014-09-18 11:29:19 +02:00
|
|
|
function showContentSpinner() {
|
|
|
|
$spinner.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideContentSpinner() {
|
|
|
|
$spinner.hide();
|
|
|
|
}
|
|
|
|
|
2014-09-17 22:37:49 +02:00
|
|
|
function switchContentPresenter(presenter, args) {
|
|
|
|
var contentPresenterLoaded = function() {
|
|
|
|
window.clearTimeout(spinnerTimeout);
|
2014-09-18 11:29:19 +02:00
|
|
|
hideContentSpinner();
|
2014-09-17 22:37:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
spinnerTimeout = window.setTimeout(function() {
|
2014-09-18 11:29:19 +02:00
|
|
|
showContentSpinner();
|
|
|
|
}, 100);
|
2014-09-17 22:37:49 +02:00
|
|
|
|
|
|
|
if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) {
|
2014-09-29 18:11:21 +02:00
|
|
|
keyboard.reset();
|
2014-09-11 13:59:12 +02:00
|
|
|
topNavigationPresenter.changeTitle(null);
|
2014-09-17 22:37:49 +02:00
|
|
|
presenter.init.call(presenter, args, contentPresenterLoaded);
|
2014-09-11 13:59:12 +02:00
|
|
|
lastContentPresenter = presenter;
|
|
|
|
} else if (lastContentPresenter.reinit) {
|
2014-09-17 22:37:49 +02:00
|
|
|
lastContentPresenter.reinit.call(lastContentPresenter, args, contentPresenterLoaded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initPresenters(options, loaded) {
|
|
|
|
var count = 0;
|
|
|
|
var subPresenterLoaded = function() {
|
|
|
|
count ++;
|
|
|
|
if (count === options.length) {
|
|
|
|
loaded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < options.length; i ++) {
|
|
|
|
initPresenter(options[i][0], options[i][1], subPresenterLoaded);
|
2014-09-11 13:59:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
init: init,
|
2014-09-17 22:37:49 +02:00
|
|
|
initPresenter: initPresenter,
|
|
|
|
initPresenters: initPresenters,
|
2014-09-11 13:59:12 +02:00
|
|
|
switchContentPresenter: switchContentPresenter,
|
2014-09-18 11:29:19 +02:00
|
|
|
showContentSpinner: showContentSpinner,
|
|
|
|
hideContentSpinner: hideContentSpinner,
|
2014-09-11 13:59:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-09-29 18:11:21 +02:00
|
|
|
App.DI.registerSingleton('presenterManager', ['jQuery', 'topNavigationPresenter', 'keyboard'], App.PresenterManager);
|