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
|
|
|
|
2019-10-18 02:03:05 +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">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="toast-body">
|
|
|
|
${options.message}
|
|
|
|
</div>
|
|
|
|
</div>`);
|
|
|
|
|
|
|
|
$("#toast-container").append($toast);
|
|
|
|
|
|
|
|
$toast.toast({
|
|
|
|
delay: options.delay
|
|
|
|
}).toast("show");
|
|
|
|
}
|
|
|
|
|
2019-10-14 16:31:58 +08:00
|
|
|
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
|
|
|
|
2019-10-18 02:03:05 +08:00
|
|
|
toast({
|
|
|
|
title: "Info",
|
|
|
|
icon: "check",
|
|
|
|
message: message,
|
|
|
|
delay
|
|
|
|
});
|
2018-03-26 09:29:35 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 17:31:42 +08:00
|
|
|
function showAndLogError(message, delay = 10000) {
|
|
|
|
showError(message, delay);
|
|
|
|
|
2019-08-27 02:21:43 +08:00
|
|
|
ws.logError(message);
|
2018-08-17 17:31:42 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-10-18 02:03:05 +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,
|
2018-08-17 17:31:42 +08:00
|
|
|
showAndLogError,
|
2018-03-26 09:29:35 +08:00
|
|
|
throwError
|
|
|
|
}
|