2014-08-31 23:22:56 +02:00
|
|
|
var App = App || {};
|
|
|
|
|
2014-09-04 19:57:06 +02:00
|
|
|
App.Router = function(jQuery, util, appState) {
|
2014-08-31 23:22:56 +02:00
|
|
|
|
|
|
|
var root = '#/';
|
|
|
|
|
|
|
|
injectRoutes();
|
|
|
|
|
|
|
|
function navigateToMainPage() {
|
|
|
|
window.location.href = root;
|
|
|
|
};
|
|
|
|
|
|
|
|
function navigate(url) {
|
|
|
|
window.location.href = url;
|
|
|
|
};
|
|
|
|
|
|
|
|
function start() {
|
|
|
|
Path.listen();
|
|
|
|
};
|
|
|
|
|
|
|
|
function injectRoutes() {
|
2014-09-03 09:10:26 +02:00
|
|
|
inject('#/login', function() { return App.DI.get('loginPresenter'); });
|
|
|
|
inject('#/logout', function() { return App.DI.get('logoutPresenter'); });
|
|
|
|
inject('#/register', function() { return App.DI.get('registrationPresenter'); });
|
2014-08-31 23:22:56 +02:00
|
|
|
inject('#/users', function() { return App.DI.get('userListPresenter'); });
|
2014-09-03 19:07:53 +02:00
|
|
|
inject('#/users/:searchArgs', function() { return App.DI.get('userListPresenter'); });
|
|
|
|
inject('#/user/:userName', function() { return App.DI.get('userPresenter'); });
|
2014-08-31 23:22:56 +02:00
|
|
|
setRoot('#/users');
|
|
|
|
};
|
|
|
|
|
|
|
|
function setRoot(newRoot) {
|
|
|
|
root = newRoot;
|
|
|
|
Path.root(newRoot);
|
|
|
|
};
|
|
|
|
|
|
|
|
function inject(path, presenterGetter) {
|
|
|
|
Path.map(path).to(function() {
|
2014-09-03 09:10:26 +02:00
|
|
|
util.initContentPresenter(presenterGetter, this.params);
|
2014-08-31 23:22:56 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
start: start,
|
|
|
|
navigate: navigate,
|
|
|
|
navigateToMainPage: navigateToMainPage,
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
App.DI.registerSingleton('router', App.Router);
|