(js) Improve Contacts controllers

This commit is contained in:
Francis Lachapelle 2015-05-06 17:46:58 -04:00
parent 0eb2ecd2f2
commit 2d46f4fd33
2 changed files with 20 additions and 17 deletions

View file

@ -8,9 +8,10 @@
*/ */
AddressBookController.$inject = ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook']; AddressBookController.$inject = ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook'];
function AddressBookController($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) { function AddressBookController($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
var currentAddressbook; var currentAddressbook;
$rootScope.currentFolder = stateAddressbook; $rootScope.currentFolder = stateAddressbook;
$rootScope.card = null;
$scope.newComponent = function(ev) { $scope.newComponent = function(ev) {
$mdDialog.show({ $mdDialog.show({
@ -19,13 +20,13 @@
clickOutsideToClose: true, clickOutsideToClose: true,
escapeToClose: true, escapeToClose: true,
template: [ template: [
'<md-dialog aria-label="Create component">', '<md-dialog aria-label="' + l('Create component') + '">',
' <md-content>', ' <md-content>',
' <div layout="column">', ' <div layout="column">',
' <md-button ng-click="createContact()">', ' <md-button ng-click="create(\'card\')">',
' ' + l('Contact'), ' ' + l('Contact'),
' </md-button>', ' </md-button>',
' <md-button ng-click="createList()">', ' <md-button ng-click="create(\'list\')">',
' ' + l('List'), ' ' + l('List'),
' </md-button>', ' </md-button>',
' </div>', ' </div>',
@ -33,18 +34,20 @@
'</md-dialog>' '</md-dialog>'
].join(''), ].join(''),
locals: { locals: {
state: $state state: $state,
addressbookId: $scope.currentFolder.id
}, },
controller: ComponentDialogController controller: ComponentDialogController
}); });
function ComponentDialogController(scope, $mdDialog, state) {
scope.createContact = function() { /**
state.go('app.addressbook.new', { addressbookId: $scope.currentFolder.id, contactType: 'card' }); * @ngInject
$mdDialog.hide(); */
} ComponentDialogController.$inject = ['scope', '$mdDialog', 'state', 'addressbookId'];
scope.createList = function() { function ComponentDialogController(scope, $mdDialog, state, addressbookId) {
state.go('app.addressbook.new', { addressbookId: $scope.currentFolder.id, contactType: 'list' }); scope.create = function(type) {
$mdDialog.hide(); $mdDialog.hide();
state.go('app.addressbook.new', { addressbookId: addressbookId, contactType: type });
} }
} }
}; };

View file

@ -67,7 +67,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
$scope.card = null; $rootScope.card = null;
$state.go('app.addressbook', { addressbookId: $scope.currentFolder.id }); $state.go('app.addressbook', { addressbookId: $scope.currentFolder.id });
} }
else { else {
@ -87,7 +87,7 @@
return o.id == card.id; return o.id == card.id;
}); });
// Remove card object from scope // Remove card object from scope
$scope.card = null; $rootScope.card = null;
$state.go('app.addressbook', { addressbookId: $scope.currentFolder.id }); $state.go('app.addressbook', { addressbookId: $scope.currentFolder.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}".',
@ -98,6 +98,6 @@
} }
angular angular
.module('SOGo.ContactsUI') .module('SOGo.ContactsUI')
.controller('CardController', CardController); .controller('CardController', CardController);
})(); })();