1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-10-27 13:28:04 +00:00

Refactored send email by make use of ajax calls instead of posting the page

Always use getPath instead of pathname
This commit is contained in:
Ozzie Isaacs
2023-03-25 12:34:16 +01:00
parent 2b9f920454
commit 321db4d712
8 changed files with 403 additions and 372 deletions

View File

@@ -314,9 +314,6 @@ $(document).mouseup(function (e) {
});
});
// Split path name to array and remove blanks
url = window.location.pathname
// Move create shelf
$("#nav_createshelf").prependTo(".your-shelves");
@@ -360,31 +357,6 @@ $(document).on("click", ".dropdown-toggle", function () {
});
});
// Fade out content on page unload
// delegate all clicks on "a" tag (links)
/*$(document).on("click", "a:not(.btn-toolbar a, a[href*='shelf/remove'], .identifiers a, .bookinfo , .btn-group > a, #add-to-shelves a, #book-list a, .stat.blur a )", function () {
// get the href attribute
var newUrl = $(this).attr("href");
// veryfy if the new url exists or is a hash
if (!newUrl || newUrl[0] === "#") {
// set that hash
location.hash = newUrl;
return;
}
now, fadeout the html (whole page)
$( '.blur-wrapper' ).fadeOut(250);
$(".row-fluid .col-sm-10").fadeOut(500,function () {
// when the animation is complete, set the new location
location = newUrl;
});
// prevent the default browser behavior.
return false;
});*/
// Collapse long text into read-more
$("div.comments").readmore({
collapsedHeight: 134,
@@ -447,6 +419,8 @@ if ($("body.author").length > 0) {
}
}
// Split path name to array and remove blanks
url = window.location.pathname
// Ereader Page - add class to iframe body on ereader page after it loads.
backurl = "../../book/" + url[2]
$("body.epub #title-controls")

View File

@@ -1,5 +1,5 @@
/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
* Copyright (C) 2018 jkrehm
* Copyright (C) 2018-2023 jkrehm, OzzieIsaacs
*
* 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
@@ -17,6 +17,35 @@
/* global _ */
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'),
success: function (data) {
handleResponse(data)
}
})
});
$(function() {
$("#have_read_form").ajaxForm();
});

View File

@@ -36,7 +36,7 @@ function init(logType) {
d.innerHTML = "loading ...";
$.ajax({
url: window.location.pathname + "/../../ajax/log/" + logType,
url: getPath() + "/../../ajax/log/" + logType,
datatype: "text",
cache: false
})

View File

@@ -85,14 +85,6 @@ $(document).on("change", "select[data-controlall]", function() {
}
});
/*$(document).on("click", "#sendbtn", function (event) {
postButton(event, $(this).data('action'));
});
$(document).on("click", ".sendbutton", function (event) {
// $(".sendbutton").on("click", "body", function(event) {
postButton(event, $(this).data('action'));
});*/
$(document).on("click", ".postAction", function (event) {
// $(".sendbutton").on("click", "body", function(event) {
@@ -100,7 +92,6 @@ $(document).on("click", ".postAction", function (event) {
});
// Syntax has to be bind not on, otherwise problems with firefox
$(".container-fluid").bind("dragenter dragover", function () {
if($("#btn-upload").length && !$('body').hasClass('shelforder')) {
@@ -321,7 +312,7 @@ $(function() {
folder: folder,
filter: filt
},
url: window.location.pathname + request_path,
url: getPath() + request_path,
success: function success(data) {
if ($("#element_selected").text() ==="") {
$("#element_selected").text(data.cwd);
@@ -434,7 +425,7 @@ $(function() {
}
$.ajax({
dataType: "json",
url: window.location.pathname + "/../../get_update_status",
url: getPath() + "/../../get_update_status",
success: function success(data) {
$this.html(buttonText);
@@ -538,6 +529,7 @@ $(function() {
$("#bookDetailsModal")
.on("show.bs.modal", function(e) {
$("#flash_danger").remove();
$("#flash_success").remove();
var $modalBody = $(this).find(".modal-body");
// Prevent static assets from loading multiple times
@@ -650,7 +642,6 @@ $(function() {
);
});
$("#user_submit").click(function() {
this.closest("form").submit();
});
@@ -682,7 +673,7 @@ $(function() {
$.ajax({
method:"post",
dataType: "json",
url: window.location.pathname + "/../../ajax/simulatedbchange",
url: getPath() + "/../../ajax/simulatedbchange",
data: {config_calibre_dir: $("#config_calibre_dir").val(), csrf_token: $("input[name='csrf_token']").val()},
success: function success(data) {
if ( data.change ) {
@@ -713,13 +704,13 @@ $(function() {
var loader = "/../..";
$("#flash_success").remove();
$("#flash_danger").remove();
$.post(window.location.pathname + request_path, $(this).closest("form").serialize(), function(data) {
$.post(getPath() + request_path, $(this).closest("form").serialize(), function(data) {
$('#config_upload_formats').val(data.config_upload);
if(data.reboot) {
$("#spinning_success").show();
var rebootInterval = setInterval(function(){
$.get({
url:window.location.pathname + "/../../admin/alive",
url:getPath() + "/../../admin/alive",
success: function (d, statusText, xhr) {
if (xhr.status < 400) {
$("#spinning_success").hide();
@@ -745,7 +736,6 @@ $(function() {
$(this).data('value'),
function(value){
postButton(event, $("#delete_shelf").data("action"));
// $("#delete_shelf").closest("form").submit()
}
);

View File

@@ -49,7 +49,7 @@ $(function() {
method: "post",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: window.location.pathname + "/../ajax/canceltask",
url: getPath() + "/../ajax/canceltask",
data: JSON.stringify({"task_id": taskId}),
});
});