trilium/src/public/javascripts/services/info.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-27 02:21:43 +08:00
import ws from "./ws.js";
2018-03-26 10:37:02 +08:00
import utils from "./utils.js";
2018-03-26 09:29:35 +08:00
function toast(options) {
const $toast = $(`<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="mr-auto"><span class="jam jam-${options.icon}"></span> ${options.title}</strong>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="toast-body">
${options.message}
</div>
</div>`);
$("#toast-container").append($toast);
$toast.toast({
delay: options.delay
}).toast("show");
}
function showMessage(message, delay = 3000) {
2018-10-30 15:53:30 +08:00
console.debug(utils.now(), "message: ", message);
2018-03-26 09:29:35 +08:00
toast({
title: "Info",
icon: "check",
message: message,
delay
});
2018-03-26 09:29:35 +08:00
}
function showAndLogError(message, delay = 10000) {
showError(message, delay);
2019-08-27 02:21:43 +08:00
ws.logError(message);
}
2018-03-26 09:29:35 +08:00
function showError(message, delay = 10000) {
2018-03-26 10:37:02 +08:00
console.log(utils.now(), "error: ", message);
2018-03-26 09:29:35 +08:00
toast({
title: "Error",
icon: 'alert',
message: message,
delay
});
2018-03-26 09:29:35 +08:00
}
function throwError(message) {
2019-08-27 02:21:43 +08:00
ws.logError(message);
2018-03-26 09:29:35 +08:00
throw new Error(message);
}
export default {
showMessage,
showError,
showAndLogError,
2018-03-26 09:29:35 +08:00
throwError
}