From 5be78bf5b5c875488c0f9f2da968f7db858f1e2c Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Mon, 20 Apr 2015 21:42:07 +0200 Subject: [PATCH] fixes #47: set attended attribute in separate call to trigger actions --- angular_app/js/controllers.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 76b1f50..b878e75 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -104,20 +104,21 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person', var original_data = angular.copy(person_data); person_data.person_id = person_data._id; person_data._id = $stateParams.id; - person_data.attended = true; Event.addPerson(person_data, function() { // This could be improved adding it only locally. //$scope.event.persons.push(person_data); - Event.get($stateParams, function(data) { - $scope.event.persons = angular.fromJson(data).persons; + $scope.setPersonAttribute(person_data, 'attended', true, function() { + Event.get($stateParams, function(data) { + $scope.event.persons = angular.fromJson(data).persons; + }); + var idx = $scope.allPersons.indexOf(original_data); + if (idx != -1) { + $scope.allPersons.splice(idx, 1); + } else { + $scope.allPersons = Person.all(); + } + $scope.newPerson = {}; }); - var idx = $scope.allPersons.indexOf(original_data); - if (idx != -1) { - $scope.allPersons.splice(idx, 1); - } else { - $scope.allPersons = Person.all(); - } - $scope.newPerson = {}; }); $scope.query = ''; }; @@ -135,7 +136,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person', } }; - $scope.setPersonAttribute = function(person, key, value) { + $scope.setPersonAttribute = function(person, key, value, callback) { $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $stateParams.id); $log.debug('EventDetailsCtrl.setPersonAttribute.person_id: ' + person.person_id); $log.debug('EventDetailsCtrl.setPersonAttribute.key: ' + key + ' value: ' + value); @@ -146,11 +147,12 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person', $log.debug('EventDetailsCtrl.setPersonAttribute.data'); $log.debug(data); $scope.event.persons = data; + if (callback) { + callback(data); + } }); }; - $scope.focusinControl = {}; - $scope.setPersonAttributeAndRefocus = function(person, key, value) { $scope.setPersonAttribute(person, key, value); $scope.query = '';