2011-11-17 00:47:29 +00:00
|
|
|
jQuery(document).ready(function($) {
|
|
|
|
|
|
|
|
// post to form_loc and alert with response
|
|
|
|
var post_and_alert = function (form_loc){
|
|
|
|
|
2011-12-26 17:53:28 +00:00
|
|
|
return function(bubble,location,params) {
|
2011-11-17 00:47:29 +00:00
|
|
|
$.post(form_loc, params, function (data) {
|
2011-12-26 17:53:28 +00:00
|
|
|
$(location+' > div').html(data);
|
2011-11-17 00:47:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return bubble;
|
|
|
|
}
|
|
|
|
};
|
2012-01-24 17:36:45 +00:00
|
|
|
|
2011-11-17 00:47:29 +00:00
|
|
|
|
|
|
|
$('#librarything_load').submit(function(){
|
2011-12-26 17:53:28 +00:00
|
|
|
post_and_alert('/librarything/load/')(false,'#librarything_load',$('#librarything_load').serialize());
|
2011-11-17 00:47:29 +00:00
|
|
|
return false;
|
2012-01-24 17:36:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#load_shelf_form').submit(function(){
|
|
|
|
// do ajax call to pick up the list of shelves
|
|
|
|
|
|
|
|
if ($('#id_goodreads_shelf_name_number').length == 0) {
|
|
|
|
|
|
|
|
var params = {};
|
|
|
|
$.getJSON('/goodreads/shelves', params, function(json) {
|
|
|
|
// say waiting
|
|
|
|
$('#goodreads_input').attr('value', 'Loading....');
|
|
|
|
var sel = $('<select id="id_goodreads_shelf_name_number" name="goodreads_shelf_name_number"></select>').appendTo('#goodreads_shelves');
|
|
|
|
$('<option value="' + 'all:' + json.total_book_count + '">' + 'all (' + json.total_book_count +')' + '</option>').appendTo(sel);
|
|
|
|
for (var i = 0; i < json.user_shelves.length; i++) {
|
|
|
|
$('<option value="' + json.user_shelves[i].name + ':' + json.user_shelves[i].book_count + '">' + json.user_shelves[i].name +
|
|
|
|
' (' + json.user_shelves[i].book_count + ')' + '</option>').appendTo(sel);
|
|
|
|
}
|
|
|
|
$('#load_gr_shelves_list').attr('id','load_shelf_form');
|
|
|
|
$('#goodreads_input').attr('value', 'Add this shelf');
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
post_and_alert('/goodreads/load_shelf/')(false,'#load_shelf_form',$('#load_shelf_form').serialize());
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// change the button value
|
|
|
|
// change form id to 'load_shelf_form'
|
|
|
|
});
|
2011-11-17 00:47:29 +00:00
|
|
|
|
|
|
|
});
|