2019-01-20 18:37:45 +00:00
|
|
|
/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
2023-03-25 11:34:16 +00:00
|
|
|
* Copyright (C) 2018-2023 jkrehm, OzzieIsaacs
|
2019-01-20 18:37:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-08-13 05:24:56 +00:00
|
|
|
/* global _ */
|
|
|
|
|
2023-03-25 11:34:16 +00:00
|
|
|
function handleResponse (data) {
|
|
|
|
$(".row-fluid.text-center").remove();
|
|
|
|
$("#flash_danger").remove();
|
|
|
|
$("#flash_success").remove();
|
|
|
|
if (!jQuery.isEmptyObject(data)) {
|
|
|
|
if($("#bookDetailsModal").is(":visible")) {
|
|
|
|
data.forEach(function (item) {
|
|
|
|
$(".modal-header").after('<div id="flash_' + item.type +
|
|
|
|
'" class="text-center alert alert-' + item.type + '">' + item.message + '</div>');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
data.forEach(function (item) {
|
|
|
|
$(".navbar").after('<div class="row-fluid text-center">' +
|
|
|
|
'<div id="flash_' + item.type + '" class="alert alert-' + item.type + '">' + item.message + '</div>' +
|
|
|
|
'</div>');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(".sendbtn-form").click(function() {
|
|
|
|
$.ajax({
|
|
|
|
method: 'post',
|
|
|
|
url: $(this).data('href'),
|
2023-07-29 13:15:38 +00:00
|
|
|
data: {csrf_token: $("input[name='csrf_token']").val()},
|
2023-03-25 11:34:16 +00:00
|
|
|
success: function (data) {
|
|
|
|
handleResponse(data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-08-13 05:24:56 +00:00
|
|
|
$(function() {
|
2017-07-22 03:42:01 +00:00
|
|
|
$("#have_read_form").ajaxForm();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#have_read_cb").on("change", function() {
|
2021-10-15 17:26:20 +00:00
|
|
|
$.ajax({
|
2021-05-01 16:42:57 +00:00
|
|
|
url: this.closest("form").action,
|
2021-10-15 17:26:20 +00:00
|
|
|
method:"post",
|
|
|
|
data: $(this).closest("form").serialize(),
|
2021-05-01 16:42:57 +00:00
|
|
|
error: function(response) {
|
|
|
|
var data = [{type:"danger", message:response.responseText}]
|
2022-03-12 21:15:19 +00:00
|
|
|
// $("#flash_success").parent().remove();
|
2021-05-01 16:42:57 +00:00
|
|
|
$("#flash_danger").remove();
|
2022-03-12 21:15:19 +00:00
|
|
|
$(".row-fluid.text-center").remove();
|
2021-05-01 16:42:57 +00:00
|
|
|
if (!jQuery.isEmptyObject(data)) {
|
2022-03-12 21:15:19 +00:00
|
|
|
$("#have_read_cb").prop("checked", !$("#have_read_cb").prop("checked"));
|
|
|
|
if($("#bookDetailsModal").is(":visible")) {
|
|
|
|
data.forEach(function (item) {
|
|
|
|
$(".modal-header").after('<div id="flash_' + item.type +
|
|
|
|
'" class="text-center alert alert-' + item.type + '">' + item.message + '</div>');
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
data.forEach(function (item) {
|
|
|
|
$(".navbar").after('<div class="row-fluid text-center" >' +
|
|
|
|
'<div id="flash_' + item.type + '" class="alert alert-' + item.type + '">' + item.message + '</div>' +
|
|
|
|
'</div>');
|
|
|
|
});
|
|
|
|
}
|
2021-05-01 16:42:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-22 03:42:01 +00:00
|
|
|
});
|
|
|
|
|
2020-01-25 23:29:17 +00:00
|
|
|
$(function() {
|
|
|
|
$("#archived_form").ajaxForm();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#archived_cb").on("change", function() {
|
|
|
|
$(this).closest("form").submit();
|
|
|
|
});
|
|
|
|
|
2017-08-13 05:24:56 +00:00
|
|
|
(function() {
|
|
|
|
var templates = {
|
|
|
|
add: _.template(
|
|
|
|
$("#template-shelf-add").html()
|
|
|
|
),
|
|
|
|
remove: _.template(
|
|
|
|
$("#template-shelf-remove").html()
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2022-01-25 18:30:17 +00:00
|
|
|
$("#add-to-shelves, #remove-from-shelves").on("click", "[data-shelf-action]", function (e) {
|
2017-08-13 05:24:56 +00:00
|
|
|
e.preventDefault();
|
2022-01-17 16:46:57 +00:00
|
|
|
$.ajax({
|
2022-01-25 18:30:17 +00:00
|
|
|
url: $(this).data('href'),
|
2022-01-17 16:46:57 +00:00
|
|
|
method:"post",
|
|
|
|
data: {csrf_token:$("input[name='csrf_token']").val()},
|
|
|
|
})
|
2017-08-13 05:24:56 +00:00
|
|
|
.done(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
switch ($this.data("shelf-action")) {
|
|
|
|
case "add":
|
|
|
|
$("#remove-from-shelves").append(
|
|
|
|
templates.remove({
|
2022-01-25 18:30:17 +00:00
|
|
|
add: $this.data('href'),
|
2017-08-13 05:24:56 +00:00
|
|
|
remove: $this.data("remove-href"),
|
2021-08-30 15:05:53 +00:00
|
|
|
content: $("<div>").text(this.textContent).html()
|
2017-08-13 05:24:56 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
$("#add-to-shelves").append(
|
|
|
|
templates.add({
|
|
|
|
add: $this.data("add-href"),
|
2022-01-25 18:30:17 +00:00
|
|
|
remove: $this.data('href'),
|
2021-08-30 15:05:53 +00:00
|
|
|
content: $("<div>").text(this.textContent).html(),
|
2017-08-13 05:24:56 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
}.bind(this))
|
|
|
|
.fail(function(xhr) {
|
|
|
|
var $msg = $("<span/>", { "class": "text-danger"}).text(xhr.responseText);
|
|
|
|
$("#shelf-action-status").html($msg);
|
2017-07-22 03:42:01 +00:00
|
|
|
|
2017-08-13 05:24:56 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$msg.remove();
|
|
|
|
}, 10000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|