fixes #180: delete all tickets of an event

This commit is contained in:
Davide Alberani 2017-04-30 12:33:03 +02:00
parent 09035932ad
commit f5154bcddd
3 changed files with 64 additions and 25 deletions

View file

@ -74,7 +74,15 @@
</td> </td>
<td ng-if="hasPermission('event|update') || hasPermission('event|delete')" class="vtop"> <td ng-if="hasPermission('event|update') || hasPermission('event|delete')" class="vtop">
<div ng-if="hasPermission('event|update')" class="top5 hcenter"><button ng-click="$state.go('event.edit', {id: event._id})" type="button" class="min150 btn btn-warning" title="{{'Edit event' | translate}}"><span class="fa fa-cog"></span> {{'Edit event' | translate}}</button></div> <div ng-if="hasPermission('event|update')" class="top5 hcenter"><button ng-click="$state.go('event.edit', {id: event._id})" type="button" class="min150 btn btn-warning" title="{{'Edit event' | translate}}"><span class="fa fa-cog"></span> {{'Edit event' | translate}}</button></div>
<div ng-if="hasPermission('event|delete')" class="top5 hcenter bottom5"><button ng-click="deleteEvent(event._id)" type="button" class="min150 btn btn-danger" title="{{'Delete event' | translate}}"><span class="fa fa-trash"></span> {{'Delete event' | translate}}</button></div> <div ng-if="hasPermission('event|delete')" class="top5 hcenter bottom5" id="delete-event" uib-dropdown>
<button type="button" class="min150 btn btn-danger" title="{{'Delete' | translate}}" uib-dropdown-toggle>
<span class="fa fa-trash"></span> {{'Delete' | translate}} <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="delete-event">
<li role="menuitem"><a href="#" ng-click="deleteEvent(event._id)">{{'Delete event' | translate}}</a></li>
<li role="menuitem"><a href="#" ng-click="deleteAllTickets(event._id)">{{'Delete all tickets in event' | translate}}</a></li>
</ul>
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -64,10 +64,19 @@ eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModal
); );
eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', '$state', '$filter', eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', 'EventTicket', '$uibModal', '$log', '$translate', '$rootScope', '$state', '$filter', 'toaster',
function ($scope, Event, $uibModal, $log, $translate, $rootScope, $state, $filter) { function ($scope, Event, EventTicket, $uibModal, $log, $translate, $rootScope, $state, $filter, toaster) {
$scope.query = ''; $scope.query = '';
$scope.tickets = []; $scope.tickets = [];
$scope.eventsOrderProp = "-begin_date";
$scope.ticketsOrderProp = ["name", "surname"];
$scope.shownItems = [];
$scope.currentPage = 1;
$scope.itemsPerPage = 10;
$scope.filteredLength = 0;
$scope.maxPaginationSize = 10;
$scope.events = Event.all(function(events) { $scope.events = Event.all(function(events) {
if (events && $state.is('tickets')) { if (events && $state.is('tickets')) {
angular.forEach(events, function(evt, idx) { angular.forEach(events, function(evt, idx) {
@ -81,14 +90,6 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal'
$scope.filterTickets(); $scope.filterTickets();
} }
}); });
$scope.eventsOrderProp = "-begin_date";
$scope.ticketsOrderProp = ["name", "surname"];
$scope.shownItems = [];
$scope.currentPage = 1;
$scope.itemsPerPage = 10;
$scope.filteredLength = 0;
$scope.maxPaginationSize = 10;
$scope.filterTickets = function() { $scope.filterTickets = function() {
var tickets = $scope.tickets || []; var tickets = $scope.tickets || [];
@ -111,10 +112,18 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal'
}); });
$scope.confirm_delete = 'Do you really want to delete this event?'; $scope.confirm_delete = 'Do you really want to delete this event?';
$scope.confirm_delete_all_tickets = 'Do you really want to delete all tickets from this event?';
$scope.deleted_all_tickets = 'successfully removed all tickets from event';
$rootScope.$on('$translateChangeSuccess', function () { $rootScope.$on('$translateChangeSuccess', function () {
$translate('Do you really want to delete this event?').then(function (translation) { $translate('Do you really want to delete this event?').then(function (translation) {
$scope.confirm_delete = translation; $scope.confirm_delete = translation;
}); });
$translate('Do you really want to delete all tickets from this event?').then(function (translation) {
$scope.confirm_delete_all_tickets = translation;
});
$translate('successfully removed all tickets from event').then(function (translation) {
$scope.deleted_all_tickets = translation;
});
}); });
$scope.deleteEvent = function(_id) { $scope.deleteEvent = function(_id) {
@ -133,6 +142,25 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal'
}); });
}; };
$scope.deleteAllTickets = function(_id) {
var modalInstance = $uibModal.open({
scope: $scope,
templateUrl: 'modal-confirm-action.html',
controller: 'ModalConfirmInstanceCtrl',
resolve: {
message: function() { return $scope.confirm_delete_all_tickets; }
}
});
modalInstance.result.then(function() {
EventTicket.delete({
event_id: _id
}, function() {
toaster.pop({type: 'error', title: $scope.deleted_all_tickets});
$scope.events = Event.all();
});
});
};
$scope.updateOrded = function(key) { $scope.updateOrded = function(key) {
var new_order = [key]; var new_order = [key];
var inv_key; var inv_key;

View file

@ -874,18 +874,21 @@ class EventsHandler(CollectionHandler):
return ret return ret
def handle_delete_tickets(self, id_, ticket_id): def handle_delete_tickets(self, id_, ticket_id):
# Remove a specific ticket from the list of tickets registered at this event. # Remove a ticket (or all tickets) from the list of tickets registered at this event.
uuid, arguments = self.uuid_arguments uuid, arguments = self.uuid_arguments
doc = self.db.query('events', doc = self.db.query('events', {'_id': id_})
{'_id': id_, 'tickets._id': ticket_id})
ret = {'action': 'delete', '_id': ticket_id, 'uuid': uuid} ret = {'action': 'delete', '_id': ticket_id, 'uuid': uuid}
if doc: if doc:
ticket = self._get_ticket_data(ticket_id, doc[0].get('tickets') or []) ticket = self._get_ticket_data(ticket_id, doc[0].get('tickets') or [])
ticket_query = {}
if ticket:
ticket_query['_id'] = ticket_id
merged, rdoc = self.db.update('events', merged, rdoc = self.db.update('events',
{'_id': id_}, {'_id': id_},
{'tickets': {'_id': ticket_id}}, {'tickets': ticket_query},
operation='delete', operation='delete',
create=False) create=False)
if ticket:
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
env = dict(ticket) env = dict(ticket)
env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_, env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_,