2016-03-19 11:02:13 +00:00
|
|
|
angular.module('contactsApp')
|
2016-02-18 21:10:56 +00:00
|
|
|
.controller('contactdetailsCtrl', function(ContactService, AddressBookService, vCardPropertiesService, $route, $routeParams, $scope) {
|
|
|
|
|
2015-11-05 15:33:30 +00:00
|
|
|
var ctrl = this;
|
2016-01-13 20:14:14 +00:00
|
|
|
|
2017-09-21 05:07:11 +00:00
|
|
|
ctrl.init = true;
|
|
|
|
ctrl.loading = false;
|
2016-02-18 21:10:56 +00:00
|
|
|
ctrl.show = false;
|
|
|
|
|
|
|
|
ctrl.clearContact = function() {
|
|
|
|
$route.updateParams({
|
|
|
|
gid: $routeParams.gid,
|
|
|
|
uid: undefined
|
|
|
|
});
|
|
|
|
ctrl.show = false;
|
|
|
|
ctrl.contact = undefined;
|
|
|
|
};
|
2016-03-04 12:32:51 +00:00
|
|
|
|
2016-02-15 12:42:26 +00:00
|
|
|
ctrl.uid = $routeParams.uid;
|
2016-02-24 19:54:35 +00:00
|
|
|
ctrl.t = {
|
2016-02-29 12:43:05 +00:00
|
|
|
noContacts : t('contacts', 'No contacts in here'),
|
2016-02-29 15:29:48 +00:00
|
|
|
placeholderName : t('contacts', 'Name'),
|
2016-03-08 11:04:04 +00:00
|
|
|
placeholderOrg : t('contacts', 'Organization'),
|
|
|
|
placeholderTitle : t('contacts', 'Title'),
|
2017-09-21 09:56:23 +00:00
|
|
|
selectField : t('contacts', 'Add field …'),
|
2016-12-29 10:30:36 +00:00
|
|
|
download : t('contacts', 'Download'),
|
2017-01-05 11:32:39 +00:00
|
|
|
delete : t('contacts', 'Delete'),
|
2017-07-26 22:31:35 +00:00
|
|
|
save : t('contacts', 'Save changes'),
|
2017-09-21 05:07:11 +00:00
|
|
|
addressBook : t('contacts', 'Address book'),
|
2017-09-21 09:56:23 +00:00
|
|
|
loading : t('contacts', 'Loading contacts …')
|
2016-02-24 19:54:35 +00:00
|
|
|
};
|
2016-02-15 12:42:26 +00:00
|
|
|
|
2016-02-26 07:25:55 +00:00
|
|
|
ctrl.fieldDefinitions = vCardPropertiesService.fieldDefinitions;
|
2016-03-02 09:35:35 +00:00
|
|
|
ctrl.focus = undefined;
|
2016-03-03 15:11:35 +00:00
|
|
|
ctrl.field = undefined;
|
2016-03-02 08:43:03 +00:00
|
|
|
ctrl.addressBooks = [];
|
|
|
|
|
|
|
|
AddressBookService.getAll().then(function(addressBooks) {
|
|
|
|
ctrl.addressBooks = addressBooks;
|
2016-03-17 18:01:11 +00:00
|
|
|
|
2017-11-20 04:47:05 +00:00
|
|
|
if (!angular.isUndefined(ctrl.contact)) {
|
2016-03-17 18:01:11 +00:00
|
|
|
ctrl.addressBook = _.find(ctrl.addressBooks, function(book) {
|
|
|
|
return book.displayName === ctrl.contact.addressBookId;
|
2016-03-02 09:52:19 +00:00
|
|
|
});
|
|
|
|
}
|
2017-09-21 05:07:11 +00:00
|
|
|
ctrl.init = false;
|
2017-01-06 16:33:01 +00:00
|
|
|
// Start watching for ctrl.uid when we have addressBooks, as they are needed for fetching
|
|
|
|
// full details.
|
|
|
|
$scope.$watch('ctrl.uid', function(newValue) {
|
|
|
|
ctrl.changeContact(newValue);
|
|
|
|
});
|
2016-03-02 08:43:03 +00:00
|
|
|
});
|
2016-02-26 07:25:55 +00:00
|
|
|
|
2016-02-15 12:42:26 +00:00
|
|
|
|
|
|
|
ctrl.changeContact = function(uid) {
|
2016-03-09 10:13:41 +00:00
|
|
|
if (typeof uid === 'undefined') {
|
2016-02-18 21:10:56 +00:00
|
|
|
ctrl.show = false;
|
|
|
|
$('#app-navigation-toggle').removeClass('showdetails');
|
2016-02-17 21:34:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-09-21 05:07:11 +00:00
|
|
|
ctrl.loading = true;
|
2017-01-04 18:13:49 +00:00
|
|
|
ContactService.getById(ctrl.addressBooks, uid).then(function(contact) {
|
2016-04-18 18:39:29 +00:00
|
|
|
if (angular.isUndefined(contact)) {
|
|
|
|
ctrl.clearContact();
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 12:42:26 +00:00
|
|
|
ctrl.contact = contact;
|
2016-02-18 21:10:56 +00:00
|
|
|
ctrl.show = true;
|
2017-09-21 05:07:11 +00:00
|
|
|
ctrl.loading = false;
|
2016-02-18 21:10:56 +00:00
|
|
|
$('#app-navigation-toggle').addClass('showdetails');
|
|
|
|
|
2016-03-17 18:01:11 +00:00
|
|
|
ctrl.addressBook = _.find(ctrl.addressBooks, function(book) {
|
|
|
|
return book.displayName === ctrl.contact.addressBookId;
|
2016-03-02 08:43:03 +00:00
|
|
|
});
|
2016-02-15 12:42:26 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-01-13 20:14:14 +00:00
|
|
|
ctrl.deleteContact = function() {
|
2017-11-20 18:10:23 +00:00
|
|
|
ContactService.delete(ctrl.addressBook, ctrl.contact);
|
2016-01-13 20:14:14 +00:00
|
|
|
};
|
2016-02-26 07:25:55 +00:00
|
|
|
|
|
|
|
ctrl.addField = function(field) {
|
2016-03-03 15:11:35 +00:00
|
|
|
var defaultValue = vCardPropertiesService.getMeta(field).defaultValue || {value: ''};
|
|
|
|
ctrl.contact.addProperty(field, defaultValue);
|
2016-03-02 09:35:35 +00:00
|
|
|
ctrl.focus = field;
|
2016-03-03 15:11:35 +00:00
|
|
|
ctrl.field = '';
|
2016-03-02 09:35:35 +00:00
|
|
|
};
|
2016-03-02 08:43:03 +00:00
|
|
|
|
2016-03-03 16:57:04 +00:00
|
|
|
ctrl.deleteField = function (field, prop) {
|
|
|
|
ctrl.contact.removeProperty(field, prop);
|
2016-03-02 14:51:52 +00:00
|
|
|
ctrl.focus = undefined;
|
|
|
|
};
|
|
|
|
|
2017-11-19 11:44:28 +00:00
|
|
|
ctrl.changeAddressBook = function (addressBook, oldAddressBook) {
|
|
|
|
ContactService.moveContact(ctrl.contact, addressBook, oldAddressBook);
|
2016-03-02 08:43:03 +00:00
|
|
|
};
|
2018-03-20 15:07:17 +00:00
|
|
|
|
|
|
|
ctrl.updateContact = function() {
|
|
|
|
ContactService.queueUpdate(ctrl.contact);
|
|
|
|
};
|
2018-04-26 20:36:32 +00:00
|
|
|
|
|
|
|
ctrl.closeMenus = function() {
|
|
|
|
ctrl.openedMenu = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
ctrl.openMenu = function(index) {
|
|
|
|
ctrl.closeMenus();
|
|
|
|
ctrl.openedMenu = index;
|
|
|
|
};
|
|
|
|
|
|
|
|
ctrl.toggleMenu = function(index) {
|
|
|
|
if (ctrl.openedMenu === index) {
|
|
|
|
ctrl.closeMenus();
|
|
|
|
} else {
|
|
|
|
ctrl.openMenu(index);
|
|
|
|
}
|
|
|
|
};
|
2016-03-16 19:37:40 +00:00
|
|
|
});
|