mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Added 404 page
This commit is contained in:
48
public_html/js/Presenters/HttpErrorPresenter.js
Normal file
48
public_html/js/Presenters/HttpErrorPresenter.js
Normal file
@ -0,0 +1,48 @@
|
||||
var App = App || {};
|
||||
App.Presenters = App.Presenters || {};
|
||||
|
||||
App.Presenters.HttpErrorPresenter = function(
|
||||
jQuery,
|
||||
promise,
|
||||
util,
|
||||
topNavigationPresenter) {
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var templates = {};
|
||||
|
||||
function init(params, loaded) {
|
||||
topNavigationPresenter.changeTitle('Error ' + params.error);
|
||||
|
||||
if (params.error === 404) {
|
||||
promise.wait(util.promiseTemplate('404'))
|
||||
.then(function(template) {
|
||||
templates.errorPage = template;
|
||||
reinit(params, loaded);
|
||||
}).fail(function() {
|
||||
console.log(arguments);
|
||||
loaded();
|
||||
});
|
||||
} else {
|
||||
console.log('Not supported.');
|
||||
loaded();
|
||||
}
|
||||
}
|
||||
|
||||
function reinit(params, loaded) {
|
||||
render();
|
||||
loaded();
|
||||
}
|
||||
|
||||
function render() {
|
||||
$el.html(templates.errorPage());
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
reinit: reinit,
|
||||
render: render,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('httpErrorPresenter', ['jQuery', 'promise', 'util', 'topNavigationPresenter'], App.Presenters.HttpErrorPresenter);
|
@ -11,6 +11,7 @@ App.Router = function(_, jQuery, promise, util, appState, presenterManager) {
|
||||
function injectRoutes() {
|
||||
inject('', 'homePresenter');
|
||||
inject('#/', 'homePresenter');
|
||||
inject('#/404', 'httpErrorPresenter', {error: 404});
|
||||
inject('#/home', 'homePresenter');
|
||||
inject('#/login', 'loginPresenter');
|
||||
inject('#/logout', 'logoutPresenter');
|
||||
@ -28,20 +29,29 @@ App.Router = function(_, jQuery, promise, util, appState, presenterManager) {
|
||||
inject('#/help(/:tab)', 'helpPresenter');
|
||||
}
|
||||
|
||||
function navigate(url) {
|
||||
window.location.href = url;
|
||||
function navigate(url, useBrowserDispatcher) {
|
||||
if (('pushState' in history) && !useBrowserDispatcher) {
|
||||
history.pushState('', '', url);
|
||||
dispatch();
|
||||
} else {
|
||||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
|
||||
function navigateToMainPage() {
|
||||
navigate(root);
|
||||
}
|
||||
|
||||
function navigateInplace(url) {
|
||||
function navigateInplace(url, useBrowserDispatcher) {
|
||||
if ('replaceState' in history) {
|
||||
history.replaceState('', '', url);
|
||||
dispatch();
|
||||
if (!useBrowserDispatcher) {
|
||||
dispatch();
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
} else {
|
||||
navigate(url);
|
||||
navigate(url, useBrowserDispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,8 +100,7 @@ App.Router = function(_, jQuery, promise, util, appState, presenterManager) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//todo: 404
|
||||
console.log(new Error('Unhandled route: ' + url));
|
||||
navigateInplace('#/404', true);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user