contacts/js/components/contactDetails/contactDetails_controller.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

app.controller('contactdetailsCtrl', ['ContactService', 'vCardPropertiesService', '$routeParams', '$scope', function(ContactService, vCardPropertiesService, $routeParams, $scope) {
2015-11-05 15:33:30 +00:00
var ctrl = this;
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'),
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
ctrl.fieldDefinitions = vCardPropertiesService.fieldDefinitions;
2016-03-02 09:35:35 +00:00
ctrl.focus = undefined;
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() {
ContactService.update(ctrl.contact);
2016-01-14 10:36:41 +00:00
};
ctrl.deleteContact = function() {
2016-02-11 14:30:52 +00:00
ContactService.delete(ctrl.contact);
};
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;
};
}]);