2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGoContacts */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2016-01-04 17:51:59 +01:00
|
|
|
angular.module('SOGo.ContactsUI', ['ui.router', 'angularFileUpload', 'ck', 'SOGo.Common', 'SOGo.PreferencesUI', 'SOGo.MailerUI'])
|
2015-08-03 17:53:54 +02:00
|
|
|
.config(configure)
|
|
|
|
.run(runBlock);
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
configure.$inject = ['$stateProvider', '$urlRouterProvider'];
|
|
|
|
function configure($stateProvider, $urlRouterProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.state('app', {
|
|
|
|
url: '/addressbooks',
|
|
|
|
abstract: true,
|
|
|
|
views: {
|
|
|
|
addressbooks: {
|
|
|
|
templateUrl: 'UIxContactFoldersView', // UI/Templates/Contacts/UIxContactFoldersView.wox
|
2015-05-28 19:48:45 +02:00
|
|
|
controller: 'AddressBooksController',
|
|
|
|
controllerAs: 'app'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateAddressbooks: stateAddressbooks
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('app.addressbook', {
|
|
|
|
url: '/:addressbookId',
|
|
|
|
views: {
|
|
|
|
addressbook: {
|
|
|
|
templateUrl: 'addressbook',
|
2015-05-28 19:48:45 +02:00
|
|
|
controller: 'AddressBookController',
|
|
|
|
controllerAs: 'addressbook'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateAddressbook: stateAddressbook
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('app.addressbook.new', {
|
|
|
|
url: '/{contactType:(?:card|list)}/new',
|
|
|
|
views: {
|
|
|
|
card: {
|
|
|
|
templateUrl: 'UIxContactEditorTemplate', // UI/Templates/Contacts/UIxContactEditorTemplate.wox
|
2015-05-28 19:48:45 +02:00
|
|
|
controller: 'CardController',
|
|
|
|
controllerAs: 'editor'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateCard: stateNewCard
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('app.addressbook.card', {
|
|
|
|
url: '/:cardId',
|
|
|
|
abstract: true,
|
|
|
|
views: {
|
|
|
|
card: {
|
|
|
|
template: '<ui-view/>'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-05-06 18:12:27 +02:00
|
|
|
stateCard: stateCard
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('app.addressbook.card.view', {
|
|
|
|
url: '/view',
|
|
|
|
views: {
|
|
|
|
'card@app.addressbook': {
|
|
|
|
templateUrl: 'UIxContactViewTemplate', // UI/Templates/Contacts/UIxContactViewTemplate.wox
|
2015-05-28 19:48:45 +02:00
|
|
|
controller: 'CardController',
|
|
|
|
controllerAs: 'editor'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('app.addressbook.card.editor', {
|
|
|
|
url: '/edit',
|
|
|
|
views: {
|
|
|
|
'card@app.addressbook': {
|
|
|
|
templateUrl: 'UIxContactEditorTemplate', // UI/Templates/Contacts/UIxContactEditorTemplate.wox
|
2015-05-28 19:48:45 +02:00
|
|
|
controller: 'CardController',
|
|
|
|
controllerAs: 'editor'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// if none of the above states are matched, use this as the fallback
|
|
|
|
$urlRouterProvider.otherwise('/addressbooks/personal');
|
|
|
|
}
|
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateAddressbooks.$inject = ['AddressBook'];
|
|
|
|
function stateAddressbooks(AddressBook) {
|
|
|
|
return AddressBook.$findAll(window.contactFolders);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-12-14 18:19:15 +01:00
|
|
|
stateAddressbook.$inject = ['$q', '$state', '$stateParams', 'AddressBook'];
|
|
|
|
function stateAddressbook($q, $state, $stateParams, AddressBook) {
|
|
|
|
var addressbook = _.find(AddressBook.$findAll(), function(addressbook) {
|
2015-11-09 20:46:30 +01:00
|
|
|
return addressbook.id == $stateParams.addressbookId;
|
|
|
|
});
|
2015-12-14 18:19:15 +01:00
|
|
|
if (addressbook) {
|
|
|
|
addressbook.$reload();
|
|
|
|
return addressbook;
|
|
|
|
}
|
|
|
|
return $q.reject('Addressbook ' + $stateParams.addressbookId + ' not found');
|
2015-05-06 18:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateNewCard.$inject = ['$stateParams', 'stateAddressbook', 'Card'];
|
|
|
|
function stateNewCard($stateParams, stateAddressbook, Card) {
|
|
|
|
var tag = 'v' + $stateParams.contactType,
|
2015-07-27 18:47:40 +02:00
|
|
|
card = new Card({ pid: $stateParams.addressbookId, c_component: tag });
|
2015-07-15 21:15:17 +02:00
|
|
|
stateAddressbook.selectedCard = true;
|
2015-05-06 18:12:27 +02:00
|
|
|
return card;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateCard.$inject = ['$stateParams', 'stateAddressbook'];
|
|
|
|
function stateCard($stateParams, stateAddressbook) {
|
2015-07-15 19:44:17 +02:00
|
|
|
stateAddressbook.selectedCard = $stateParams.cardId;
|
2015-05-06 18:12:27 +02:00
|
|
|
return stateAddressbook.$getCard($stateParams.cardId);
|
|
|
|
}
|
|
|
|
|
2015-08-03 17:53:54 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-10-09 22:19:28 +02:00
|
|
|
runBlock.$inject = ['$rootScope', '$log', '$state'];
|
|
|
|
function runBlock($rootScope, $log, $state) {
|
|
|
|
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
|
|
|
|
$log.error(error);
|
2015-12-14 18:19:15 +01:00
|
|
|
$state.go('app.addressbook', { addressbookId: 'personal' });
|
2015-10-09 22:19:28 +02:00
|
|
|
});
|
2015-08-03 17:53:54 +02:00
|
|
|
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
|
2015-10-09 22:19:28 +02:00
|
|
|
$log.error(event, current, previous, rejection);
|
2015-08-03 17:53:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|