issue #2164 optimize batchmanager JS

Added more verification to saveChanges Ajax call
optimized batchManagerFilter.js variables
This commit is contained in:
marsooooo 2024-09-05 11:37:39 +02:00
parent a8a5e515a2
commit 3d36978f84
2 changed files with 33 additions and 23 deletions

View file

@ -36,20 +36,20 @@ $(document).ready(function () {
$(".removeFilter").addClass("icon-cancel-circled");
$(".removeFilter").click(function () {
var filter = $(this).parent('li').attr("id");
const filter = $(this).parent('li').attr("id");
filter_disable(filter);
return false;
});
$("#addFilter a").on('click', function () {
var filter = $(this).attr("data-value");
const filter = $(this).attr("data-value");
filter_enable(filter);
});
$("#removeFilters").click(function() {
$("#filterList li").each(function() {
var filter = $(this).attr("id");
const filter = $(this).attr("id");
filter_disable(filter);
});
return false;
@ -66,4 +66,5 @@ $(document).ready(function () {
$('.addFilter-dropdown').slideUp();
}
});
})
})

View file

@ -109,7 +109,7 @@ $(document).ready(function() {
text: str_yes,
btnClass: 'btn-red',
action: function() {
const image_ids = [pictureId];
let image_ids = [pictureId];
(function(ids) {
$.ajax({
type: 'POST',
@ -358,6 +358,7 @@ function saveChanges(pictureId) {
$.ajax({
url: 'ws.php?format=json',
method: 'POST',
dataType: 'json',
data: {
method: 'pwg.images.setInfo',
image_id: pictureId,
@ -372,13 +373,28 @@ function saveChanges(pictureId) {
multiple_value_mode: "replace",
pwg_token: jQuery("input[name=pwg_token]").val()
},
success: function(response) {
enableLocalButton(pictureId);
enableGlobalButton();
hideUnsavedLocalBadge(pictureId);
showSuccessLocalBadge(pictureId);
updateSuccessGlobalBadge();
// pluginSaveLoop(activePlugins); //call for plugin save
success: function(data) {
const isOk = data.stat && data.stat === 'ok';
if (isOk) {
console.log("Data saved successfully for picture " + pictureId);
enableLocalButton(pictureId);
enableGlobalButton();
hideUnsavedLocalBadge(pictureId);
showSuccessLocalBadge(pictureId);
updateSuccessGlobalBadge();
// Call for extension's save
// This is the first method we're implementing to validate extension's data
// More informations will be provided on next skeleton update
pluginSaveLoop(activePlugins, pictureId);
}
else {
console.error("Error: " + data);
enableLocalButton(pictureId);
enableGlobalButton();
hideUnsavedLocalBadge(pictureId);
showErrorLocalBadge(pictureId);
updateSuccessGlobalBadge();
}
},
error: function(xhr, status, error) {
enableLocalButton(pictureId);
@ -389,7 +405,7 @@ function saveChanges(pictureId) {
console.error('Error:', error);
}
});
} else {}
}
}
function saveAllChanges() {
@ -407,26 +423,19 @@ function pluginFunctionMapInit(activePlugins) {
if (typeof window[functionName] === 'function') {
pluginFunctionMap[pluginId] = window[functionName];
}
// else {
// console.log('Function not found during initialization: ' + functionName);
// }
});
}
function pluginSaveLoop(activePlugins) {
function pluginSaveLoop(activePlugins, pictureId) {
if (activePlugins.length === 0) {
// console.log("No plugins to process in pluginSaveLoop.");
return;
}
activePlugins.forEach(function(pluginId) {
const saveFunction = pluginFunctionMap[pluginId];
if (typeof saveFunction === 'function') {
saveFunction();
// console.log('Executed function for plugin: ' + pluginId);
saveFunction(pictureId);
}
// else {
// console.log('Function not found for plugin: ' + pluginId);
// }
});
}
//UPDATE BLOCKS (Yet to be implemented)