Minor improvements to SOGo.ContactsUI ng module

This commit is contained in:
Francis Lachapelle 2015-01-08 16:12:29 -05:00
parent 34d7a3bf52
commit f3597616ea

View file

@ -82,25 +82,6 @@
$urlRouterProvider.otherwise('/personal'); $urlRouterProvider.otherwise('/personal');
}]) }])
.directive('sgFocusOn', function() {
return function(scope, elem, attr) {
scope.$on('sgFocusOn', function(e, name) {
if (name === attr.sgFocusOn) {
elem[0].focus();
elem[0].select();
}
});
};
})
.factory('sgFocus', ['$rootScope', '$timeout', function($rootScope, $timeout) {
return function(name) {
$timeout(function() {
$rootScope.$broadcast('sgFocusOn', name);
});
}
}])
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook, Dialog, stateAddressbooks, stateAddressbook) { .controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook, Dialog, stateAddressbooks, stateAddressbook) {
var currentAddressbook; var currentAddressbook;
@ -140,7 +121,7 @@
}); });
}; };
$scope.currentFolderIsConfigurable = function(folder) { $scope.currentFolderIsConfigurable = function(folder) {
return ($scope.addressbook.id == folder.id && !folder.isRemote); return ($scope.addressbook && $scope.addressbook.id == folder.id && !folder.isRemote);
}; };
$scope.edit = function(i) { $scope.edit = function(i) {
if (!$rootScope.addressbook.isRemote) { if (!$rootScope.addressbook.isRemote) {
@ -236,7 +217,7 @@
$scope.removeUser = function(user) { $scope.removeUser = function(user) {
stateAddressbook.$acl.$removeUser(user.uid).then(function() { stateAddressbook.$acl.$removeUser(user.uid).then(function() {
if (user.uid == $scope.selectedUser.uid) { if (user.uid == $scope.selectedUser.uid) {
delete $scope.selectedUser; $scope.selectedUser = null;
} }
}, function(data, status) { }, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured please try again.')) Dialog.alert(l('Warning'), l('An error occured please try again.'))
@ -360,7 +341,7 @@
$scope.card.$reset(); $scope.card.$reset();
if ($scope.card.isNew) { if ($scope.card.isNew) {
// Cancelling the creation of a card // Cancelling the creation of a card
delete $scope.card; $scope.card = null;
$state.go('addressbook', { addressbookId: $scope.addressbook.id }); $state.go('addressbook', { addressbookId: $scope.addressbook.id });
} }
else { else {
@ -381,7 +362,8 @@
return o.id == card.id; return o.id == card.id;
}); });
// Remove card object from scope // Remove card object from scope
delete $scope.card; $scope.card = null;
$state.go('addressbook', { addressbookId: $scope.addressbook.id });
}, function(data, status) { }, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".', Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
card.$fullname())); card.$fullname()));