add registered person from event details

This commit is contained in:
Davide Alberani 2015-04-07 23:20:42 +02:00
parent 484a543b4c
commit ce1f4b6103
2 changed files with 25 additions and 17 deletions

View file

@ -72,7 +72,7 @@
<span class="input-group-addon">{{'Email' | translate}}</span>
<input type="email" name="email" class="form-control" placeholder="{{'name.surname@example.com' | translate}}" ng-model="newPerson.email">
</div>
<button ng-disabled="!(newPerson.name && newPerson.surname)" ng-click="fastAddPerson(newPerson)" class="btn btn-success top5">
<button ng-disabled="!(newPerson.name && newPerson.surname)" ng-click="fastAddPerson(newPerson, true)" class="btn btn-success top5">
<span class="glyphicon glyphicon-plus-sign"></span>
{{'Add' | translate}}
</button>
@ -91,14 +91,14 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="person in allPersons | splittedFilter:query">
<tr ng-repeat="person in allPersons | filter:newPerson">
<td>
<strong><a ui-sref="person.info({id: person.person_id})">{{person.name}} {{person.surname}}</a></strong>
<br />
{{person.email}}
</td>
<td>
<button ng-click="addAttendee(person)" type="button" class="btn btn-link glyphicon glyphicon-plus-sign"></button>
<button ng-click="fastAddPerson(person)" type="button" class="btn btn-link glyphicon glyphicon-plus-sign"></button>
</td>
</tr>
</tbody>

View file

@ -76,23 +76,30 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person',
$scope.eventForm.$dirty = false;
};
$scope.fastAddPerson = function(newPerson) {
$log.debug('EventDetailsCtrl.fastAddPerson.newPerson:');
$log.debug(newPerson);
var person = new Person(newPerson);
person.$save(function(p) {
var data = angular.copy(p);
data.person_id = data._id;
data._id = $stateParams.id;
data.attended = true;
Event.addAttendee(data, function() {
$scope.event = Event.get($stateParams);
$scope.allPersons = Person.all();
$scope.newPerson = {};
});
$scope._addAttendee = function(person_data) {
person_data.person_id = person_data._id;
person_data._id = $stateParams.id;
person_data.attended = true;
Event.addAttendee(person_data, function() {
$scope.event = Event.get($stateParams);
$scope.allPersons = Person.all();
$scope.newPerson = {};
});
};
$scope.fastAddPerson = function(person, isNew) {
$log.debug('EventDetailsCtrl.fastAddPerson.person:');
$log.debug(person);
if (isNew) {
var personObj = new Person(person);
personObj.$save(function(p) {
$scope._addAttendee(angular.copy(p));
});
} else {
$scope._addAttendee(person);
}
};
$scope.updateAttendee = function(person, attended) {
$log.debug('EventDetailsCtrl.event_id: ' + $stateParams.id);
$log.debug('EventDetailsCtrl.person_id: ' + person.person_id);
@ -116,6 +123,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person',
},
function(data) {
$scope.event.persons = data;
$scope.allPersons = Person.all();
});
};
}]