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> <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"> <input type="email" name="email" class="form-control" placeholder="{{'name.surname@example.com' | translate}}" ng-model="newPerson.email">
</div> </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> <span class="glyphicon glyphicon-plus-sign"></span>
{{'Add' | translate}} {{'Add' | translate}}
</button> </button>
@ -91,14 +91,14 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="person in allPersons | splittedFilter:query"> <tr ng-repeat="person in allPersons | filter:newPerson">
<td> <td>
<strong><a ui-sref="person.info({id: person.person_id})">{{person.name}} {{person.surname}}</a></strong> <strong><a ui-sref="person.info({id: person.person_id})">{{person.name}} {{person.surname}}</a></strong>
<br /> <br />
{{person.email}} {{person.email}}
</td> </td>
<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> </td>
</tr> </tr>
</tbody> </tbody>

View file

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