pandorafms/pandora_console/include/javascript/tipsWindow.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-02-13 10:06:14 +01:00
/* globals $, idTips, totalTips, idTips, url, page */
$(".carousel").ready(function() {
function render({ title, text, url, files }) {
$("#title_tip").html(title);
$("#text_tip").html(text);
$("#url_tip").attr("href", url);
$(".carousel .images").empty();
if (files) {
files.forEach(file => {
$(".carousel .images").append(`<img src="${file.filename}" />`);
});
$(".carousel").removeClass("invisible");
} else {
$(".carousel").addClass("invisible");
}
}
$("#next_tip").on("click", function() {
if (idTips.length >= totalTips) {
idTips = [];
}
$.ajax({
method: "POST",
url: url,
dataType: "json",
data: {
page: page,
method: "getRandomTip",
exclude: JSON.stringify(idTips)
},
success: function({ success, data }) {
if (success) {
idTips.push(parseInt(data.id));
render(data);
} else {
//TODO control error
}
}
});
});
});