From 33a0a4c173a5ae229427a1e296d38da63d54293f Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 31 Jan 2021 18:55:32 +0100 Subject: [PATCH] Changed function for getting path in js file --- cps/static/js/edit_books.js | 4 ++-- cps/static/js/main.js | 28 ++++++++++++---------------- cps/templates/admin.html | 3 +-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 5f9154fc..b7890764 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -78,10 +78,10 @@ function prefixedSource(prefix, query, cb, bhAdapter) { }); } -function getPath() { +/*function getPath() { var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path return jsFileLocation.substr(0, jsFileLocation.search("/static/js/edit_books.js")); // the js folder path -} +}*/ var authors = new Bloodhound({ name: "authors", diff --git a/cps/static/js/main.js b/cps/static/js/main.js index 33881aaa..fe617763 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -15,6 +15,11 @@ * along with this program. If not, see . */ + +function getPath() { + var jsFileLocation = $("script[src*=jquery]").attr("src"); // the js file path + return jsFileLocation.substr(0, jsFileLocation.search("/static/js/libs/jquery.min.js")); // the js folder path +} // Generic control/related handler to show/hide fields based on a checkbox' value // e.g. // @@ -110,15 +115,13 @@ $(document).ready(function() { }); function ConfirmDialog(id, dataValue, yesFn, noFn) { - var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src; - var path = src.substring(0, src.lastIndexOf("/")); var $confirm = $("#GeneralDeleteModal"); // var dataValue= e.data('value'); // target.data('value'); $confirm.modal('show'); $.ajax({ method:"get", dataType: "json", - url: path + "/../../ajax/loaddialogtexts/" + id, + url: getPath() + "/ajax/loaddialogtexts/" + id, success: function success(data) { $("#header").html(data.header); $("#text").html(data.main); @@ -140,15 +143,13 @@ function ConfirmDialog(id, dataValue, yesFn, noFn) { $("#delete_confirm").click(function() { //get data-id attribute of the clicked element - var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src; - var path = src.substring(0, src.lastIndexOf("/")); var deleteId = $(this).data("delete-id"); var bookFormat = $(this).data("delete-format"); if (bookFormat) { - window.location.href = path + "/../../delete/" + deleteId + "/" + bookFormat; + window.location.href = getPath() + "/delete/" + deleteId + "/" + bookFormat; } else { if ($(this).data("delete-format")) { - path = path + "/../../ajax/delete/" + deleteId; + path = getPath() + "/ajax/delete/" + deleteId; $.ajax({ method:"get", url: path, @@ -168,7 +169,7 @@ $("#delete_confirm").click(function() { } }); } else { - window.location.href = path + "/../../delete/" + deleteId; + window.location.href = getPath() + "/delete/" + deleteId; } } @@ -224,7 +225,7 @@ $(function() { function updateTimer() { $.ajax({ dataType: "json", - url: window.location.pathname + "/../../get_updater_status", + url: window.location.pathname + "/get_updater_status", success: function success(data) { // console.log(data.status); $("#DialogContent").html(updateText[data.status]); @@ -484,12 +485,9 @@ $(function() { $(this).attr('id'), $(this).data('value'), function (value) { - var pathname = document.getElementsByTagName("script"); - var src = pathname[pathname.length - 1].src; - var path = src.substring(0, src.lastIndexOf("/")); $.ajax({ method: "get", - url: path + "/../../kobo_auth/deleteauthtoken/" + value, + url: getPath() + "/kobo_auth/deleteauthtoken/" + value, }); $("#config_delete_kobo_token").hide(); } @@ -582,12 +580,10 @@ $(function() { $("#DialogFinished").addClass("hidden"); $("#DialogContent").html(""); $("#spinner2").show(); - var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src; - var path = src.substring(0, src.lastIndexOf("/")); $.ajax({ method:"get", dataType: "json", - url: path + "/../../import_ldap_users", + url: getPath() + "/import_ldap_users", success: function success(data) { $("#spinner2").hide(); $("#DialogContent").html(data.text); diff --git a/cps/templates/admin.html b/cps/templates/admin.html index 777a6f8a..89e423a2 100644 --- a/cps/templates/admin.html +++ b/cps/templates/admin.html @@ -42,9 +42,8 @@ {% endif %} {% endfor %} - {% else %} - {% endif %} + {% if (config.config_login_type == 1) %}
{{_('Import LDAP Users')}}