omlink.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Main Javascript file
  3. *
  4. * @author Open Mind
  5. * @date 27/06/2018
  6. * @time 17:42
  7. */
  8. function NotificationBuilder(notifications) {
  9. let tplNotify = '';
  10. let htmlNotificationArea = '';
  11. if (notifications.length == 0) {
  12. $('#notification_area_button').addClass('disabled');
  13. $('#sysmsgnum').empty();
  14. } else {
  15. notifications.forEach(function (element) {
  16. tplNotify += `<a class="dropdown-item" href="javascript:NotificationDelete('${element.link}', ${element.code})">${element.caption}<span class="ml-1 badge badge-danger">${element.count}</span></a>`;
  17. });
  18. htmlNotificationArea = `
  19. ${tplNotify}
  20. <a id="notification_area_deleteall" class="dropdown-item text-center" href="javascript:NotificationDelete('#', 0)" >Cancella tutto</a>
  21. `;
  22. $('#notification_area_button').removeClass('disabled');
  23. $('#sysmsgnum').html(notifications.length);
  24. }
  25. $('#notification_area').html(htmlNotificationArea);
  26. }
  27. function refreshNotificationArea() {
  28. fetch('/omlink/api.system.getserverstatus')
  29. .then(resp => {
  30. if (resp.status == 200)
  31. return resp.json();
  32. else
  33. return Promise.reject("getserverstatus: error");
  34. })
  35. .then(data => {
  36. NotificationBuilder(data.notify);
  37. })
  38. .catch(err => {
  39. console.log(err);
  40. });
  41. }
  42. function NotificationDelete(link, code) {
  43. fetch(`/omlink/api.system.removenotification/${code}`, {method: "POST"})
  44. .then(() => {
  45. window.location.href = `${BASEURL}${link}`;
  46. })
  47. .catch(() => {
  48. alert('NotificationDelete error');
  49. });
  50. }
  51. $(function () {
  52. refreshNotificationArea();
  53. $('form').on('submit', function () {
  54. $('form input,select').prop('disabled', false);
  55. setTimeout(function () {
  56. $('form input,select').prop('disabled', true);
  57. }, 500);
  58. });
  59. setInterval(() => {
  60. refreshNotificationArea();
  61. }, 5000);
  62. });