fixes #180: delete all tickets of an event
This commit is contained in:
parent
09035932ad
commit
f5154bcddd
3 changed files with 64 additions and 25 deletions
|
@ -74,7 +74,15 @@
|
|||
</td>
|
||||
<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|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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
48
angular_app/js/controllers.js
vendored
48
angular_app/js/controllers.js
vendored
|
@ -64,10 +64,19 @@ eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModal
|
|||
);
|
||||
|
||||
|
||||
eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', '$state', '$filter',
|
||||
function ($scope, Event, $uibModal, $log, $translate, $rootScope, $state, $filter) {
|
||||
eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', 'EventTicket', '$uibModal', '$log', '$translate', '$rootScope', '$state', '$filter', 'toaster',
|
||||
function ($scope, Event, EventTicket, $uibModal, $log, $translate, $rootScope, $state, $filter, toaster) {
|
||||
$scope.query = '';
|
||||
$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) {
|
||||
if (events && $state.is('tickets')) {
|
||||
angular.forEach(events, function(evt, idx) {
|
||||
|
@ -81,14 +90,6 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal'
|
|||
$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() {
|
||||
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_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 () {
|
||||
$translate('Do you really want to delete this event?').then(function (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) {
|
||||
|
@ -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) {
|
||||
var new_order = [key];
|
||||
var inv_key;
|
||||
|
|
|
@ -874,28 +874,31 @@ class EventsHandler(CollectionHandler):
|
|||
return ret
|
||||
|
||||
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
|
||||
doc = self.db.query('events',
|
||||
{'_id': id_, 'tickets._id': ticket_id})
|
||||
doc = self.db.query('events', {'_id': id_})
|
||||
ret = {'action': 'delete', '_id': ticket_id, 'uuid': uuid}
|
||||
if doc:
|
||||
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',
|
||||
{'_id': id_},
|
||||
{'tickets': {'_id': ticket_id}},
|
||||
{'tickets': ticket_query},
|
||||
operation='delete',
|
||||
create=False)
|
||||
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
|
||||
env = dict(ticket)
|
||||
env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_,
|
||||
'EVENT_TITLE': rdoc.get('title', ''), 'WEB_USER': self.current_user_info.get('username', ''),
|
||||
'WEB_REMOTE_IP': self.request.remote_ip})
|
||||
stdin_data = {'old': ticket,
|
||||
'event': rdoc,
|
||||
'merged': merged
|
||||
}
|
||||
self.run_triggers('delete_ticket_in_event', stdin_data=stdin_data, env=env)
|
||||
if ticket:
|
||||
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
|
||||
env = dict(ticket)
|
||||
env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_,
|
||||
'EVENT_TITLE': rdoc.get('title', ''), 'WEB_USER': self.current_user_info.get('username', ''),
|
||||
'WEB_REMOTE_IP': self.request.remote_ip})
|
||||
stdin_data = {'old': ticket,
|
||||
'event': rdoc,
|
||||
'merged': merged
|
||||
}
|
||||
self.run_triggers('delete_ticket_in_event', stdin_data=stdin_data, env=env)
|
||||
return ret
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue