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');
|
2012-03-12 19:08:47 +00:00
|
|
|
if (json.total_book_count === 1) {
|
|
|
|
$('<option value="' + 'all:' + json.total_book_count + '">' + 'all (' + json.total_book_count +' book)' + '</option>').appendTo(sel);
|
|
|
|
} else {
|
|
|
|
$('<option value="' + 'all:' + json.total_book_count + '">' + 'all (' + json.total_book_count +' books)' + '</option>').appendTo(sel);
|
|
|
|
}
|
2012-01-24 17:36:45 +00:00
|
|
|
for (var i = 0; i < json.user_shelves.length; i++) {
|
2012-03-12 19:08:47 +00:00
|
|
|
if (json.user_shelves[i].book_count === 1) {
|
|
|
|
$('<option value="' + json.user_shelves[i].name + ':' + json.user_shelves[i].book_count + '">' + json.user_shelves[i].name +
|
|
|
|
' (' + json.user_shelves[i].book_count + ' book)' + '</option>').appendTo(sel);
|
|
|
|
} else {
|
|
|
|
$('<option value="' + json.user_shelves[i].name + ':' + json.user_shelves[i].book_count + '">' + json.user_shelves[i].name +
|
|
|
|
' (' + json.user_shelves[i].book_count + ' books)' + '</option>').appendTo(sel);
|
|
|
|
}
|
2012-01-24 17:36:45 +00:00
|
|
|
}
|
|
|
|
$('#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
|
|
|
|
|
|
|
});
|