2017-07-22 03:42:01 +00:00
|
|
|
$( document ).ready(function() {
|
|
|
|
$("#have_read_form").ajaxForm();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#have_read_cb").on("change", function() {
|
|
|
|
$(this).closest("form").submit();
|
|
|
|
});
|
|
|
|
|
2017-07-22 18:24:47 +00:00
|
|
|
$("#shelf-actions").on("click", "[data-shelf-action]", function (e) {
|
2017-07-22 03:42:01 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$.get(this.href)
|
|
|
|
.done(() => {
|
|
|
|
const $this = $(this);
|
|
|
|
switch ($this.data("shelf-action")) {
|
|
|
|
case "add":
|
|
|
|
$("#remove-from-shelves").append(`<a href="${$this.data("remove-href")}"
|
|
|
|
data-add-href="${this.href}"
|
|
|
|
class="btn btn-sm btn-default" data-shelf-action="remove"
|
|
|
|
><span class="glyphicon glyphicon-remove"></span> ${this.textContent}</a>`);
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
$("#add-to-shelves").append(`<li><a href="${$this.data("add-href")}"
|
|
|
|
data-remove-href="${this.href}"
|
|
|
|
data-shelf-action="add"
|
|
|
|
>${this.textContent}</a></li>`);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
})
|
2017-07-22 14:34:38 +00:00
|
|
|
.fail((xhr) => {
|
2017-07-22 03:42:01 +00:00
|
|
|
const $msg = $("<span/>", { "class": "text-danger"}).text(xhr.responseText);
|
|
|
|
$("#shelf-action-status").html($msg);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
$msg.remove();
|
|
|
|
}, 10000);
|
|
|
|
});
|
|
|
|
});
|