2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-10-03 17:44:51 +02:00
|
|
|
AddressBookController.$inject = ['$scope', '$q', '$window', '$state', '$timeout', '$mdDialog', '$mdToast', 'Account', 'Card', 'AddressBook', 'sgFocus', 'Dialog', 'sgSettings', 'sgHotkeys', 'stateAddressbooks', 'stateAddressbook'];
|
|
|
|
function AddressBookController($scope, $q, $window, $state, $timeout, $mdDialog, $mdToast, Account, Card, AddressBook, focus, Dialog, Settings, sgHotkeys, stateAddressbooks, stateAddressbook) {
|
2018-05-07 22:43:16 +02:00
|
|
|
var vm = this, hotkeys = [], sortLabels;
|
|
|
|
|
|
|
|
sortLabels = {
|
|
|
|
c_cn: 'Name',
|
|
|
|
c_sn: 'Lastname',
|
|
|
|
c_givenname: 'Firstname',
|
|
|
|
c_mail: 'Email',
|
|
|
|
c_screenname: 'Screen Name',
|
|
|
|
c_o: 'Organization',
|
|
|
|
c_telephonenumber: 'Preferred Phone'
|
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.$onInit = function() {
|
|
|
|
AddressBook.selectedFolder = stateAddressbook;
|
|
|
|
|
|
|
|
this.service = AddressBook;
|
|
|
|
this.selectedFolder = stateAddressbook;
|
|
|
|
this.mode = { search: false, multiple: 0 };
|
|
|
|
|
|
|
|
|
|
|
|
_registerHotkeys(hotkeys);
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
// Deregister hotkeys
|
|
|
|
_.forEach(hotkeys, function(key) {
|
|
|
|
sgHotkeys.deregisterHotkey(key);
|
|
|
|
});
|
2016-09-27 21:19:24 +02:00
|
|
|
});
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
function _registerHotkeys(keys) {
|
2016-10-03 17:44:51 +02:00
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: l('hotkey_search'),
|
|
|
|
description: l('Search'),
|
2017-07-04 16:09:22 +02:00
|
|
|
callback: angular.bind(vm, vm.searchMode)
|
2016-10-03 17:44:51 +02:00
|
|
|
}));
|
2016-09-27 21:19:24 +02:00
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: l('key_create_card'),
|
|
|
|
description: l('Create a new address book card'),
|
2017-07-04 16:09:22 +02:00
|
|
|
callback: angular.bind(vm, vm.newComponent, 'card')
|
2016-09-27 21:19:24 +02:00
|
|
|
}));
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: l('key_create_list'),
|
|
|
|
description: l('Create a new list'),
|
2017-07-04 16:09:22 +02:00
|
|
|
callback: angular.bind(vm, vm.newComponent, 'list')
|
2016-09-27 21:19:24 +02:00
|
|
|
}));
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'space',
|
|
|
|
description: l('Toggle item'),
|
2017-07-04 16:09:22 +02:00
|
|
|
callback: angular.bind(vm, vm.toggleCardSelection)
|
2016-09-27 21:19:24 +02:00
|
|
|
}));
|
2016-11-10 16:34:31 +01:00
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'shift+space',
|
|
|
|
description: l('Toggle range of items'),
|
2017-07-04 16:09:22 +02:00
|
|
|
callback: angular.bind(vm, vm.toggleCardSelection)
|
2016-11-10 16:34:31 +01:00
|
|
|
}));
|
2016-09-27 21:19:24 +02:00
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'up',
|
|
|
|
description: l('View next item'),
|
|
|
|
callback: _nextCard
|
|
|
|
}));
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'down',
|
|
|
|
description: l('View previous item'),
|
|
|
|
callback: _previousCard
|
|
|
|
}));
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'shift+up',
|
|
|
|
description: l('Add next item to selection'),
|
|
|
|
callback: _addNextCardToSelection
|
|
|
|
}));
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: 'shift+down',
|
|
|
|
description: l('Add previous item to selection'),
|
|
|
|
callback: _addPreviousCardToSelection
|
|
|
|
}));
|
2017-06-14 19:37:13 +02:00
|
|
|
_.forEach(['backspace', 'delete'], function(hotkey) {
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: hotkey,
|
|
|
|
description: l('Delete selected card or address book'),
|
2017-07-04 16:09:22 +02:00
|
|
|
callback: angular.bind(vm, vm.confirmDeleteSelectedCards)
|
2017-06-14 19:37:13 +02:00
|
|
|
}));
|
|
|
|
});
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
// Register the hotkeys
|
|
|
|
_.forEach(keys, function(key) {
|
|
|
|
sgHotkeys.registerHotkey(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:35:15 +01:00
|
|
|
this.centerIsClose = function(navController_centerIsClose) {
|
|
|
|
// Allow the cards list to be hidden only if a card is selected
|
|
|
|
return this.selectedFolder.hasSelectedCard() && !!navController_centerIsClose;
|
|
|
|
};
|
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.selectCard = function(card) {
|
2016-06-06 16:32:45 +02:00
|
|
|
$state.go('app.addressbook.card.view', {cardId: card.id});
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2016-09-27 21:19:24 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.toggleCardSelection = function($event, card) {
|
|
|
|
var folder = this.selectedFolder,
|
2016-11-10 16:34:31 +01:00
|
|
|
selectedIndex, nextSelectedIndex, i;
|
|
|
|
|
|
|
|
if (!card)
|
|
|
|
card = folder.$selectedCard();
|
2015-09-10 15:19:28 +02:00
|
|
|
card.selected = !card.selected;
|
2017-07-04 16:09:22 +02:00
|
|
|
this.mode.multiple += card.selected? 1 : -1;
|
2016-11-10 16:34:31 +01:00
|
|
|
|
|
|
|
// Select closest range of cards when shift key is pressed
|
|
|
|
if ($event.shiftKey && folder.$selectedCount() > 1) {
|
|
|
|
selectedIndex = folder.idsMap[card.id];
|
|
|
|
// Search for next selected card above
|
|
|
|
nextSelectedIndex = selectedIndex - 2;
|
|
|
|
while (nextSelectedIndex >= 0 &&
|
|
|
|
!folder.$cards[nextSelectedIndex].selected)
|
|
|
|
nextSelectedIndex--;
|
|
|
|
if (nextSelectedIndex < 0) {
|
|
|
|
// Search for next selected card bellow
|
|
|
|
nextSelectedIndex = selectedIndex + 2;
|
|
|
|
while (nextSelectedIndex < folder.getLength() &&
|
|
|
|
!folder.$cards[nextSelectedIndex].selected)
|
|
|
|
nextSelectedIndex++;
|
|
|
|
}
|
|
|
|
if (nextSelectedIndex >= 0 && nextSelectedIndex < folder.getLength()) {
|
|
|
|
for (i = Math.min(selectedIndex, nextSelectedIndex);
|
|
|
|
i <= Math.max(selectedIndex, nextSelectedIndex);
|
|
|
|
i++)
|
|
|
|
folder.$cards[i].selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 15:19:28 +02:00
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-09-10 15:19:28 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.newComponent = function(type) {
|
2016-06-10 21:05:35 +02:00
|
|
|
$state.go('app.addressbook.new', { contactType: type });
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-05-08 21:47:09 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.unselectCards = function() {
|
|
|
|
_.forEach(this.selectedFolder.$cards, function(card) {
|
2016-03-08 19:20:34 +01:00
|
|
|
card.selected = false;
|
|
|
|
});
|
2017-07-04 16:09:22 +02:00
|
|
|
this.mode.multiple = 0;
|
|
|
|
};
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User has pressed up arrow key
|
|
|
|
*/
|
|
|
|
function _nextCard($event) {
|
|
|
|
var index = vm.selectedFolder.$selectedCardIndex();
|
|
|
|
|
2016-10-03 17:27:57 +02:00
|
|
|
if (angular.isDefined(index)) {
|
2016-09-27 21:19:24 +02:00
|
|
|
index--;
|
2016-10-03 17:27:57 +02:00
|
|
|
if (vm.selectedFolder.$topIndex > 0)
|
|
|
|
vm.selectedFolder.$topIndex--;
|
|
|
|
}
|
|
|
|
else {
|
2016-11-10 16:34:31 +01:00
|
|
|
// No card is selected, show oldest card
|
2016-09-27 21:19:24 +02:00
|
|
|
index = vm.selectedFolder.$cards.length() - 1;
|
2016-10-03 17:27:57 +02:00
|
|
|
vm.selectedFolder.$topIndex = vm.selectedFolder.getLength();
|
|
|
|
}
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
if (index > -1)
|
2017-07-04 16:09:22 +02:00
|
|
|
vm.selectCard(vm.selectedFolder.$cards[index]);
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
$event.preventDefault();
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User has pressed the down arrow key
|
|
|
|
*/
|
|
|
|
function _previousCard($event) {
|
|
|
|
var index = vm.selectedFolder.$selectedCardIndex();
|
|
|
|
|
2016-10-03 17:27:57 +02:00
|
|
|
if (angular.isDefined(index)) {
|
2016-09-27 21:19:24 +02:00
|
|
|
index++;
|
2016-10-03 17:27:57 +02:00
|
|
|
if (vm.selectedFolder.$topIndex < vm.selectedFolder.$cards.length)
|
|
|
|
vm.selectedFolder.$topIndex++;
|
|
|
|
}
|
2016-09-27 21:19:24 +02:00
|
|
|
else
|
2016-11-10 16:34:31 +01:00
|
|
|
// No card is selected, show newest
|
2016-09-27 21:19:24 +02:00
|
|
|
index = 0;
|
|
|
|
|
|
|
|
if (index < vm.selectedFolder.$cards.length)
|
2017-07-04 16:09:22 +02:00
|
|
|
vm.selectCard(vm.selectedFolder.$cards[index]);
|
2016-09-27 21:19:24 +02:00
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
|
|
|
|
$event.preventDefault();
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _addNextCardToSelection($event) {
|
|
|
|
var index;
|
|
|
|
|
|
|
|
if (vm.selectedFolder.hasSelectedCard()) {
|
|
|
|
index = _nextCard($event);
|
|
|
|
if (index >= 0)
|
|
|
|
toggleCardSelection($event, vm.selectedFolder.$cards[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _addPreviousCardToSelection($event) {
|
|
|
|
var index;
|
|
|
|
|
|
|
|
if (vm.selectedFolder.hasSelectedCard()) {
|
|
|
|
index = _previousCard($event);
|
|
|
|
if (index >= 0)
|
|
|
|
toggleCardSelection($event, vm.selectedFolder.$cards[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.confirmDeleteSelectedCards = function($event) {
|
|
|
|
var selectedCards = this.selectedFolder.$selectedCards();
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
if (_.size(selectedCards) > 0)
|
|
|
|
Dialog.confirm(l('Warning'),
|
|
|
|
l('Are you sure you want to delete the selected contacts?'),
|
|
|
|
{ ok: l('Delete') })
|
2015-05-08 21:47:09 +02:00
|
|
|
.then(function() {
|
|
|
|
// User confirmed the deletion
|
2016-07-19 22:31:48 +02:00
|
|
|
vm.selectedFolder.$deleteCards(selectedCards).then(function() {
|
2016-07-20 17:07:57 +02:00
|
|
|
vm.mode.multiple = 0;
|
2016-07-19 22:31:48 +02:00
|
|
|
if (!vm.selectedFolder.selectedCard)
|
|
|
|
$state.go('app.addressbook');
|
|
|
|
});
|
2015-05-08 21:47:09 +02:00
|
|
|
});
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
$event.preventDefault();
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-07-20 20:24:36 +02:00
|
|
|
|
2016-08-05 22:08:04 +02:00
|
|
|
/**
|
|
|
|
* @see AddressBooksController.dragSelectedCards
|
|
|
|
*/
|
|
|
|
function _selectedCardsOperation(operation, dstId) {
|
|
|
|
var srcFolder, allCards, cards, ids, clearCardView, promise, success;
|
|
|
|
|
|
|
|
srcFolder = vm.selectedFolder;
|
|
|
|
clearCardView = false;
|
|
|
|
allCards = srcFolder.$selectedCards();
|
|
|
|
cards = _.filter(allCards, function(card) {
|
|
|
|
return card.$isCard();
|
2015-08-10 15:48:47 +02:00
|
|
|
});
|
2016-08-05 22:08:04 +02:00
|
|
|
|
|
|
|
if (cards.length != allCards.length)
|
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
|
|
|
.content(l("Lists can't be moved or copied."))
|
|
|
|
.position('top right')
|
|
|
|
.hideDelay(2000));
|
|
|
|
|
|
|
|
if (cards.length) {
|
|
|
|
if (operation == 'copy') {
|
|
|
|
promise = srcFolder.$copyCards(cards, dstId);
|
|
|
|
success = l('%{0} card(s) copied', cards.length);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
promise = srcFolder.$moveCards(cards, dstId);
|
|
|
|
success = l('%{0} card(s) moved', cards.length);
|
|
|
|
// Check if currently displayed card will be moved
|
|
|
|
ids = _.map(cards, 'id');
|
|
|
|
clearCardView = (srcFolder.selectedCard && ids.indexOf(srcFolder.selectedCard) >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show success toast when action succeeds
|
|
|
|
promise.then(function() {
|
|
|
|
if (clearCardView)
|
|
|
|
$state.go('app.addressbook');
|
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
|
|
|
.content(success)
|
|
|
|
.position('top right')
|
|
|
|
.hideDelay(2000));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.copySelectedCards = function(folder) {
|
2016-08-05 22:08:04 +02:00
|
|
|
_selectedCardsOperation('copy', folder);
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2016-08-05 22:08:04 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.moveSelectedCards = function(folder) {
|
2016-08-05 22:08:04 +02:00
|
|
|
_selectedCardsOperation('move', folder);
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-08-10 15:48:47 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.selectAll = function() {
|
|
|
|
_.forEach(this.selectedFolder.$cards, function(card) {
|
2015-08-05 21:04:47 +02:00
|
|
|
card.selected = true;
|
|
|
|
});
|
2017-07-04 16:09:22 +02:00
|
|
|
this.mode.multiple = this.selectedFolder.$cards.length;
|
|
|
|
};
|
2015-08-05 21:04:47 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.sort = function(field) {
|
2018-05-07 22:43:16 +02:00
|
|
|
if (field) {
|
|
|
|
this.selectedFolder.$filter('', { sort: field });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return sortLabels[AddressBook.$query.sort];
|
|
|
|
}
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-07-20 20:24:36 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.sortedBy = function(field) {
|
2015-08-14 21:22:59 +02:00
|
|
|
return AddressBook.$query.sort == field;
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-07-20 21:03:29 +02:00
|
|
|
|
2018-05-07 22:43:16 +02:00
|
|
|
this.ascending = function() {
|
|
|
|
return AddressBook.$query.asc;
|
|
|
|
};
|
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.searchMode = function() {
|
2016-10-03 17:44:51 +02:00
|
|
|
vm.mode.search = true;
|
|
|
|
focus('search');
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2016-10-03 17:44:51 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.cancelSearch = function() {
|
|
|
|
this.mode.search = false;
|
|
|
|
this.selectedFolder.$filter('');
|
|
|
|
};
|
2015-08-27 17:01:23 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.newMessage = function($event, recipients, recipientsField) {
|
2015-08-27 17:01:23 +02:00
|
|
|
Account.$findAll().then(function(accounts) {
|
2016-05-16 20:23:01 +02:00
|
|
|
var account = _.find(accounts, function(o) {
|
2015-08-27 17:01:23 +02:00
|
|
|
if (o.id === 0)
|
|
|
|
return o;
|
2016-05-16 20:23:01 +02:00
|
|
|
});
|
2015-08-27 17:01:23 +02:00
|
|
|
|
|
|
|
// We must initialize the Account with its mailbox
|
|
|
|
// list before proceeding with message's creation
|
|
|
|
account.$getMailboxes().then(function(mailboxes) {
|
|
|
|
account.$newMessage().then(function(message) {
|
2017-01-27 16:52:58 +01:00
|
|
|
message.editable[recipientsField] = recipients;
|
2015-08-27 17:01:23 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
targetEvent: $event,
|
|
|
|
clickOutsideToClose: false,
|
|
|
|
escapeToClose: false,
|
|
|
|
templateUrl: '../Mail/UIxMailEditor',
|
|
|
|
controller: 'MessageEditorController',
|
|
|
|
controllerAs: 'editor',
|
|
|
|
locals: {
|
2016-05-16 20:23:01 +02:00
|
|
|
stateAccount: account,
|
2016-05-19 21:58:26 +02:00
|
|
|
stateMessage: message
|
2015-08-27 17:01:23 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-08-27 17:01:23 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.newMessageWithRecipient = function($event, recipient, fn) {
|
2016-05-19 21:58:26 +02:00
|
|
|
var recipients = [fn + ' <' + recipient + '>'];
|
2017-07-04 16:09:22 +02:00
|
|
|
this.newMessage($event, recipients, 'to');
|
2015-12-08 16:35:26 +01:00
|
|
|
$event.stopPropagation();
|
|
|
|
$event.preventDefault();
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
2015-08-27 17:01:23 +02:00
|
|
|
|
2017-07-04 16:09:22 +02:00
|
|
|
this.newMessageWithSelectedCards = function($event, recipientsField) {
|
|
|
|
var selectedCards = _.filter(this.selectedFolder.$cards, function(card) { return card.selected; });
|
2015-08-27 17:01:23 +02:00
|
|
|
var promises = [], recipients = [];
|
|
|
|
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(selectedCards, function(card) {
|
2016-05-19 22:34:42 +02:00
|
|
|
if (card.$isList({expandable: true})) {
|
2015-08-27 17:01:23 +02:00
|
|
|
// If the list's members were already fetch, use them
|
|
|
|
if (angular.isDefined(card.refs) && card.refs.length) {
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(card.refs, function(ref) {
|
2015-08-27 17:01:23 +02:00
|
|
|
if (ref.email.length)
|
2016-05-19 22:34:42 +02:00
|
|
|
recipients.push(ref.$shortFormat());
|
2015-08-27 17:01:23 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2016-05-30 18:29:58 +02:00
|
|
|
promises.push(card.$reload().then(function(card) {
|
|
|
|
_.forEach(card.refs, function(ref) {
|
|
|
|
if (ref.email.length)
|
|
|
|
recipients.push(ref.$shortFormat());
|
2015-08-27 17:01:23 +02:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 22:34:42 +02:00
|
|
|
else if (card.c_mail.length) {
|
|
|
|
recipients.push(card.$shortFormat());
|
|
|
|
}
|
2015-08-27 17:01:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$q.all(promises).then(function() {
|
2016-05-19 22:34:42 +02:00
|
|
|
recipients = _.uniq(recipients);
|
2015-08-27 17:01:23 +02:00
|
|
|
if (recipients.length)
|
2017-01-26 19:27:13 +01:00
|
|
|
vm.newMessage($event, recipients, recipientsField);
|
2015-08-27 17:01:23 +02:00
|
|
|
});
|
2017-07-04 16:09:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.newListWithSelectedCards = function() {
|
|
|
|
var selectedCards = _.filter(this.selectedFolder.$cards, function(card) { return card.selected; });
|
|
|
|
var promises = [], refs = [];
|
|
|
|
|
|
|
|
_.forEach(selectedCards, function(card) {
|
|
|
|
if (card.$isList({expandable: true})) {
|
|
|
|
// If the list's members were already fetch, use them
|
|
|
|
if (angular.isDefined(card.refs) && card.refs.length) {
|
|
|
|
_.forEach(card.refs, function(ref) {
|
|
|
|
if (ref.email.length)
|
|
|
|
refs.push(ref);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
promises.push(card.$reload().then(function(card) {
|
|
|
|
_.forEach(card.refs, function(ref) {
|
|
|
|
if (ref.email.length)
|
|
|
|
refs.push(ref);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (card.$$email && card.$$email.length) {
|
|
|
|
refs.push(card);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$q.all(promises).then(function() {
|
|
|
|
refs = _.uniqBy(_.map(refs, function(o) {
|
|
|
|
return { reference: o.id || o.reference, email: o.$$email || o.email };
|
|
|
|
}), 'reference');
|
|
|
|
if (refs.length)
|
|
|
|
$state.go('app.addressbook.new', { contactType: 'list', refs: refs });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-05-08 21:47:09 +02:00
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
angular
|
2016-09-27 21:19:24 +02:00
|
|
|
.module('SOGo.ContactsUI')
|
|
|
|
.controller('AddressBookController', AddressBookController);
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|