(js) Restore user's last Calendar view

Also reviewed the handling of Angular modules dependencies.
This commit is contained in:
Francis Lachapelle
2015-07-29 11:47:01 -04:00
parent 762f305914
commit 7e10cff395
16 changed files with 101 additions and 65 deletions
+16 -21
View File
@@ -4,22 +4,7 @@
(function() {
'use strict';
angular.module('SOGo.ContactsUI', []);
angular.module('SOGo.MailerUI', []);
angular.module('SOGo.PreferencesUI', []);
angular.module('SOGo.SchedulerUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.ContactsUI', 'SOGo.MailerUI', 'SOGo.PreferencesUI'])
.constant('sgSettings', {
baseURL: ApplicationBaseURL,
activeUser: {
login: UserLogin,
identification: UserIdentification,
language: UserLanguage,
folderURL: UserFolderURL,
isSuperUser: IsSuperUser
}
})
angular.module('SOGo.SchedulerUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.PreferencesUI', 'SOGo.ContactsUI', 'SOGo.MailerUI'])
.config(configure)
.run(runBlock);
@@ -67,19 +52,20 @@
// If no date is specified, show today
var now = new Date();
return '/calendar/day/' + now.getDayString();
})
});
$urlRouterProvider.when('/calendar/week', function() {
// If no date is specified, show today's week
var now = new Date();
return '/calendar/week/' + now.getDayString();
})
});
$urlRouterProvider.when('/calendar/month', function() {
// If no date is specified, show today's month
var now = new Date();
return '/calendar/month/' + now.getDayString();
});
// if none of the above states are matched, use this as the fallback
// If none of the above states are matched, use this as the fallback.
// runBlock will also act as a fallback by looking at user's settings
$urlRouterProvider.otherwise('/calendar');
}
@@ -102,11 +88,20 @@
/**
* @ngInject
*/
runBlock.$inject = ['$rootScope'];
function runBlock($rootScope) {
runBlock.$inject = ['$rootScope', '$location', 'Preferences'];
function runBlock($rootScope, $location, Preferences) {
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
console.error(event, current, previous, rejection);
});
if ($location.url().length === 0) {
// Restore user's last view
Preferences.ready().then(function() {
var view = /(.+)view/.exec(Preferences.settings.Calendar.View);
if (view) {
$location.replace().url('/calendar/' + view[1]);
}
});
}
}
})();