From 5a5b4cc829d3940b13024de26a2a35d0d5825ae9 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 24 Nov 2015 15:05:03 -0500 Subject: [PATCH] (js) Various improvements and fixes --- .../AdministrationController.js | 4 +- .../js/Common/Dialog.service.js | 8 +-- .../js/Contacts/AddressBook.service.js | 2 +- .../js/Contacts/AddressBookController.js | 4 +- .../js/Mailer/MailboxController.js | 10 ++-- .../js/Preferences/Preferences.service.js | 13 +++-- .../js/Preferences/PreferencesController.js | 49 +++++++++++++------ 7 files changed, 56 insertions(+), 34 deletions(-) diff --git a/UI/WebServerResources/js/Administration/AdministrationController.js b/UI/WebServerResources/js/Administration/AdministrationController.js index fb4e6b40a..2362a3c6d 100644 --- a/UI/WebServerResources/js/Administration/AdministrationController.js +++ b/UI/WebServerResources/js/Administration/AdministrationController.js @@ -7,8 +7,8 @@ /** * @ngInject */ - AdministrationController.$inject = ['$state', '$mdDialog', '$mdToast', 'Dialog', 'encodeUriFilter', 'User', 'Administration']; - function AdministrationController($state, $mdDialog, $mdToast, Dialog, encodeUriFilter, User, Administration) { + AdministrationController.$inject = ['$state', '$mdToast', 'Dialog', 'encodeUriFilter', 'User', 'Administration']; + function AdministrationController($state, $mdToast, Dialog, encodeUriFilter, User, Administration) { var vm = this; vm.administration = Administration; diff --git a/UI/WebServerResources/js/Common/Dialog.service.js b/UI/WebServerResources/js/Common/Dialog.service.js index ce5261455..f0d1c43bf 100644 --- a/UI/WebServerResources/js/Common/Dialog.service.js +++ b/UI/WebServerResources/js/Common/Dialog.service.js @@ -19,7 +19,7 @@ Dialog.alert = function(title, content) { var alert = this.$modal.alert() .title(title) - .content(content) + .textContent(content) .ok(l('OK')); this.$modal.show(alert); }; @@ -34,7 +34,7 @@ Dialog.confirm = function(title, content, options) { var confirm = this.$modal.confirm() .title(title) - .content(content) + .textContent(content) .ok((options && options.ok)? options.ok : l('OK')) .cancel((options && options.cancel)? options.cancel : l('Cancel')); return this.$modal.show(confirm); @@ -67,14 +67,14 @@ ' ng-model="name" required="required"/>', ' ', ' ', - '
', + ' ', ' ', ' ' + l('Cancel'), ' ', ' ', ' ' + l('OK'), ' ', - '
', + ' ', '' ].join(''), controller: PromptDialogController diff --git a/UI/WebServerResources/js/Contacts/AddressBook.service.js b/UI/WebServerResources/js/Contacts/AddressBook.service.js index 1904f2871..552c312db 100644 --- a/UI/WebServerResources/js/Contacts/AddressBook.service.js +++ b/UI/WebServerResources/js/Contacts/AddressBook.service.js @@ -506,7 +506,7 @@ AddressBook.prototype.$unwrap = function(futureAddressBookData) { var _this = this; - // Expose and sesolve the promise + // Expose and resolve the promise this.$futureAddressBookData = futureAddressBookData.then(function(data) { return AddressBook.$timeout(function() { // Extend AddressBook instance from data of addressbooks list. diff --git a/UI/WebServerResources/js/Contacts/AddressBookController.js b/UI/WebServerResources/js/Contacts/AddressBookController.js index 99abce134..d7fdd00f7 100644 --- a/UI/WebServerResources/js/Contacts/AddressBookController.js +++ b/UI/WebServerResources/js/Contacts/AddressBookController.js @@ -6,8 +6,8 @@ /** * @ngInject */ - AddressBookController.$inject = ['$scope', '$q', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Account', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook']; - function AddressBookController($scope, $q, $state, $timeout, $mdDialog, focus, Account, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) { + AddressBookController.$inject = ['$scope', '$q', '$state', '$timeout', '$mdDialog', 'Account', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook']; + function AddressBookController($scope, $q, $state, $timeout, $mdDialog, Account, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) { var vm = this; AddressBook.selectedFolder = stateAddressbook; diff --git a/UI/WebServerResources/js/Mailer/MailboxController.js b/UI/WebServerResources/js/Mailer/MailboxController.js index 6d332a8da..48439f8c6 100644 --- a/UI/WebServerResources/js/Mailer/MailboxController.js +++ b/UI/WebServerResources/js/Mailer/MailboxController.js @@ -6,8 +6,8 @@ /** * @ngInject */ - MailboxController.$inject = ['$state', '$timeout', '$mdDialog', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox']; - function MailboxController($state, $timeout, $mdDialog, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) { + MailboxController.$inject = ['$state', '$timeout', '$mdDialog', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'Dialog', 'Account', 'Mailbox']; + function MailboxController($state, $timeout, $mdDialog, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, Dialog, Account, Mailbox) { var vm = this, messageDialog = null; Mailbox.selectedFolder = stateMailbox; @@ -93,9 +93,9 @@ } function selectAll() { - _.each(vm.selectedFolder.$messages, function(message) { - message.selected = true; - }); + var i = 0, length = vm.selectedFolder.$messages.length; + for (; i < length; i++) + vm.selectedFolder.$messages[i].selected = true; } function markSelectedMessagesAsFlagged() { diff --git a/UI/WebServerResources/js/Preferences/Preferences.service.js b/UI/WebServerResources/js/Preferences/Preferences.service.js index d2f9a9afe..86533d57b 100644 --- a/UI/WebServerResources/js/Preferences/Preferences.service.js +++ b/UI/WebServerResources/js/Preferences/Preferences.service.js @@ -128,7 +128,11 @@ * @return an object literal copy of the Preferences instance */ Preferences.prototype.$omit = function(deep) { - var preferences = {}; + var preferences, labels, whitelist; + + preferences = {}; + whitelist = {}; + angular.forEach(this, function(value, key) { if (key != 'constructor' && key[0] != '$') { if (deep) @@ -139,7 +143,7 @@ }); // We swap _$key -> $key to avoid an Angular bug (https://github.com/angular/angular.js/issues/6266) - var labels = _.object(_.map(preferences.defaults.SOGoMailLabelsColors, function(value, key) { + labels = _.object(_.map(preferences.defaults.SOGoMailLabelsColors, function(value, key) { if (key.charAt(0) == '_' && key.charAt(1) == '$') return [key.substring(1), value]; return [key, value]; @@ -163,11 +167,10 @@ preferences.defaults.Forward.forwardAddress = preferences.defaults.Forward.forwardAddress.split(","); if (preferences.settings.Calendar && preferences.settings.Calendar.PreventInvitationsWhitelist) { - var h = {}; _.each(preferences.settings.Calendar.PreventInvitationsWhitelist, function(user) { - h[user.uid] = user.$shortFormat(); + whitelist[user.uid] = user.$shortFormat(); }); - preferences.settings.Calendar.PreventInvitationsWhitelist = h; + preferences.settings.Calendar.PreventInvitationsWhitelist = whitelist; } return preferences; diff --git a/UI/WebServerResources/js/Preferences/PreferencesController.js b/UI/WebServerResources/js/Preferences/PreferencesController.js index 039af37be..bb994b421 100644 --- a/UI/WebServerResources/js/Preferences/PreferencesController.js +++ b/UI/WebServerResources/js/Preferences/PreferencesController.js @@ -200,7 +200,10 @@ } function save() { - var sendForm = true; + var i, sendForm, addresses, defaultAddresses, domains, domain; + + sendForm = true; + domains = []; // We do some sanity checks if (window.forwardConstraints > 0 && @@ -208,11 +211,10 @@ vm.preferences.defaults.Forward.enabled && angular.isDefined(vm.preferences.defaults.Forward.forwardAddress)) { - var addresses = vm.preferences.defaults.Forward.forwardAddress.split(","); + addresses = vm.preferences.defaults.Forward.forwardAddress.split(","); // We first extract the list of 'known domains' to SOGo - var defaultAddresses = window.defaultEmailAddresses.split(/, */); - var domains = []; + defaultAddresses = window.defaultEmailAddresses.split(/, */); _.forEach(defaultAddresses, function(adr) { var domain = adr.split("@")[1]; @@ -222,8 +224,8 @@ }); // We check if we're allowed or not to forward based on the domain defaults - for (var i = 0; i < addresses.length && sendForm; i++) { - var domain = addresses[i].split("@")[1].toLowerCase(); + for (i = 0; i < addresses.length && sendForm; i++) { + domain = addresses[i].split("@")[1].toLowerCase(); if (domains.indexOf(domain) < 0 && window.forwardConstraints == 1) { Dialog.alert(l('Error'), l("You are not allowed to forward your messages to an external email address.")); sendForm = false; @@ -236,14 +238,23 @@ } if (sendForm) - vm.preferences.$save().then(function(data) { - $mdToast.show( - $mdToast.simple() - .content(l('Preferences saved')) - .position('top right') - .hideDelay(3000) - ); + return vm.preferences.$save().then(function(data) { + $mdToast.show({ + controller: 'savePreferencesToastCtrl', + template: [ + '', + ' ' + l('Preferences saved') + '', + ' ', + ' close', + ' ', + '' + ].join(''), + hideDelay: 2000, + position: 'top right' + }); }); + + return $q.reject(); } function canChangePassword() { @@ -260,7 +271,7 @@ var alert = $mdDialog.alert({ title: l('Password'), content: l('The password was changed successfully.'), - ok: 'OK' + ok: l('OK') }); $mdDialog.show( alert ) .finally(function() { @@ -270,7 +281,7 @@ var alert = $mdDialog.alert({ title: l('Password'), content: msg, - ok: 'OK' + ok: l('OK') }); $mdDialog.show( alert ) .finally(function() { @@ -286,8 +297,16 @@ } } + savePreferencesToastCtrl.$inject = ['$scope', '$mdToast']; + function savePreferencesToastCtrl($scope, $mdToast) { + $scope.closeToast = function() { + $mdToast.hide(); + }; + } + angular .module('SOGo.PreferencesUI') + .controller('savePreferencesToastCtrl', savePreferencesToastCtrl) .controller('PreferencesController', PreferencesController); })();