From b29f90747b4774fe64fb1fbf98859c0002297c9e Mon Sep 17 00:00:00 2001
From: Davide Alberani
Date: Thu, 9 Jun 2016 23:13:56 +0200
Subject: [PATCH] update ticket
---
angular_app/events-list.html | 4 ++--
angular_app/js/controllers.js | 19 ++++++++++++++-----
angular_app/js/services.js | 18 +++++-------------
angular_app/ticket-edit.html | 16 ++++++++++------
eventman_server.py | 13 +++++++------
5 files changed, 38 insertions(+), 32 deletions(-)
diff --git a/angular_app/events-list.html b/angular_app/events-list.html
index 56f2e28..d1a740f 100644
--- a/angular_app/events-list.html
+++ b/angular_app/events-list.html
@@ -42,10 +42,10 @@
{{'Ends:' | translate}} {{event['end-date'] | date:'fullDate' }} {{event['end-time'] | date:'HH:mm'}}
- {{attendeesNr}} / {{event.persons.length || 0}} ({{((attendeesNr / (event.persons.length || 0) * 100) || 0).toFixed()}}%)
+ {{attendeesNr}} / {{event.persons.length || 0}} ({{((attendeesNr / (event.persons.length || 0) * 100) || 0).toFixed()}}%)
|
-
+
|
diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js
index 02dccaa..b80c8f1 100644
--- a/angular_app/js/controllers.js
+++ b/angular_app/js/controllers.js
@@ -363,6 +363,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
function ($scope, $state, Event, EventTicket, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope) {
$scope.message = {};
$scope.event = {};
+ $scope.ticket = {};
$scope.newTicket = $state.is('event.ticket.new');
@@ -373,7 +374,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
if ($state.params.ticket_id) {
EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) {
- $scope.newPerson = data.person;
+ $scope.ticket = data;
});
}
@@ -381,11 +382,19 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
var personObj = new Person(person);
personObj.$save(function(p) {
person.person_id = p._id;
- person._id = $stateParams.id; // that's the id of the event, not the person.
- EventTicket.addTicket(person, function(p) {
- $log.debug(p);
+ person._id = $state.params.id; // that's the id of the event, not the person.
+ EventTicket.add(person, function(ticket) {
+ $log.debug(ticket);
+ $state.go('event.ticket.edit', {ticket_id: ticket._id});
});
- $scope.newPerson = {};
+ });
+ };
+
+ $scope.updateTicket = function(ticket) {
+ var data = angular.copy(ticket);
+ data.ticket_id = data._id;
+ data._id = $state.params.id;
+ EventTicket.update(data, function(t) {
});
};
}]
diff --git a/angular_app/js/services.js b/angular_app/js/services.js
index a44c84f..f16a3da 100644
--- a/angular_app/js/services.js
+++ b/angular_app/js/services.js
@@ -107,31 +107,23 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope',
interceptor : {responseError: $rootScope.errorHandler},
transformResponse: function(data, headers) {
data = angular.fromJson(data);
- convert_dates(data);
- // strip empty keys.
- angular.forEach(data.persons || [], function(person, person_idx) {
- angular.forEach(person, function(value, key) {
- if (value === "") {
- delete person[key];
- }
- });
- });
- return data;
+ return data.person;
}
},
- addTicket: {
+ add: {
method: 'POST',
interceptor : {responseError: $rootScope.errorHandler},
isArray: false,
url: 'events/:id/tickets/:ticket_id',
params: {uuid: $rootScope.app_uuid},
transformResponse: function(data, headers) {
- return angular.fromJson(data);
+ data = angular.fromJson(data);
+ return data.person;
}
},
- updateTicket: {
+ update: {
method: 'PUT',
interceptor : {responseError: $rootScope.errorHandler},
isArray: false,
diff --git a/angular_app/ticket-edit.html b/angular_app/ticket-edit.html
index 169cf3e..e1e9d52 100644
--- a/angular_app/ticket-edit.html
+++ b/angular_app/ticket-edit.html
@@ -18,29 +18,33 @@
diff --git a/eventman_server.py b/eventman_server.py
index 0a9e45e..d2a8e9e 100755
--- a/eventman_server.py
+++ b/eventman_server.py
@@ -68,9 +68,7 @@ class BaseHandler(tornado.web.RequestHandler):
permissions = {
'event|read': True,
'events|read': True,
- 'event:tickets|create': True,
- 'event:tickets|update': True,
- 'event:tickets|read': True,
+ 'event:tickets|all': True,
'person|create': True
}
@@ -532,13 +530,15 @@ class EventsHandler(CollectionHandler):
handle_post_tickets = handle_post_persons
- def handle_put_persons(self, id_, person_id, data):
+ def handle_put_persons(self, id_, person_id, data, ticket=False):
# Update an existing entry for a person registered at this event.
self._clean_dict(data)
uuid, arguments = self.uuid_arguments
query = dict([('persons.%s' % k, v) for k, v in arguments.iteritems()])
query['_id'] = id_
- if person_id is not None:
+ if ticket:
+ query['persons._id'] = person_id
+ elif person_id is not None:
query['persons.person_id'] = person_id
old_person_data = {}
current_event = self.db.query(self.collection, query)
@@ -573,7 +573,8 @@ class EventsHandler(CollectionHandler):
self.send_ws_message('event/%s/updates' % id_, json.dumps(ret))
return ret
- handle_put_tickets = handle_put_persons
+ def handle_put_tickets(self, id_, person_id, data):
+ return self.handle_put_persons(id_, person_id, data, True)
def handle_delete_persons(self, id_, person_id):
# Remove a specific person from the list of persons registered at this event.