2016-03-19 11:02:13 +00:00
|
|
|
angular.module('contactsApp')
|
|
|
|
.controller('contactdetailsCtrl', function(ContactService, AddressBookService, vCardPropertiesService, $routeParams, $scope) {
|
2015-11-05 15:33:30 +00:00
|
|
|
var ctrl = this;
|
2016-01-13 20:14:14 +00:00
|
|
|
|
2016-03-04 12:32:51 +00:00
|
|
|
ctrl.loading = true;
|
|
|
|
|
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'),
|
2016-02-29 15:29:48 +00:00
|
|
|
selectField : t('contacts', 'Add field ...')
|
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
|
|
|
|
2016-03-02 09:52:19 +00:00
|
|
|
if (!_.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
|
|
|
});
|
|
|
|
}
|
2016-03-04 12:32:51 +00:00
|
|
|
ctrl.loading = false;
|
2016-03-02 08:43:03 +00:00
|
|
|
});
|
2016-02-26 07:25:55 +00:00
|
|
|
|
2016-03-19 11:26:17 +00:00
|
|
|
$scope.$watch('ctrl.uid', function(newValue) {
|
2016-02-15 12:42:26 +00:00
|
|
|
ctrl.changeContact(newValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
ctrl.changeContact = function(uid) {
|
2016-03-09 10:13:41 +00:00
|
|
|
if (typeof uid === 'undefined') {
|
2016-02-17 21:34:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-15 12:42:26 +00:00
|
|
|
ContactService.getById(uid).then(function(contact) {
|
|
|
|
ctrl.contact = contact;
|
2016-02-24 15:28:47 +00:00
|
|
|
ctrl.photo = ctrl.contact.photo();
|
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-14 10:36:41 +00:00
|
|
|
ctrl.updateContact = function() {
|
2016-01-21 12:28:52 +00:00
|
|
|
ContactService.update(ctrl.contact);
|
2016-01-14 10:36:41 +00:00
|
|
|
};
|
|
|
|
|
2016-01-13 20:14:14 +00:00
|
|
|
ctrl.deleteContact = function() {
|
2016-02-11 14:30:52 +00:00
|
|
|
ContactService.delete(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;
|
|
|
|
};
|
|
|
|
|
2016-03-02 08:43:03 +00:00
|
|
|
ctrl.changeAddressBook = function (addressBook) {
|
|
|
|
ContactService.moveContact(ctrl.contact, addressBook);
|
|
|
|
};
|
2016-03-16 19:37:40 +00:00
|
|
|
});
|