An Event can have multiple tickets for different purposes. For instance an Arts Exhibition can have multiple Galleries. The Organizer might be interested in assigning a ticket (let’s assume paid) for each Gallery. The user can then buy tickets for the Galleries that he wishes to attend. The feature that Multiple Tickets really provide is exclusiveness. Let’s say Gallery1
has a shorter area (by land) than others. Obviously the Organizer would want fewer people to be present there than other Galleries. To do this, he can create a separate ticket for Gallery1
and specify a shorter sales period. He can also reduce the Maximum number of order that a user can make (max_order
). If we would have implemented single ticket per event, this wouldn’t have been possible.
Tickets at Wizard
To handle multiple tickets at the wizard, proper naming of input tags was required. Since the number of tickets that can be created by the user was unknown to the server we had to send ticket field values as lists. Also at the client-side a way was required to let users create multiple tickets.
User Interface
A ticket can be of three types: Free
, Paid
and Donation
. Out of these, only the Paid tickets need a Price. The Tickets holder could be a simple table, with every ticket being a table row. This became more complex afterwards, when more details about the ticket needed to be displayed. A ticket would then be two table rows with one of them (details) hidden.
Ticket holder can be a simple bootstrap table:
<table class="table tickets-table">
<thead>
<tr>
<th>Ticket Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<!-- Ticket -->
<tr>
<!-- Main info -->
</tr>
<tr>
<!-- More details (initially hidden) -->
</tr>
<!-- /Ticket -->
</tbody>
</table>
To make ticket creation interactive, three buttons were needed to create the above three tickets. The type-name doesn’t not necessarily have to be shown to the user. It could be specified with the Price. For Paid ticket, the Price input
element would be a number. For Free and Donation tickets, a Price input
element wasn’t required. We could specify an element displaying one of the two types: Free or Donation.
Here’s the holder table with a Free Ticket and a Donation Ticket:
Since only the Price field is changing in the three types of tickets, I decided to create a template ticket outside of the form
and create a JavaScript function to create one of the tickets by cloning the template.
A Free Ticket with its edit options opened up. You can see other details about the ticket in the second table row.
This is a simplified version of the template. I’ve removed common bootstrap elements (grid system) including some other fields.
<div id="ticket-template">
<tr>
<td>
<input type="hidden" name="tickets[type]">
<input type="text" name="tickets[name]" class="form-control" placeholder="Ticket Name" required="required" data-uniqueticket="true">
<div class="help-block with-errors"></div>
</td>
<td>
<!-- Ticket Price -->
</td>
<td>
<input type="number" min="0" name="tickets[quantity]" class="form-control" placeholder="100" value="{{ quantity }}">
</td>
<td>
<div class="btn-group">
<a class="btn btn-info edit-ticket-button" data-toggle="tooltip" title="Settings">
<i class="glyphicon glyphicon-cog"></i>
</a>
<a class="btn btn-info remove-ticket-button" data-toggle="tooltip" title="Remove">
<i class="glyphicon glyphicon-trash"></i>
</a>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<div class="row" style="display: none;">
<!-- Other fields including Description, Sales Start and End time,
Min and Max Orders, etc.
-->
</div>
</td>
</tr>
</div>
Like I said, the Price element of ticket will make the type obvious for the user, so a type
field does not need to be displayed. But the type
field is required by the server. You can see it specified as hidden in the template.
The function to create a Ticket according to the type:
I’ve commented snippets to make it easy to understand.
function createTicket(type) {
/* Clone ticket from template */
var $tmpl = $("#ticket-template").children().clone();
var $ticket = $($tmpl[0]).attr("id", "ticket_" + String(ticketsCount));
var $ticketMore = $($tmpl[1]).attr("id", "ticket-more_" + String(ticketsCount));
/* Bind datepicker and timepicker to dates and times */
$ticketMore.find("input.date").datepicker();
$ticketMore.find("input.time").timepicker({
'showDuration': true,
'timeFormat': 'H:i',
'scrollDefault': 'now'
});
/* Bind iCheck to checkboxes */
$ticketMore.find("input.checkbox.flat").iCheck({
checkboxClass: 'icheckbox_flat-green',
radioClass: 'iradio_flat-green'
});
/* Bind events to Edit (settings) and Remove buttons */
var $ticketEdit = $ticket.find(".edit-ticket-button");
$ticketEdit.tooltip();
$ticketEdit.on("click", function () {
$ticketMore.toggle("slow");
$ticketMore.children().children(".row").slideToggle("slow");
});
var $ticketRemove = $ticket.find(".remove-ticket-button");
$ticketRemove.tooltip();
$ticketRemove.on("click", function () {
var confirmRemove = confirm("Are you sure you want to remove the Ticket?");
if (confirmRemove) {
$ticket.remove();
$ticketMore.remove();
}
});
/* Set Ticket Type field */
$ticket.children("td:nth-child(1)").children().first().val(type);
/* Set Ticket Price field */
var html = null;
if (type === "free") {
html = '';
} else if (type === "paid") {
html = '';
} else if (type === "donation") {
html = '';
}
$ticket.children("td:nth-child(2)").html(html);
/* Append ticket to table */
$ticket.hide();
$ticketMore.children().children(".row").hide();
$ticketsTable.append($ticket, $ticketMore);
$ticket.show("slow");
ticketsCount += 1;
}
The flow is simple. Clone the template, bind events to various elements, specify type and price fields and then append to the ticket holder table.
We use the Datepicker and Timepicker JavaScript libraries for date and time elements. So fields using these widgets need to have methods called on the elements. Also, we use iCheck for checkboxes and radio buttons. Apart from these, the Edit-Ticket and Remove-Ticket buttons also need event handlers. Edit-Ticket button toggles the Ticket Details segment (second tr
of a ticket). Remove-Ticket deletes the ticket. After the Price and Type fields are set, the ticket is appended to the holder table with slow animation.
Pingback: Multiple Tickets: Back-end – FOSSASIA