| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**
- * Main Javascript file
- *
- * @author Open Mind
- * @date 27/06/2018
- * @time 17:42
- */
- function NotificationBuilder(notifications) {
- let tplNotify = '';
- let htmlNotificationArea = '';
- if (notifications.length == 0) {
- $('#notification_area_button').addClass('disabled');
- $('#sysmsgnum').empty();
- } else {
- notifications.forEach(function (element) {
- tplNotify += `<a class="dropdown-item" href="javascript:NotificationDelete('${element.link}', ${element.code})">[${element.timestamp}] ${element.caption}<span class="ml-1 badge badge-danger">${element.count}</span></a>`;
- });
- htmlNotificationArea = `
- ${tplNotify}
- <a id="notification_area_deleteall" class="dropdown-item text-center" href="javascript:NotificationDelete('#', 0)" >Cancella tutto</a>
- `;
- $('#notification_area_button').removeClass('disabled');
- $('#sysmsgnum').html(notifications.length);
- }
- $('#notification_area').html(htmlNotificationArea);
- }
- function refreshNotificationArea() {
- fetch('/omlink/api.system.getserverstatus')
- .then(resp => {
- if (resp.status == 200)
- return resp.json();
- else
- return Promise.reject("getserverstatus: error");
- })
- .then(data => {
- NotificationBuilder(data.notify);
- })
- .catch(err => {
- console.log(err);
- });
- }
- function NotificationDelete(link, code) {
- fetch(`/omlink/api.system.removenotification/${code}`, {method: "POST"})
- .then(() => {
- if (link != '#')
- window.location.href = `${BASEURL}${link}`;
- })
- .catch(() => {
- alert('NotificationDelete error');
- });
- }
- function SetupConfirmationDialog() {
- $('.requestconfirm').on('click', function (ev) {
- let confirmText = $(this).data('confirmtext');
- if (!confirm(confirmText))
- ev.preventDefault();
- });
- }
- $(function () {
- SetupConfirmationDialog();
- refreshNotificationArea();
- $('form').on('submit', function () {
- $('form input,select').prop('disabled', false);
- setTimeout(function () {
- $('form input,select').prop('disabled', true);
- }, 500);
- });
- setInterval(() => {
- refreshNotificationArea();
- }, 10000);
- });
|