Bug 42289: Tidy all script tags - tools (auto tidy)

Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2026-04-03 11:45:23 +02:00 committed by Lucas Gass
parent 387a91eb58
commit a532a346bd
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 169 additions and 168 deletions

View File

@ -597,14 +597,12 @@
[% INCLUDE 'calendar.inc' %]
[% INCLUDE 'select2.inc' %]
[% Asset.js("js/tools-menu.js") | $raw %]
<script nonce="[% Koha.CSPNonce | $raw %]" data-tt-allowed="true">
const category = "[% category | html %]";
const wysiwyg = [% wysiwyg ? 1 : 0 | html %];
const interface = "[% interface | html %]";
const theme = "[% theme | html %]";
</script>
<script nonce="[% Koha.CSPNonce | $raw %]">
$("#saveandcontinue").on("click", function (e) {
e.preventDefault();
@ -693,48 +691,47 @@
</script>
[% ELSE %]
<script nonce="[% Koha.CSPNonce | $raw %]">
function showLocationNotes( location ){
function showLocationNotes(location) {
$(".customization_note").hide();
$( "#" + location + "_notes" ).show();
$("#" + location + "_notes").show();
}
$(document).ready(function() {
if ( category == 'news' ){
$("#add_additional_content").validate({
submitHandler: function(form){
if ( ! $("#title_default").val().length > 0 ) {
alert(_("Please specify a title for 'Default'"));
return false;
}
else {
if (!wysiwyg){
let content = $('#content_default').siblings(".CodeMirror")[0].CodeMirror.getValue();
} else {
let content = tinyMCE.get('content_default').getContent();
}
if ( ! content.length > 0 ) {
alert(_("Please specify a content for 'Default'"));
$(document).ready(function () {
if (category == "news") {
$("#add_additional_content").validate({
submitHandler: function (form) {
if (!$("#title_default").val().length > 0) {
alert(_("Please specify a title for 'Default'"));
return false;
}
}
} else {
if (!wysiwyg) {
let content = $("#content_default").siblings(".CodeMirror")[0].CodeMirror.getValue();
} else {
let content = tinyMCE.get("content_default").getContent();
}
form.submit();
}
});
if (!content.length > 0) {
alert(_("Please specify a content for 'Default'"));
return false;
}
}
form.submit();
},
});
}
showLocationNotes( $("#location").val() );
showLocationNotes($("#location").val());
$("#location").on("change", function(){
showLocationNotes( $(this).val() );
$("#location").on("change", function () {
showLocationNotes($(this).val());
});
$("#submit_form").on("click",function(){
$("#submit_form").on("click", function () {
$("#add_additional_content").submit();
});
$("#location").select2({ width: '50%' });
$("#location").select2({ width: "50%" });
});
</script>
[% END %]
@ -784,43 +781,43 @@
[% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
[% INCLUDE 'str/tinymce_i18n.inc' %]
<script nonce="[% Koha.CSPNonce | $raw %]">
$(document).ready(function(){
if( $("#tabs").length > 0 && $("#tabs .tab-pane.active").length < 1 ){
$(document).ready(function () {
if ($("#tabs").length > 0 && $("#tabs .tab-pane.active").length < 1) {
/* Activate first tab and initialize its tinyMCE instance */
let firstTab = $("#tabs a:first");
firstTab.tab("show");
initTinyMce( firstTab[0].hash );
initTinyMce(firstTab[0].hash);
}
$("#tabs a[data-bs-toggle='tab']").on("shown.bs.tab", function (e) {
/* Try to initialize tinyMCE instance when tab opens */
initTinyMce( e.target.hash );
initTinyMce(e.target.hash);
});
});
function initTinyMce( container ){
let textarea = $( container ).find("textarea[name^='content_']");
function initTinyMce(container) {
let textarea = $(container).find("textarea[name^='content_']");
/* TinyMCE seems to do its own check to prevent double-initialization
so We don't need to keep track of it */
let editor = tinyMCE.init({
branding : false,
block_unsupported_drop : false,
content_css : `${interface}/${theme}/css/tinymce.css`,
convert_urls : false,
custom_elements:"style,link,~link",
extended_valid_elements:"style,link[href|rel]",
force_br_newlines : false,
force_p_newlines : false,
forced_root_block : '',
menubar : "file edit view insert format tools table",
plugins : "autoresize table hr link image charmap lists code emoticons",
branding: false,
block_unsupported_drop: false,
content_css: `${interface}/${theme}/css/tinymce.css`,
convert_urls: false,
custom_elements: "style,link,~link",
extended_valid_elements: "style,link[href|rel]",
force_br_newlines: false,
force_p_newlines: false,
forced_root_block: "",
menubar: "file edit view insert format tools table",
plugins: "autoresize table hr link image charmap lists code emoticons",
autoresize_bottom_margin: 60,
relative_urls : false,
relative_urls: false,
selector: "#" + textarea[0].id,
verify_html: false,
toolbar : [
toolbar: [
"formatselect | bold italic | cut copy paste | alignleft aligncenter alignright | outdent indent | image link unlink anchor cleanup hr",
"table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code"
"table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code",
],
});
return editor;

View File

@ -272,27 +272,27 @@
var xhr;
var PROFILE_SAVE_MSG = _("Profile saved");
var PROFILE_DEL_MSG = _("Profile deleted");
$(document).ready(function(){
$(document).ready(function () {
$("#processfile").hide();
$('#profile_fieldset').hide();
$("#record_type").change(function() {
if ($(this).val() == 'auth') {
$('#items').hide();
$("#profile_fieldset").hide();
$("#record_type").change(function () {
if ($(this).val() == "auth") {
$("#items").hide();
} else {
$('#items').show();
$("#items").show();
}
});
$("#fileuploadbutton").on("click",function(e){
$("#fileuploadbutton").on("click", function (e) {
e.preventDefault();
StartUpload();
});
$("#fileuploadcancel").on("click",function(e){
$("#fileuploadcancel").on("click", function (e) {
e.preventDefault();
CancelUpload();
});
$("#mainformsubmit").on("click",function(e){
$("#mainformsubmit").on("click", function (e) {
e.preventDefault();
if ($("#fileToUpload").value == '') {
if ($("#fileToUpload").value == "") {
alert(_("Please upload a file first."));
return false;
} else {
@ -302,27 +302,27 @@
});
getProfiles();
$('#profile').change(function(){
if(this.value=='') {
$("#mod_profile, #del_profile").prop("disabled",true);
$("#profile").change(function () {
if (this.value == "") {
$("#mod_profile, #del_profile").prop("disabled", true);
$("#profile_id").val("");
$("#comments").val("");
$("#record_type").val('biblio').change();
$("#encoding").val('UTF-8').change();
$("#format").val('ISO2709').change();
$("#record_type").val("biblio").change();
$("#encoding").val("UTF-8").change();
$("#format").val("ISO2709").change();
$("#marc_modification_template_id").val("").change();
$("#matcher").val("").change();
$("#overlay_action").val('replace').change();
$("#nomatch_action").val('create_new').change();
$("#overlay_action").val("replace").change();
$("#nomatch_action").val("create_new").change();
$("#parse_itemsyes").prop("checked", true).change();
$("#item_action").val('always_add').change();
$("#profile_name").val('').keyup();
$("#del_profile span").text( _("Remove profile") );
$("#item_action").val("always_add").change();
$("#profile_name").val("").keyup();
$("#del_profile span").text(_("Remove profile"));
} else {
const profile = $('option:selected', this).data('profile');
const profile = $("option:selected", this).data("profile");
$("#profile_id").val(profile.profile_id);
$("#mod_profile, #del_profile").prop("disabled", null);
$("#del_profile span").text( _("Remove profile") + ": " + profile.name );
$("#del_profile span").text(_("Remove profile") + ": " + profile.name);
$("#comments").val(profile.comments);
$("#record_type").val(profile.record_type).change();
$("#encoding").val(profile.encoding).change();
@ -331,40 +331,41 @@
$("#matcher").val(profile.matcher_id).change();
$("#overlay_action").val(profile.overlay_action).change();
$("#nomatch_action").val(profile.nomatch_action).change();
$("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
$("input[name='parse_items'][value='" + (profile.parse_items ? "1" : "0") + "']")
.prop("checked", true)
.change();
$("#item_action").val(profile.item_action).change();
$("#profile_name").val(profile.name).keyup();
}
});
$("#profile_name").on("change keyup", function(){
$("#add_profile").prop("disabled", this.value.trim()=='');
$("#profile_name").on("change keyup", function () {
$("#add_profile").prop("disabled", this.value.trim() == "");
});
$("#add_profile").click(function(event) {
$("#add_profile").click(function (event) {
event.preventDefault();
var name = $("#profile_name").val().trim();
if(!name) {
if (!name) {
alert(_("Profile must have a name"));
return;
}
var profile = $("#profile option[value!='']")
.map(function() {
return $(this).data('profile');
.map(function () {
return $(this).data("profile");
})
.filter(function() {
.filter(function () {
return this.name == name;
});
if(profile.length) {
if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values?"))) {
if (profile.length) {
if (!confirm(_("There is another profile with this name.") + "\n\n" + _("Do you want to update it with new values?"))) {
return;
}
}
new Promise(function(resolve, reject) {
new Promise(function (resolve, reject) {
const params = {
comments: $("#comments").val() || null,
record_type: $("#record_type").val() || null,
@ -376,149 +377,152 @@
nomatch_action: $("#nomatch_action").val() || null,
parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
item_action: $("#item_action").val() || null,
name: name
name: name,
};
if(profile.length) {
if (profile.length) {
$.ajax({
url: "/api/v1/import_batch_profiles/"+profile[0].profile_id,
url: "/api/v1/import_batch_profiles/" + profile[0].profile_id,
method: "PUT",
data: JSON.stringify(params),
contentType: 'application/json'
contentType: "application/json",
})
.done(resolve)
.fail(reject);
.done(resolve)
.fail(reject);
} else {
$.ajax({
url: "/api/v1/import_batch_profiles/",
method: "POST",
data: JSON.stringify(params),
contentType: 'application/json'
contentType: "application/json",
})
.done(resolve)
.fail(reject);
.done(resolve)
.fail(reject);
}
})
.then(function(profile) {
humanMsg.displayAlert(PROFILE_SAVE_MSG);
return getProfiles(profile.profile_id);
})
.catch(function(error) {
alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
})
.then(function (profile) {
humanMsg.displayAlert(PROFILE_SAVE_MSG);
return getProfiles(profile.profile_id);
})
.catch(function (error) {
alert(_("An error occurred") + "\n\n" + ((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
});
});
$("#del_profile").click(function(event) {
$("#del_profile").click(function (event) {
event.preventDefault();
var id = $("#profile").val();
if(!id) return;
if(!confirm(_("Are you sure you want to delete this profile?"))) {
if (!id) return;
if (!confirm(_("Are you sure you want to delete this profile?"))) {
return;
}
new Promise(function(resolve, reject) {
new Promise(function (resolve, reject) {
$.ajax({
url: "/api/v1/import_batch_profiles/"+id,
method: "DELETE"
url: "/api/v1/import_batch_profiles/" + id,
method: "DELETE",
})
.done(resolve)
.fail(reject);
})
.then(function() {
humanMsg.displayAlert(PROFILE_DEL_MSG);
return getProfiles();
})
.catch(function(error) {
alert(_("An error occurred")+"\n\n"+((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
.done(resolve)
.fail(reject);
})
.then(function () {
humanMsg.displayAlert(PROFILE_DEL_MSG);
return getProfiles();
})
.catch(function (error) {
alert(_("An error occurred") + "\n\n" + ((error.responseJSON && error.responseJSON.error) || error.responseText || error.statusText));
});
});
if (job_enqueued){
if (job_enqueued) {
updateProgress(job_id, {
finish_callback : function(){
$.getJSON(`/api/v1/jobs/${job_id}`, function(job){
finish_callback: function () {
$.getJSON(`/api/v1/jobs/${job_id}`, function (job) {
let import_batch_id = job.data.report.import_batch_id;
$('<p><a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=%s">%s</a></p>'.format(import_batch_id, _("View batch"))).appendTo("#job_callback");
let basket_id = job.data.report.basket_id;
let vendor_id = job.data.report.vendor_id;
if ( basket_id && vendor_id ) {
$('<p><a id="addtobasket" class="btn btn-default" href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=%s&basketno=%s&booksellerid=%s">%s</a></p>'.format(import_batch_id, basket_id, vendor_id, _("Add staged files to basket"))).appendTo("#job_callback");
if (basket_id && vendor_id) {
$(
'<p><a id="addtobasket" class="btn btn-default" href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=%s&basketno=%s&booksellerid=%s">%s</a></p>'.format(
import_batch_id,
basket_id,
vendor_id,
_("Add staged files to basket")
)
).appendTo("#job_callback");
}
});
}
},
});
}
});
function StartUpload() {
if( $('#fileToUpload').prop('files').length == 0 ) return;
$('#fileuploadbutton').hide();
if ($("#fileToUpload").prop("files").length == 0) return;
$("#fileuploadbutton").hide();
$("#fileuploadfailed").hide();
$("#processfile").hide();
$('#profile_fieldset').hide();
$("#profile_fieldset").hide();
$("#fileuploadstatus").show();
$("#uploadedfileid").val('');
xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
$("#uploadedfileid").val("");
xhr = AjaxUpload($("#fileToUpload"), $("#fileuploadprogress"), "temp=1", cbUpload);
$("#fileuploadcancel").show();
}
function CancelUpload() {
if( xhr ) xhr.abort();
if (xhr) xhr.abort();
$("#fileuploadstatus").hide();
$('#fileuploadbutton').show();
$("#fileuploadbutton").show();
$("#fileuploadcancel").hide();
$("#fileuploadfailed").show();
$("#fileuploadfailed").text( _("Upload status: Cancelled ") );
$("#fileuploadfailed").text(_("Upload status: Cancelled "));
}
function cbUpload( status, fileid, errors ) {
if( status=='done' ) {
$("#uploadedfileid").val( fileid );
$('#fileToUpload').prop('disabled',true);
$('#fileuploadbutton').prop('disabled',true);
$('#fileuploadbutton').show();
function cbUpload(status, fileid, errors) {
if (status == "done") {
$("#uploadedfileid").val(fileid);
$("#fileToUpload").prop("disabled", true);
$("#fileuploadbutton").prop("disabled", true);
$("#fileuploadbutton").show();
$("#fileuploadcancel").hide();
var filename=$('#fileToUpload').prop('files')[0].name;
if( filename.match( new RegExp(/[^.]+\.xml$/) ) ) {
$('#format').val('MARCXML');
var filename = $("#fileToUpload").prop("files")[0].name;
if (filename.match(new RegExp(/[^.]+\.xml$/))) {
$("#format").val("MARCXML");
}
$("#processfile").show();
$('#profile_fieldset').show();
$("#profile_fieldset").show();
} else {
var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ];
var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
$('#fileuploadbutton').show();
var errMsgs = [_("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined")];
var errCode = errors[$("#fileToUpload").prop("files")[0].name].code;
$("#fileuploadbutton").show();
$("#fileuploadcancel").hide();
$("#fileuploadstatus").hide();
$("#fileuploadfailed").show();
$("#fileuploadfailed").text( _("Upload status: ") +
( status=='failed'? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode]:
( status=='denied'? _("Denied"): status ))
);
$("#fileuploadfailed").text(_("Upload status: ") + (status == "failed" ? _("Failed") + " - (" + errCode + ") " + errMsgs[errCode] : status == "denied" ? _("Denied") : status));
}
}
function getProfiles(id) {
const select = $("#profile");
$("option[value!='']", select).remove();
return new Promise(function(resolve, reject) {
$.ajax("/api/v1/import_batch_profiles")
.then(resolve, reject);
return new Promise(function (resolve, reject) {
$.ajax("/api/v1/import_batch_profiles").then(resolve, reject);
})
.then(function(profiles) {
profiles.sort( function(a, b) {
return a.name.localeCompare(b.name);
.then(function (profiles) {
profiles.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
profiles.forEach(function (profile) {
const opt = $("<option/>");
select.append(opt);
if (id && profile.profile_id == id) {
opt.prop("selected", true);
}
opt.attr("value", profile.profile_id);
opt.text(profile.name);
opt.data("profile", profile);
});
})
.then(function () {
select.change();
});
profiles.forEach(function(profile) {
const opt = $("<option/>");
select.append(opt);
if(id && profile.profile_id == id) {
opt.prop('selected', true);
}
opt.attr("value", profile.profile_id);
opt.text(profile.name);
opt.data("profile", profile);
});
})
.then(function(){
select.change();
});
}
</script>
[% END %]