Enough on goodreads for now.

pull/1/head
Raymond Yee 2011-11-01 15:23:54 -07:00
parent fa1806759b
commit 6ddebadf87
1 changed files with 37 additions and 21 deletions

View File

@ -5,37 +5,53 @@
jQuery(document).ready(function($) {
$('#test_click').click(function() {
var d = new Date();
// d.toUTCString()
// post to form_loc and alert with response
var post_and_alert = function (form_loc){
return function(bubble,params) {
$.post(form_loc, params, function (data) {
alert(data);
});
return bubble;
}
};
var update_number_of_books = function (){
$.ajax({url:'/api/v1/wishlist/1/',
data: {format:'json',
api_key:'{{api_key}}',
username: '{{user.username}}'},
success: function(json) {
$('#number_of_books_on_wishlist').html(json["works"].length);
var d = new Date();
$('#num_books_update_time').html(d.toUTCString());
},
error: function(jqXHR, textStatus, errorThrown) {
alert('error')
}
})
})
})
}
// add a current date time to the display of current number of books on wishlist
var d = new Date()
$('#num_books_update_time').html(d.toUTCString());
$('#test_click').click(update_number_of_books);
// post to form_loc and alert with response
post_and_alert = function(form_loc){
return function() {
$.post(form_loc, {}, function(data) {
alert(data);
});
return false;
}
};
$('#clear_wishlist_form').submit(post_and_alert('{% url clear_wishlist %}'));
$('#clear_wishlist_form').submit(function (){
post_and_alert('{% url clear_wishlist %}')(true,{});
update_number_of_books();
return false;
});
$('#load_shelf_form').submit(function(){
post_and_alert('{% url goodreads_load_shelf%}')(false,$('#load_shelf_form').serialize());
return false;
});
});
@ -62,7 +78,7 @@
<hr />
<form method="post" action="{% url goodreads_load_shelf%}">
<form id="load_shelf_form" method="post" action="#">
{{gr_shelf_load_form.as_p}}
<input type="submit" value="Load the books from your Goodreads shelf to your wishlist" />
</form>
@ -75,7 +91,7 @@
<hr />
<p><a href="#" id="test_click">Click here to update the number of books on your wishlist:</a></p>
<div id="gr_status"><p>Number of books on your wishlist: <span id="number_of_books_on_wishlist">{{user.wishlist.books.all|length}}</span></p></div>
<div id="gr_status"><p>Number of books on your wishlist: <span id="number_of_books_on_wishlist">{{user.wishlist.books.all|length}}</span> (as of <span id="num_books_update_time"></span>)</p></div>
<form id="clear_wishlist_form" method="post" action="#">
<input type="submit" value="Empty your wishlist" />
</form>