(js) Improve Contacts controllers

pull/91/head
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'];
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) {
$mdDialog.show({
@ -19,13 +20,13 @@
clickOutsideToClose: true,
escapeToClose: true,
template: [
'<md-dialog aria-label="Create component">',
'<md-dialog aria-label="' + l('Create component') + '">',
' <md-content>',
' <div layout="column">',
' <md-button ng-click="createContact()">',
' <md-button ng-click="create(\'card\')">',
' ' + l('Contact'),
' </md-button>',
' <md-button ng-click="createList()">',
' <md-button ng-click="create(\'list\')">',
' ' + l('List'),
' </md-button>',
' </div>',
@ -33,18 +34,20 @@
'</md-dialog>'
].join(''),
locals: {
state: $state
state: $state,
addressbookId: $scope.currentFolder.id
},
controller: ComponentDialogController
});
function ComponentDialogController(scope, $mdDialog, state) {
scope.createContact = function() {
state.go('app.addressbook.new', { addressbookId: $scope.currentFolder.id, contactType: 'card' });
$mdDialog.hide();
}
scope.createList = function() {
state.go('app.addressbook.new', { addressbookId: $scope.currentFolder.id, contactType: 'list' });
/**
* @ngInject
*/
ComponentDialogController.$inject = ['scope', '$mdDialog', 'state', 'addressbookId'];
function ComponentDialogController(scope, $mdDialog, state, addressbookId) {
scope.create = function(type) {
$mdDialog.hide();
state.go('app.addressbook.new', { addressbookId: addressbookId, contactType: type });
}
}
};

View File

@ -67,7 +67,7 @@
$scope.card.$reset();
if ($scope.card.isNew) {
// Cancelling the creation of a card
$scope.card = null;
$rootScope.card = null;
$state.go('app.addressbook', { addressbookId: $scope.currentFolder.id });
}
else {
@ -87,7 +87,7 @@
return o.id == card.id;
});
// Remove card object from scope
$scope.card = null;
$rootScope.card = null;
$state.go('app.addressbook', { addressbookId: $scope.currentFolder.id });
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
@ -98,6 +98,6 @@
}
angular
.module('SOGo.ContactsUI')
.controller('CardController', CardController);
.module('SOGo.ContactsUI')
.controller('CardController', CardController);
})();