Skip to content

Instantly share code, notes, and snippets.

@codylindley
Created July 6, 2010 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codylindley/466024 to your computer and use it in GitHub Desktop.
Save codylindley/466024 to your computer and use it in GitHub Desktop.
/*recent orders*/
before(function(context) {
var email = context.store.get('email');
if(email) {
var foo = context.cache();
console.log(foo.recentOrders);
if(foo.recentOrders){
context.partial('templates/previous_orders/recent.mustache', PreviousOrdersView(context.cache().recentOrders), function(html) {
$('.recent_orders').html(html);
});
console.log('from cache');
}else{
var url = context.recent_orders_url(email, 5);
$.ajax({
url: url,
type: 'get',
beforeSend: function(xhr) {
context.authenticate(xhr, url);
},
success: function(orders) {
context.partial('templates/previous_orders/recent.mustache', PreviousOrdersView(orders), function(html) {
$('.recent_orders').html(html);
});
foo.recentOrders = orders;
console.log('not from cache');
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment