2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-07-25 02:02:35 +02:00
|
|
|
const _ = require("lodash");
|
2017-04-03 16:13:25 +02:00
|
|
|
/* Arguments used in the report_* functions are,
|
|
|
|
response- response that we want to display
|
|
|
|
status_box- element being used to display the response
|
|
|
|
cls- class that we want to add/remove to/from the status_box
|
2018-01-03 14:24:49 +01:00
|
|
|
*/
|
2017-04-03 16:13:25 +02:00
|
|
|
|
2019-01-17 13:34:56 +01:00
|
|
|
exports.message = function (response, status_box, cls, remove_after) {
|
2017-04-03 16:13:25 +02:00
|
|
|
if (cls === undefined) {
|
2020-07-15 01:29:15 +02:00
|
|
|
cls = "alert";
|
2017-04-03 16:13:25 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 21:55:19 +01:00
|
|
|
// Note we use html() below, since we can rely on our callers escaping HTML
|
|
|
|
// via i18n.t when interpolating data.
|
2020-07-15 00:34:28 +02:00
|
|
|
status_box
|
|
|
|
.removeClass(common.status_classes)
|
|
|
|
.addClass(cls)
|
|
|
|
.html(response)
|
|
|
|
.stop(true)
|
|
|
|
.fadeTo(0, 1);
|
2018-03-30 02:22:33 +02:00
|
|
|
if (remove_after) {
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2020-07-10 16:43:51 +02:00
|
|
|
status_box.fadeOut(400);
|
2018-03-30 02:22:33 +02:00
|
|
|
}, remove_after);
|
|
|
|
}
|
2017-03-23 20:37:08 +01:00
|
|
|
status_box.addClass("show");
|
2017-04-03 16:13:25 +02:00
|
|
|
};
|
|
|
|
|
2020-07-10 16:43:51 +02:00
|
|
|
exports.error = function (response, xhr, status_box, remove_after) {
|
2017-04-03 16:13:25 +02:00
|
|
|
if (xhr && xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
2019-12-13 01:41:59 +01:00
|
|
|
const server_response = _.escape(JSON.parse(xhr.responseText).msg);
|
2018-12-18 21:33:29 +01:00
|
|
|
if (response) {
|
|
|
|
response += ": " + server_response;
|
|
|
|
} else {
|
|
|
|
response = server_response;
|
|
|
|
}
|
2017-04-03 16:13:25 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
exports.message(response, status_box, "alert-error", remove_after);
|
2017-04-03 16:13:25 +02:00
|
|
|
};
|
|
|
|
|
2019-01-17 13:34:56 +01:00
|
|
|
exports.success = function (response, status_box, remove_after) {
|
2020-07-15 01:29:15 +02:00
|
|
|
exports.message(response, status_box, "alert-success", remove_after);
|
2017-04-03 16:13:25 +02:00
|
|
|
};
|
|
|
|
|
2017-09-16 01:16:42 +02:00
|
|
|
exports.generic_embed_error = function (error) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $alert = $("<div class='alert home-error-bar'></div>");
|
|
|
|
const $exit = "<div class='exit'></div>";
|
2017-09-16 01:16:42 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$(".alert-box").append(
|
|
|
|
$alert.html($exit + "<div class='content'>" + error + "</div>").addClass("show"),
|
|
|
|
);
|
2017-09-16 01:16:42 +02:00
|
|
|
};
|
|
|
|
|
2018-03-25 11:12:06 +02:00
|
|
|
exports.generic_row_button_error = function (xhr, btn) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
btn.closest("td").html(
|
2020-07-02 02:16:03 +02:00
|
|
|
$("<p>").addClass("text-error").text(JSON.parse(xhr.responseText).msg),
|
2018-03-25 11:12:06 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
btn.text(i18n.t("Failed!"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-23 20:37:08 +01:00
|
|
|
exports.hide_error = function ($target) {
|
|
|
|
$target.addClass("fade-out");
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2017-03-23 20:37:08 +01:00
|
|
|
$target.removeClass("show fade-out");
|
|
|
|
}, 300);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.show_error = function ($target) {
|
|
|
|
$target.addClass("show");
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.ui_report = exports;
|