alerts.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. function initAlert(id, parameter) {
  2. switch (id) {
  3. case "shutdown":
  4. initShutdownAlert();
  5. break;
  6. case "access-denied":
  7. initSimpleAlert(".access-denied.alert");
  8. break;
  9. case "bad-alias":
  10. initSimpleAlert(".bad-alias.alert", parameter);
  11. break;
  12. default:
  13. break;
  14. }
  15. }
  16. function initShutdownAlert() {
  17. let $shutdownAlert = $(".shutdown.alert");
  18. $(".alert button").on("click", function () {
  19. let $this = $(this);
  20. let action = $this.attr("data-action");
  21. switch (action) {
  22. case "restart":
  23. Actions.restart();
  24. break;
  25. case "sleep":
  26. $shutdownAlert.remove();
  27. Actions.sleep();
  28. break;
  29. case "cancel":
  30. $shutdownAlert.remove();
  31. break;
  32. case "shutdown":
  33. Actions.shutdown();
  34. break;
  35. default:
  36. break;
  37. }
  38. $(".modal").hide();
  39. });
  40. }
  41. function initSimpleAlert(alertClass, textParameter) {
  42. let $alert = $(alertClass);
  43. if (textParameter) {
  44. let $alertText = $alert.find(".text");
  45. $alertText.html($alertText.html().replace("{0}", textParameter));
  46. }
  47. $(".alert button").on("click", function () {
  48. let $this = $(this);
  49. let action = $this.attr("data-action");
  50. if (action === "ok")
  51. $alert.remove();
  52. $(".modal").hide();
  53. });
  54. }