diff --git a/UI/WebServerResources/js/Contacts/AddressBook.service.js b/UI/WebServerResources/js/Contacts/AddressBook.service.js index f5c7457b8..5fd3912ac 100644 --- a/UI/WebServerResources/js/Contacts/AddressBook.service.js +++ b/UI/WebServerResources/js/Contacts/AddressBook.service.js @@ -32,7 +32,7 @@ * @desc The factory we'll use to register with Angular * @returns the AddressBook constructor */ - AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Card', 'Acl', function($q, $timeout, $log, Settings, Resource, Card, Acl) { + AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Card', 'Acl', 'Preferences', function($q, $timeout, $log, Settings, Resource, Card, Acl, Preferences) { angular.extend(AddressBook, { $q: $q, $timeout: $timeout, @@ -40,8 +40,10 @@ $$resource: new Resource(Settings.activeUser.folderURL + 'Contacts', Settings.activeUser), $Card: Card, $$Acl: Acl, + $Preferences: Preferences, activeUser: Settings.activeUser, - selectedFolder: null + selectedFolder: null, + $refreshTimeout: null }); return AddressBook; // return constructor @@ -102,7 +104,7 @@ /** * @memberof AddressBook - * @desc Set or get the list of addressbooks. Will instanciate a new AddressBook object for each item. + * @desc Set or get the list of addressbooks. Will instantiate a new AddressBook object for each item. * @param {array} [data] - the metadata of the addressbooks * @returns the list of addressbooks */ @@ -210,6 +212,27 @@ return count; }; + /** + * @function $startRefreshTimeout + * @memberof AddressBook.prototype + * @desc Starts the refresh timeout for the current selected address book + * / + AddressBook.prototype.$startRefreshTimeout = function() { + var _this = this; + + if (AddressBook.$refreshTimeout) + AddressBook.$timeout.cancel(AddressBook.$refreshTimeout); + + AddressBook.$Preferences.ready().then(function() { + // Restart the refresh timer, if needed + var refreshViewCheck = AddressBook.$Preferences.defaults.SOGoRefreshViewCheck; + if (refreshViewCheck && refreshViewCheck != 'manually') { + var f = angular.bind(_this, AddressBook.prototype.$reload); + AddressBook.$refreshTimeout = AddressBook.$timeout(f, refreshViewCheck.timeInterval()*1000); + } + }); + }; + /** * @function $reload * @memberof AddressBook.prototype @@ -219,6 +242,8 @@ AddressBook.prototype.$reload = function() { var _this = this; + this.$startRefreshTimeout(); + return AddressBook.$$resource.fetch(this.id, 'view') .then(function(response) { var index, card, @@ -441,6 +466,9 @@ }); // Instanciate Acl object _this.$acl = new AddressBook.$$Acl('Contacts/' + _this.id); + + _this.$startRefreshTimeout(); + return _this; }); }, function(data) { diff --git a/UI/WebServerResources/js/Contacts/AddressBookController.js b/UI/WebServerResources/js/Contacts/AddressBookController.js index e28f2ad67..f29bd25db 100644 --- a/UI/WebServerResources/js/Contacts/AddressBookController.js +++ b/UI/WebServerResources/js/Contacts/AddressBookController.js @@ -6,8 +6,8 @@ /** * @ngInject */ - AddressBookController.$inject = ['$scope', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'Preferences', 'sgSettings', 'stateAddressbooks', 'stateAddressbook']; - function AddressBookController($scope, $state, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Preferences, Settings, stateAddressbooks, stateAddressbook) { + AddressBookController.$inject = ['$scope', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook']; + function AddressBookController($scope, $state, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) { var vm = this; AddressBook.selectedFolder = stateAddressbook; @@ -98,15 +98,6 @@ vm.mode.search = false; vm.selectedFolder.$filter(''); } - - // Start the address book refresh timer based on user's preferences - Preferences.ready().then(function() { - var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck; - if (refreshViewCheck && refreshViewCheck != 'manually') { - var f = angular.bind(vm.selectedFolder, AddressBook.prototype.$reload); - $timeout(f, refreshViewCheck.timeInterval()*1000); - } - }); } angular diff --git a/UI/WebServerResources/js/Mailer/Mailbox.service.js b/UI/WebServerResources/js/Mailer/Mailbox.service.js index 110ac6b37..f780fe81f 100644 --- a/UI/WebServerResources/js/Mailer/Mailbox.service.js +++ b/UI/WebServerResources/js/Mailer/Mailbox.service.js @@ -42,6 +42,7 @@ $Preferences: Preferences, $query: { sort: 'date', asc: 0 }, selectedFolder: null, + $refreshTimeout: null, PRELOAD: PRELOAD }); // Initialize sort parameters from user's settings @@ -212,6 +213,10 @@ this.$isLoading = true; return Mailbox.$Preferences.ready().then(function() { + + if (Mailbox.$refreshTimeout) + Mailbox.$timeout.cancel(Mailbox.$refreshTimeout); + if (sortingAttributes) // Sorting preferences are common to all mailboxes angular.extend(Mailbox.$query, sortingAttributes); @@ -234,6 +239,13 @@ }); } + // Restart the refresh timer, if needed + var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck; + if (refreshViewCheck && refreshViewCheck != 'manually') { + var f = angular.bind(_this, Mailbox.prototype.$filter); + Mailbox.$refreshTimeout = Mailbox.$timeout(f, refreshViewCheck.timeInterval()*1000); + } + var futureMailboxData = Mailbox.$$resource.post(_this.id, 'view', options); return _this.$unwrap(futureMailboxData); }); diff --git a/UI/WebServerResources/js/Mailer/MailboxController.js b/UI/WebServerResources/js/Mailer/MailboxController.js index d3410894d..6b04fa54f 100644 --- a/UI/WebServerResources/js/Mailer/MailboxController.js +++ b/UI/WebServerResources/js/Mailer/MailboxController.js @@ -6,8 +6,8 @@ /** * @ngInject */ - MailboxController.$inject = ['$state', '$timeout', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox', 'Preferences']; - function MailboxController($state, $timeout, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox, Preferences) { + MailboxController.$inject = ['$state', '$timeout', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox']; + function MailboxController($state, $timeout, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) { var vm = this; Mailbox.selectedFolder = stateMailbox; @@ -88,14 +88,6 @@ vm.selectedFolder.$filter(); } - // Start the mailbox refresh timer based on user's preferences - Preferences.ready().then(function() { - var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck; - if (refreshViewCheck && refreshViewCheck != 'manually') { - var f = angular.bind(vm.selectedFolder, Mailbox.prototype.$filter); - $timeout(f, refreshViewCheck.timeInterval()*1000); - } - }); } angular