Skip to content

Commit

Permalink
Extract submission as separate event
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogoevici authored and pmuir committed May 28, 2012
1 parent c0da45b commit 8414d73
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/main/webapp/tm-index.html
Expand Up @@ -242,6 +242,9 @@


TicketMonster.CreateBookingView = Backbone.View.extend({
events:{
"submit form":"save"
},
render:function (showId, performanceId) {
loadedSections = new Object()
loadedPrices = new Object()
Expand Down Expand Up @@ -274,31 +277,30 @@
$("#bookTickets").append("Email: <input type='email' name='email' required/>");
$("#bookTickets").append("<input type='hidden' name='performance' value='" + performanceId + "'/>")
$("#bookTickets").append("<input name='createBooking' type='submit' value='Book!'/>")
$("#bookTickets").submit(function (event) {
event.preventDefault()
$.post("rest/bookings", $(this).serialize(),
function (booking) {
$("#book").empty()

$("#book").append("Created booking " + booking.id + " with tickets as follows: ")
$.each(booking.allocations, function (i, allocation) {
if (allocation.quantity > 1) {
$("#book").append("<p/> Section " + allocation.row.section.name + " Row " + allocation.row.name + ", seats " + allocation.startSeat + "-" + allocation.endSeat)
} else {
$("#book").append("<p/> Section " + allocation.row.section.name + " Row " + allocation.row.name + ", seat " + allocation.startSeat)
}
$.each(allocation.ticketsPerCategory, function (i, entry) {
$("#book").append("<p/> " + entry.ticketCount + " " + entry.ticketCategory.description)
})
})

}).error(function (error) {
alert(error)
})
})
})

})
},
save:function (event) {
event.originalEvent.preventDefault()
$.post("rest/bookings", $(event.currentTarget).serialize(),
function (booking) {
$("#book").empty()

$("#book").append("Created booking " + booking.id + " with tickets as follows: ")
$.each(booking.allocations, function (i, allocation) {
if (allocation.quantity > 1) {
$("#book").append("<p/> Section " + allocation.row.section.name + " Row " + allocation.row.name + ", seats " + allocation.startSeat + "-" + allocation.endSeat)
} else {
$("#book").append("<p/> Section " + allocation.row.section.name + " Row " + allocation.row.name + ", seat " + allocation.startSeat)
}
$.each(allocation.ticketsPerCategory, function (i, entry) {
$("#book").append("<p/> " + entry.ticketCount + " " + entry.ticketCategory.description)
})
})

}).error(function (error) {
alert(error)
})
}
})

Expand Down

0 comments on commit 8414d73

Please sign in to comment.