Skip to content

Commit

Permalink
Simplification - collapse bookings in a single view
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogoevici authored and pmuir committed May 28, 2012
1 parent 41a46db commit d202864
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
43 changes: 9 additions & 34 deletions src/main/webapp/resources/js/app/views/desktop/bookings.js
@@ -1,48 +1,23 @@
define([
'backbone',
'utilities',
'text!../../../../templates/desktop/booking-row.html',
'text!../../../../templates/desktop/booking-table.html',
'require',
'bootstrap'
'text!../../../../templates/desktop/booking-table.html'
],function (Backbone,
utilities,
bookingRowTemplate,
bookingTableTemplate,
require) {
bookingTableTemplate) {


// A subview of the BookingsView
var BookingRowView = Backbone.View.extend({
tagName:'tr',
var BookingsView = Backbone.View.extend({
events:{
"click i[data-tm-role='delete']":"deleteBooking",
"click a":"showDetails"
"click i[data-tm-role='delete']":"deleteBooking"
},
render:function () {
utilities.applyTemplate($(this.el), bookingRowTemplate, this.model.attributes);
return this;
utilities.applyTemplate($(this.el), bookingTableTemplate, {model:this.model});
},
deleteBooking:function (event) {
if (confirm("Are you sure you want to delete booking " + this.model.get('id'))) {
this.model.destroy({wait:true});
}
event.stopPropagation();
event.stopImmediatePropagation();
},
showDetails:function () {
require('router').navigate("#bookings/" + this.model.get('id'), true);
}
});


var BookingsView = Backbone.View.extend({
render:function () {
utilities.applyTemplate($(this.el), bookingTableTemplate, {});
_.each(this.model.models, function (booking) {
var bookingView = new BookingRowView({model:booking});
$("#bookingList").append(bookingView.render().el);
});
var id = $(event.currentTarget).data("tm-id");
if (confirm("Are you sure you want to delete booking " + this.model.get(id).get('id'))) {
this.model.get(id).destroy({wait:true});
};
}
});

Expand Down
6 changes: 0 additions & 6 deletions src/main/webapp/resources/templates/desktop/booking-row.html

This file was deleted.

11 changes: 10 additions & 1 deletion src/main/webapp/resources/templates/desktop/booking-table.html
Expand Up @@ -13,7 +13,16 @@ <h3 class="page-header">Current bookings</h3>
</tr>
</thead>
<tbody id='bookingList'>

<% _.each(model.models, function (booking) { %>
<tr>
<td><a href="#bookings/<%=booking.id%>"><%=booking.attributes.id%></a></td>
<td><%=booking.attributes.contactEmail%></td>
<td><%=new Date(booking.attributes.createdOn).toPrettyString()%></td>
<td><%=booking.attributes.tickets.length%></td>
<td>$<%=booking.attributes.totalTicketPrice%></td>
<td><i data-tm-role='delete' data-tm-id="<%=booking.attributes.id%>" class="icon-trash" title="Delete booking"></i></td>
</tr>
<% }); %>
</tbody>
</table>
</div>
Expand Down

0 comments on commit d202864

Please sign in to comment.