diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 15478c4ff..f90b00720 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -9,7 +9,7 @@ xmlns:label="OGo:label" className="UIxPageFrame" title="title" - const:jsFiles="Preferences.app.js, Common.js, Mailer.js, Preferences.js"> + const:jsFiles="Preferences.app.js, Common.js, Mailer.js, Contacts.js, Preferences.js">
diff --git a/UI/WebServerResources/js/Common/Authentication.service.js b/UI/WebServerResources/js/Common/Authentication.service.js index cc839fc38..e3791073b 100644 --- a/UI/WebServerResources/js/Common/Authentication.service.js +++ b/UI/WebServerResources/js/Common/Authentication.service.js @@ -1,5 +1,5 @@ /* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* JavaScript for SOGoContacts */ +/* JavaScript for Authentication */ (function() { 'use strict'; @@ -23,197 +23,196 @@ }) // TODO: convert to a Factory recipe? - .provider('Authentication', function(passwordPolicyConfig) { - this.readCookie = function(name) { - var foundCookie, prefix, pairs, i, currentPair, start; - foundCookie = null; - prefix = name + '='; - pairs = document.cookie.split(';'); - for (i = 0; !foundCookie && i < pairs.length; i++) { - currentPair = pairs[i]; - start = 0; - while (currentPair.charAt(start) == ' ') - start++; - if (start > 0) - currentPair = currentPair.substr(start); - if (currentPair.indexOf(prefix) == 0) - foundCookie = currentPair.substr(prefix.length); - } + .provider('Authentication', Authentication); - return foundCookie; - }; + /** + * @ngInject + */ + function Authentication() { + function readCookie(name) { + var foundCookie, prefix, pairs, i, currentPair, start; + foundCookie = null; + prefix = name + '='; + pairs = document.cookie.split(';'); + for (i = 0; !foundCookie && i < pairs.length; i++) { + currentPair = pairs[i]; + start = 0; + while (currentPair.charAt(start) == ' ') + start++; + if (start > 0) + currentPair = currentPair.substr(start); + if (currentPair.indexOf(prefix) == 0) + foundCookie = currentPair.substr(prefix.length); + } - this.readLoginCookie = function() { - var loginValues = null, - cookie = this.readCookie('0xHIGHFLYxSOGo'), - value; - if (cookie && cookie.length > 8) { - value = decodeURIComponent(cookie.substr(8)); - loginValues = value.base64decode().split(':'); - } + return foundCookie; + } - return loginValues; - }; + function readLoginCookie() { + var loginValues = null, + cookie = readCookie('0xHIGHFLYxSOGo'), + value; + if (cookie && cookie.length > 8) { + value = decodeURIComponent(cookie.substr(8)); + loginValues = value.base64decode().split(':'); + } - this.redirectUrl = function(username, domain) { - var userName, address, baseAddress, altBaseAddress, parts, hostpart, protocol, newAddress; + return loginValues; + } - userName = username; - if (domain) - userName += '@' + domain.value; - address = '' + window.location.href; - baseAddress = ApplicationBaseURL + '/' + encodeURIComponent(userName); - if (baseAddress[0] == '/') { - parts = address.split('/'); - hostpart = parts[2]; - protocol = parts[0]; - baseAddress = protocol + '//' + hostpart + baseAddress; - } - parts = baseAddress.split('/'); - parts.splice(0, 3); - altBaseAddress = parts.join('/'); - newAddress; - if ((address.startsWith(baseAddress) - || address.startsWith(altBaseAddress)) - && !address.endsWith('/logoff')) { - newAddress = address; - } else { - newAddress = baseAddress; - } + function redirectUrl(username, domain) { + var userName, address, baseAddress, altBaseAddress, parts, hostpart, protocol, newAddress; - // if (/theme=mobile/.test(window.location.search)) { - // newAddress = baseAddress + '/Contacts' + '?theme=mobile'; - // } - // else { - // newAddress = baseAddress + '/Contacts'; - // } + userName = username; + if (domain) + userName += '@' + domain.value; + address = '' + window.location.href; + baseAddress = ApplicationBaseURL + '/' + encodeURIComponent(userName); + if (baseAddress[0] == '/') { + parts = address.split('/'); + hostpart = parts[2]; + protocol = parts[0]; + baseAddress = protocol + '//' + hostpart + baseAddress; + } + parts = baseAddress.split('/'); + parts.splice(0, 3); + altBaseAddress = parts.join('/'); + newAddress; + if ((address.startsWith(baseAddress) + || address.startsWith(altBaseAddress)) + && !address.endsWith('/logoff')) { + newAddress = address; + } else { + newAddress = baseAddress; + } - return newAddress; - }; + return newAddress; + } - this.$get = ['$q', '$http', function($q, $http) { - var _this = this, service; + this.$get = getService; - service = { - // login: function(username, password, domain, language, rememberLogin) { - // var d = $q.defer(); - login: function(data) { - var d = $q.defer(), - username = data.username, - password = data.password, - domain = data.domain, - language, - rememberLogin = data.rememberLogin ? 1 : 0; + getService.$inject = ['$q', '$http', 'passwordPolicyConfig'] + function getService($q, $http, passwordPolicyConfig) { + var _this = this, service; - if (data.loginSuffix && !username.endsWith(data.loginSuffix)) { - username += loginSuffix; - domain = false; - } - if (data.language && data.language != 'WONoSelectionString') { - language = data.language; - } + service = { + login: function(data) { + var d = $q.defer(), + username = data.username, + password = data.password, + domain = data.domain, + language, + rememberLogin = data.rememberLogin ? 1 : 0; - $http({ - method: 'POST', - url: '/SOGo/connect', - data: { - userName: username, - password: password, - domain: domain, - language: language, - rememberLogin: rememberLogin - } - }).success(function(data, status) { - // Make sure browser's cookies are enabled - var loginCookie = _this.readLoginCookie(); - if (!loginCookie) { - d.reject(l('cookiesNotEnabled')); - } - else { - // Check password policy - if (typeof data.expire != 'undefined' && typeof data.grace != 'undefined') { - if (data.expire < 0 && data.grace > 0) { - d.reject({grace: data.grace}); - //showPasswordDialog('grace', createPasswordGraceDialog, data['grace']); - } else if (data.expire > 0 && data.grace == -1) { - d.reject({expire: data.expire}); - //showPasswordDialog('expiration', createPasswordExpirationDialog, data['expire']); - } - else { - d.resolve(_this.redirectUrl(username, domain)); - } - } - else { - d.resolve(_this.redirectUrl(username, domain)); - } - } - }).error(function(data, status) { - var msg, perr; - if (data && data.LDAPPasswordPolicyError) { - perr = data.LDAPPasswordPolicyError; - if (perr == passwordPolicyConfig.PolicyNoError) { - msg = l('Wrong username or password.'); - } - else if (perr == passwordPolicyConfig.PolicyAccountLocked) { - msg = l('Your account was locked due to too many failed attempts.'); - } - else { - msg = l('Login failed due to unhandled error case: ') + perr; - } - } - else { - msg = l('Unhandled error response'); - } - d.reject({error: msg}); - }); - return d.promise; - }, // login: function(data) { ... - - changePassword: function(newPassword) { - var d = $q.defer(), - loginCookie = _this.readLoginCookie(); - - $http({ - method: 'POST', - url: '/SOGo/so/changePassword', - data: { - userName: loginCookie[0], - password: loginCookie[1], - newPassword: newPassword } - }).success(function(data, status) { - d.resolve(); - }).error(function(data, status) { - var error, - perr = data["LDAPPasswordPolicyError"]; - - if (!perr) { - perr = passwordPolicyConfig.PolicyPasswordSystemUnknown; - error = _("Unhandled error response"); - } - else if (perr == passwordPolicyConfig.PolicyNoError) { - error = l("Password change failed"); - } else if (perr == passwordPolicyConfig.PolicyPasswordModNotAllowed) { - error = l("Password change failed - Permission denied"); - } else if (perr == passwordPolicyConfig.PolicyInsufficientPasswordQuality) { - error = l("Password change failed - Insufficient password quality"); - } else if (perr == passwordPolicyConfig.PolicyPasswordTooShort) { - error = l("Password change failed - Password is too short"); - } else if (perr == passwordPolicyConfig.PolicyPasswordTooYoung) { - error = l("Password change failed - Password is too young"); - } else if (perr == passwordPolicyConfig.PolicyPasswordInHistory) { - error = l("Password change failed - Password is in history"); - } else { - error = l("Unhandled policy error: %{0}").formatted(perr); - perr = passwordPolicyConfig.PolicyPasswordUnknown; - } - - d.reject(error); - }); - return d.promise; + if (data.loginSuffix && !username.endsWith(data.loginSuffix)) { + username += loginSuffix; + domain = false; } - }; - return service; - }]; - }); + if (data.language && data.language != 'WONoSelectionString') { + language = data.language; + } + + $http({ + method: 'POST', + url: '/SOGo/connect', + data: { + userName: username, + password: password, + domain: domain, + language: language, + rememberLogin: rememberLogin + } + }).success(function(data, status) { + // Make sure browser's cookies are enabled + var loginCookie = readLoginCookie(); + if (!loginCookie) { + d.reject(l('cookiesNotEnabled')); + } + else { + // Check password policy + if (typeof data.expire != 'undefined' && typeof data.grace != 'undefined') { + if (data.expire < 0 && data.grace > 0) { + d.reject({grace: data.grace}); + //showPasswordDialog('grace', createPasswordGraceDialog, data['grace']); + } else if (data.expire > 0 && data.grace == -1) { + d.reject({expire: data.expire}); + //showPasswordDialog('expiration', createPasswordExpirationDialog, data['expire']); + } + else { + d.resolve(redirectUrl(username, domain)); + } + } + else { + d.resolve(redirectUrl(username, domain)); + } + } + }).error(function(data, status) { + var msg, perr; + if (data && data.LDAPPasswordPolicyError) { + perr = data.LDAPPasswordPolicyError; + if (perr == passwordPolicyConfig.PolicyNoError) { + msg = l('Wrong username or password.'); + } + else if (perr == passwordPolicyConfig.PolicyAccountLocked) { + msg = l('Your account was locked due to too many failed attempts.'); + } + else { + msg = l('Login failed due to unhandled error case: ') + perr; + } + } + else { + msg = l('Unhandled error response'); + } + d.reject({error: msg}); + }); + return d.promise; + }, // login: function(data) { ... + + changePassword: function(newPassword) { + var d = $q.defer(), + loginCookie = _this.readLoginCookie(); + + $http({ + method: 'POST', + url: '/SOGo/so/changePassword', + data: { + userName: loginCookie[0], + password: loginCookie[1], + newPassword: newPassword } + }).success(function(data, status) { + d.resolve(); + }).error(function(data, status) { + var error, + perr = data["LDAPPasswordPolicyError"]; + + if (!perr) { + perr = passwordPolicyConfig.PolicyPasswordSystemUnknown; + error = _("Unhandled error response"); + } + else if (perr == passwordPolicyConfig.PolicyNoError) { + error = l("Password change failed"); + } else if (perr == passwordPolicyConfig.PolicyPasswordModNotAllowed) { + error = l("Password change failed - Permission denied"); + } else if (perr == passwordPolicyConfig.PolicyInsufficientPasswordQuality) { + error = l("Password change failed - Insufficient password quality"); + } else if (perr == passwordPolicyConfig.PolicyPasswordTooShort) { + error = l("Password change failed - Password is too short"); + } else if (perr == passwordPolicyConfig.PolicyPasswordTooYoung) { + error = l("Password change failed - Password is too young"); + } else if (perr == passwordPolicyConfig.PolicyPasswordInHistory) { + error = l("Password change failed - Password is in history"); + } else { + error = l("Unhandled policy error: %{0}").formatted(perr); + perr = passwordPolicyConfig.PolicyPasswordUnknown; + } + + d.reject(error); + }); + return d.promise; + } + }; + return service; + } + } })(); diff --git a/UI/WebServerResources/js/Common/Common.app.js b/UI/WebServerResources/js/Common/Common.app.js index e7814ca22..648ae855d 100644 --- a/UI/WebServerResources/js/Common/Common.app.js +++ b/UI/WebServerResources/js/Common/Common.app.js @@ -3,7 +3,7 @@ (function() { 'use strict'; - angular.module('SOGo.Common', ['ngMaterial', 'RecursionHelper']) + angular.module('SOGo.Common', ['ngMaterial']) // md break-points values are hard-coded in angular-material/src/core/util/constant.js // $mdMedia has a built-in support for those values but can also evaluate others // For some reasons, angular-material's break-points don't match the specs diff --git a/UI/WebServerResources/js/Common/sgSubscribe.directive.js b/UI/WebServerResources/js/Common/sgSubscribe.directive.js index f71b1945d..f836104f7 100644 --- a/UI/WebServerResources/js/Common/sgSubscribe.directive.js +++ b/UI/WebServerResources/js/Common/sgSubscribe.directive.js @@ -12,7 +12,7 @@ * @ngInject * @example: - Subscribe .. + Subscribe .. */ sgSubscribe.$inject = ['User']; function sgSubscribe(User) { @@ -28,66 +28,70 @@ controllerAs: 'vm', link: link } - sgSubscribeDialogController.$inject = ['$mdDialog']; - function sgSubscribeDialogController($mdDialog) { - var vm = this; - vm.showDialog = function() { - $mdDialog.show({ - templateUrl: '../Contacts/UIxContactsUserFolders', - clickOutsideToClose: true, - //scope: vm, - //preserveScope: true, - locals: { - folderType: vm.folderType, - onFolderSelect: vm.onFolderSelect - //User: User - }, - controller: sgSubscribeController, - controllerAs: 'vm' - }); - /** - * @ngInject - */ - sgSubscribeController.$inject = ['folderType', 'onFolderSelect', 'User']; - function sgSubscribeController(folderType, onFolderSelect, User) { - var vm = this; - vm.selectedUser = null; - - vm.searchTextOptions = { - updateOn: 'default blur', - debounce: { - default: 300, - blur: 0 - } - }; - - vm.onChange = function() { - User.$filter(vm.searchText).then(function(matches) { - vm.users = matches; - }); - }; - - vm.selectUser = function(i) { - // Fetch folders of specific type for selected user - vm.users[i].$folders(folderType).then(function() { - vm.selectedUser = vm.users[i]; - }); - }; - - // Callback upon subscription to a folder - vm.selectFolder = function(folder) { - onFolderSelect({folderData: folder}); - }; - } - }; - } - function link(scope, element, attrs, controller) { - var inputEl = element.find('input'); - element.on('click', controller.showDialog); - } } + /** + * @ngInject + */ + sgSubscribeDialogController.$inject = ['$mdDialog']; + function sgSubscribeDialogController($mdDialog) { + var vm = this; + vm.showDialog = function() { + $mdDialog.show({ + templateUrl: '../Contacts/UIxContactsUserFolders', + clickOutsideToClose: true, + locals: { + folderType: vm.folderType, + onFolderSelect: vm.onFolderSelect + }, + controller: sgSubscribeController, + controllerAs: 'vm' + }); + }; + } + + /** + * @ngInject + */ + sgSubscribeController.$inject = ['folderType', 'onFolderSelect', 'User']; + function sgSubscribeController(folderType, onFolderSelect, User) { + var vm = this; + vm.selectedUser = null; + + vm.searchTextOptions = { + updateOn: 'default blur', + debounce: { + default: 300, + blur: 0 + } + }; + + vm.onChange = function() { + User.$filter(vm.searchText).then(function(matches) { + vm.users = matches; + }); + }; + + vm.selectUser = function(i) { + // Fetch folders of specific type for selected user + vm.users[i].$folders(folderType).then(function() { + vm.selectedUser = vm.users[i]; + }); + }; + + // Callback upon subscription to a folder + vm.selectFolder = function(folder) { + onFolderSelect({folderData: folder}); + }; + } + + function link(scope, element, attrs, controller) { + var inputEl = element.find('input'); + element.on('click', controller.showDialog); + } + + angular .module('SOGo.Common') .directive('sgSubscribe', sgSubscribe); - })(); +})(); diff --git a/UI/WebServerResources/js/Contacts.app.js b/UI/WebServerResources/js/Contacts.app.js index 9d6863094..deeeb2a65 100644 --- a/UI/WebServerResources/js/Contacts.app.js +++ b/UI/WebServerResources/js/Contacts.app.js @@ -37,9 +37,7 @@ } }, resolve: { - stateAddressbooks: ['AddressBook', function(AddressBook) { - return AddressBook.$findAll(window.contactFolders); - }] + stateAddressbooks: stateAddressbooks } }) .state('app.addressbook', { @@ -51,9 +49,7 @@ } }, resolve: { - stateAddressbook: ['$stateParams', 'AddressBook', function($stateParams, AddressBook) { - return AddressBook.$find($stateParams.addressbookId); - }] + stateAddressbook: stateAddressbook } }) .state('app.addressbook.new', { @@ -65,11 +61,7 @@ } }, resolve: { - stateCard: ['$stateParams', 'stateAddressbook', 'Card', function($stateParams, stateAddressbook, Card) { - var tag = 'v' + $stateParams.contactType, - card = new Card({ pid: $stateParams.addressbookId, tag: tag }); - return card; - }] + stateCard: stateNewCard } }) .state('app.addressbook.card', { @@ -81,9 +73,7 @@ } }, resolve: { - stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) { - return stateAddressbook.$getCard($stateParams.cardId); - }] + stateCard: stateCard } }) .state('app.addressbook.card.view', { @@ -109,4 +99,38 @@ $urlRouterProvider.otherwise('/addressbooks/personal'); } + /** + * @ngInject + */ + stateAddressbooks.$inject = ['AddressBook']; + function stateAddressbooks(AddressBook) { + return AddressBook.$findAll(window.contactFolders); + } + + /** + * @ngInject + */ + stateAddressbook.$inject = ['$stateParams', 'AddressBook']; + function stateAddressbook($stateParams, AddressBook) { + return AddressBook.$find($stateParams.addressbookId); + } + + /** + * @ngInject + */ + stateNewCard.$inject = ['$stateParams', 'stateAddressbook', 'Card']; + function stateNewCard($stateParams, stateAddressbook, Card) { + var tag = 'v' + $stateParams.contactType, + card = new Card({ pid: $stateParams.addressbookId, tag: tag }); + return card; + } + + /** + * @ngInject + */ + stateCard.$inject = ['$stateParams', 'stateAddressbook']; + function stateCard($stateParams, stateAddressbook) { + return stateAddressbook.$getCard($stateParams.cardId); + } + })(); diff --git a/UI/WebServerResources/js/Mailer.app.js b/UI/WebServerResources/js/Mailer.app.js index fd00e41ca..f04b49189 100644 --- a/UI/WebServerResources/js/Mailer.app.js +++ b/UI/WebServerResources/js/Mailer.app.js @@ -37,18 +37,7 @@ } }, resolve: { - stateAccounts: ['$q', 'Account', function($q, Account) { - var accounts = Account.$findAll(mailAccounts); - var promises = []; - // Fetch list of mailboxes for each account - angular.forEach(accounts, function(account, i) { - var mailboxes = account.$getMailboxes(); - promises.push(mailboxes.then(function(objects) { - return account; - })); - }); - return $q.all(promises); - }] + stateAccounts: stateAccounts } }) .state('mail.account', { @@ -60,11 +49,7 @@ } }, resolve: { - stateAccount: ['$stateParams', 'stateAccounts', function($stateParams, stateAccounts) { - return _.find(stateAccounts, function(account) { - return account.id == $stateParams.accountId; - }); - }] + stateAccount: stateAccount } }) .state('mail.account.mailbox', { @@ -76,27 +61,8 @@ } }, resolve: { - stateMailbox: ['$stateParams', 'stateAccount', 'decodeUriFilter', function($stateParams, stateAccount, decodeUriFilter) { - var mailboxId = decodeUriFilter($stateParams.mailboxId); - // Recursive find function - var _find = function(mailboxes) { - var mailbox = _.find(mailboxes, function(o) { - return o.path == mailboxId; - }); - if (!mailbox) { - angular.forEach(mailboxes, function(o) { - if (!mailbox && o.children && o.children.length > 0) { - mailbox = _find(o.children); - } - }); - } - return mailbox; - }; - return _find(stateAccount.$mailboxes); - }], - stateMessages: ['stateMailbox', function(stateMailbox) { - return stateMailbox.$filter(); - }] + stateMailbox: stateMailbox, + stateMessages: stateMessages } }) .state('mail.account.mailbox.message', { @@ -108,17 +74,7 @@ } }, resolve: { - stateMessage: ['encodeUriFilter', '$stateParams', '$state', 'stateMailbox', 'stateMessages', function(encodeUriFilter, $stateParams, $state, stateMailbox, stateMessages) { - var message = _.find(stateMessages, function(messageObject) { - return messageObject.uid == $stateParams.messageId; - }); - - if (message) - return message.$reload(); - else - // Message not found - $state.go('mail.account.mailbox', { accountId: stateMailbox.$account.id, mailboxId: encodeUriFilter(stateMailbox.path) }); - }] + stateMessage: stateMessage } }) .state('mail.account.mailbox.message.edit', { @@ -130,9 +86,7 @@ } }, resolve: { - stateContent: ['stateMessage', function(stateMessage) { - return stateMessage.$editableContent(); - }] + stateContent: stateContent } }) .state('mail.account.mailbox.message.action', { @@ -172,6 +126,88 @@ // }); } + /** + * @ngInject + */ + stateAccounts.$inject = ['$q', 'Account']; + function stateAccounts($q, Account) { + var accounts = Account.$findAll(mailAccounts); + var promises = []; + // Fetch list of mailboxes for each account + angular.forEach(accounts, function(account, i) { + var mailboxes = account.$getMailboxes(); + promises.push(mailboxes.then(function(objects) { + return account; + })); + }); + return $q.all(promises); + } + + /** + * @ngInject + */ + stateAccount.$inject = ['$stateParams', 'stateAccounts']; + function stateAccount($stateParams, stateAccounts) { + return _.find(stateAccounts, function(account) { + return account.id == $stateParams.accountId; + }); + } + + /** + * @ngInject + */ + stateMailbox.$inject = ['$stateParams', 'stateAccount', 'decodeUriFilter']; + function stateMailbox($stateParams, stateAccount, decodeUriFilter) { + var mailboxId = decodeUriFilter($stateParams.mailboxId); + // Recursive find function + var _find = function(mailboxes) { + var mailbox = _.find(mailboxes, function(o) { + return o.path == mailboxId; + }); + if (!mailbox) { + angular.forEach(mailboxes, function(o) { + if (!mailbox && o.children && o.children.length > 0) { + mailbox = _find(o.children); + } + }); + } + return mailbox; + }; + return _find(stateAccount.$mailboxes); + } + + /** + * @ngInject + */ + stateMessages.$inject = ['stateMailbox']; + function stateMessages(stateMailbox) { + return stateMailbox.$filter(); + } + + /** + * @ngInject + */ + stateMessage.$inject = ['encodeUriFilter', '$stateParams', '$state', 'stateMailbox', 'stateMessages']; + function stateMessage(encodeUriFilter, $stateParams, $state, stateMailbox, stateMessages) { + var message = _.find(stateMessages, function(messageObject) { + return messageObject.uid == $stateParams.messageId; + }); + + if (message) + return message.$reload(); + else + // Message not found + $state.go('mail.account.mailbox', { accountId: stateMailbox.$account.id, mailboxId: encodeUriFilter(stateMailbox.path) } ); + } + + /** + * @ngInject + */ + stateContent.$inject = ['stateMessage']; + function stateContent(stateMessage) { + return stateMessage.$editableContent(); + } + /** * @ngInject */ diff --git a/UI/WebServerResources/js/Preferences/Preferences.service.js b/UI/WebServerResources/js/Preferences/Preferences.service.js index 27de78a89..34da411d8 100644 --- a/UI/WebServerResources/js/Preferences/Preferences.service.js +++ b/UI/WebServerResources/js/Preferences/Preferences.service.js @@ -2,7 +2,7 @@ (function() { 'use strict'; - + /** * @name Preferences * @constructor @@ -13,47 +13,48 @@ this.defaults = {}; this.settings = {}; - this.mailboxes = Preferences.$Mailbox.$find({ id: 0 }); - - Preferences.$$resource.fetch("jsonDefaults").then(function(data) { - Preferences.$timeout(function() { + this.mailboxes = Preferences.$Mailbox.$find({ id: 0 }); - // We swap $key -> _$key to avoid an Angular bug (https://github.com/angular/angular.js/issues/6266) - var labels = _.object(_.map(data.SOGoMailLabelsColors, function(value, key) { - if (key.charAt(0) == '$') - return ['_' + key, value]; - return [key, value]; - })); + Preferences.$$resource.fetch("jsonDefaults").then(function(data) { + Preferences.$timeout(function() { - data.SOGoMailLabelsColors = labels; + // We swap $key -> _$key to avoid an Angular bug (https://github.com/angular/angular.js/issues/6266) + var labels = _.object(_.map(data.SOGoMailLabelsColors, function(value, key) { + if (key.charAt(0) == '$') + return ['_' + key, value]; + return [key, value]; + })); - // We convert our list of autoReplyEmailAddresses/forwardAddress into a string. - if (data.Vacation && data.Vacation.autoReplyEmailAddresses) - data.Vacation.autoReplyEmailAddresses = data.Vacation.autoReplyEmailAddresses.join(","); + data.SOGoMailLabelsColors = labels; - if (data.Forward && data.Forward.forwardAddress) - data.Forward.forwardAddress = data.Forward.forwardAddress.join(","); - - angular.extend(_this.defaults, data); - }); - }); - Preferences.$$resource.fetch("jsonSettings").then(function(data) { - Preferences.$timeout(function() { + // We convert our list of autoReplyEmailAddresses/forwardAddress into a string. + if (data.Vacation && data.Vacation.autoReplyEmailAddresses) + data.Vacation.autoReplyEmailAddresses = data.Vacation.autoReplyEmailAddresses.join(","); - - // We convert our PreventInvitationsWhitelist hash into a array of user - if (data.Calendar && data.Calendar.PreventInvitationsWhitelist) - data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) { - return new Preferences.$User({uid: key, shortFormat: value}); - }); - else - data.Calendar.PreventInvitationsWhitelist = []; - - angular.extend(_this.settings, data); - }); - }); + if (data.Forward && data.Forward.forwardAddress) + data.Forward.forwardAddress = data.Forward.forwardAddress.join(","); + + angular.extend(_this.defaults, data); + }); + }); + + Preferences.$$resource.fetch("jsonSettings").then(function(data) { + Preferences.$timeout(function() { + + + // We convert our PreventInvitationsWhitelist hash into a array of user + if (data.Calendar && data.Calendar.PreventInvitationsWhitelist) + data.Calendar.PreventInvitationsWhitelist = _.map(data.Calendar.PreventInvitationsWhitelist, function(value, key) { + return new Preferences.$User({uid: key, shortFormat: value}); + }); + else + data.Calendar.PreventInvitationsWhitelist = []; + + angular.extend(_this.settings, data); + }); + }); } - + /** * @memberof Preferences * @desc The factory we'll use to register with Angular @@ -82,10 +83,10 @@ * @memberof Preferences.prototype * @desc Save the preferences to the server. */ - /*Preferences.prototype.$save = function() { + Preferences.prototype.$save = function() { var _this = this; console.debug("save in model..."); - + return Preferences.$$resource.save("Preferences", this.$omit(), undefined) @@ -94,7 +95,7 @@ //_this.$shadowData = _this.$omit(true); return data; }); - };*/ + }; /** * @function $omit @@ -103,7 +104,7 @@ * @param {Boolean} [deep] - make a deep copy if true * @return an object literal copy of the Preferences instance */ - /*Preferences.prototype.$omit = function(deep) { + Preferences.prototype.$omit = function(deep) { var preferences = {}; angular.forEach(this, function(value, key) { if (key != 'constructor' && key[0] != '$') { @@ -120,9 +121,9 @@ return [key.substring(1), value]; return [key, value]; })); - + preferences.defaults.SOGoMailLabelsColors = labels; - + if (preferences.defaults.Vacation && preferences.defaults.Vacation.autoReplyEmailAddresses) preferences.defaults.Vacation.autoReplyEmailAddresses = preferences.defaults.Vacation.autoReplyEmailAddresses.split(","); @@ -137,8 +138,8 @@ preferences.settings.Calendar.PreventInvitationsWhitelist = h; }); } - + return preferences; - };*/ - + }; + })();