2016-03-01 17:27:51 +00:00
|
|
|
app.controller('contactdetailsCtrl', ['ContactService', 'vCardPropertiesService', '$routeParams', '$scope', function(ContactService, vCardPropertiesService, $routeParams, $scope) {
|
2015-11-05 15:33:30 +00:00
|
|
|
var ctrl = this;
|
2016-01-13 20:14:14 +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'),
|
|
|
|
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-02-26 07:25:55 +00:00
|
|
|
|
2016-02-15 12:42:26 +00:00
|
|
|
$scope.$watch('ctrl.uid', function(newValue, oldValue) {
|
|
|
|
ctrl.changeContact(newValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
ctrl.changeContact = function(uid) {
|
2016-02-17 21:34:36 +00:00
|
|
|
if (typeof uid === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 12:42:26 +00:00
|
|
|
ContactService.getById(uid).then(function(contact) {
|
|
|
|
ctrl.contact = contact;
|
2016-02-22 20:34:10 +00:00
|
|
|
ctrl.singleProperties = ctrl.contact.getSingleProperties();
|
2016-02-24 15:28:47 +00:00
|
|
|
ctrl.photo = ctrl.contact.photo();
|
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) {
|
|
|
|
ctrl.contact.setProperty(field, {value: ''});
|
|
|
|
ctrl.singleProperties = ctrl.contact.getSingleProperties();
|
2016-03-02 09:35:35 +00:00
|
|
|
ctrl.focus = field;
|
|
|
|
};
|
2016-01-13 20:14:14 +00:00
|
|
|
}]);
|