lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/notifications.js

129 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-10-09 22:29:56 +02:00
// Generated by CoffeeScript 1.12.8
2020-02-09 17:47:25 +01:00
/*
LemonLDAP::NG Notifications script
*/
(function() {
2020-02-14 16:53:42 +01:00
var displayError, msg, setMsg, toggle, toggle_explorer, toggle_eye, viewNotif;
2020-02-09 23:04:48 +01:00
msg = $('#msg').attr('trspan');
2020-02-09 17:47:25 +01:00
setMsg = function(msg, level) {
$('#msg').html(window.translate(msg));
$('#color').removeClass('message-positive message-warning alert-success alert-warning');
$('#color').addClass("message-" + level);
if (level === 'positive') {
level = 'success';
}
return $('#color').addClass("alert-" + level);
};
displayError = function(j, status, err) {
2020-03-03 19:52:42 +01:00
setMsg('notificationRetrieveFailed', 'warning');
return console.log('Error:', err, 'Status:', status);
2020-02-09 17:47:25 +01:00
};
2020-02-14 16:53:42 +01:00
toggle_eye = function(slash) {
if (slash) {
$("#icon-explorer-button").removeClass('fa-eye');
return $("#icon-explorer-button").addClass('fa-eye-slash');
} else {
$("#icon-explorer-button").removeClass('fa-eye-slash');
return $("#icon-explorer-button").addClass('fa-eye');
}
};
toggle_explorer = function(visible) {
if (visible) {
$('#explorer').hide();
$('#color').hide();
return toggle_eye(0);
} else {
$('#explorer').show();
$('#color').show();
return toggle_eye(1);
}
};
2020-02-10 10:58:48 +01:00
toggle = function(button, notif, epoch) {
2020-02-09 23:04:48 +01:00
setMsg(msg, 'positive');
2020-02-10 10:58:48 +01:00
$(".btn-danger").each(function() {
$(this).removeClass('btn-danger');
return $(this).addClass('btn-success');
});
$(".fa-eye-slash").each(function() {
$(this).removeClass('fa-eye-slash');
return $(this).addClass('fa-eye');
});
$(".verify").each(function() {
$(this).text(window.translate('verify'));
return $(this).attr('trspan', 'verify');
});
if (notif && epoch) {
2020-02-14 16:53:42 +01:00
button.removeClass('btn-success');
button.addClass('btn-danger');
2020-02-10 10:58:48 +01:00
$("#icon-" + notif + "-" + epoch).removeClass('fa-eye');
$("#icon-" + notif + "-" + epoch).addClass('fa-eye-slash');
$("#text-" + notif + "-" + epoch).text(window.translate('hide'));
$("#text-" + notif + "-" + epoch).attr('trspan', 'hide');
2020-02-14 16:53:42 +01:00
$("#myNotification").removeAttr('hidden');
return toggle_eye(1);
2020-02-10 10:58:48 +01:00
} else {
$("#myNotification").attr('hidden', 'true');
return $("#explorer-button").attr('hidden', 'true');
2020-02-09 18:40:43 +01:00
}
};
viewNotif = function(notif, epoch, button) {
2020-02-09 17:47:25 +01:00
console.log('Ref:', notif, 'epoch:', epoch);
if (notif && epoch) {
console.log('Send AJAX request');
return $.ajax({
type: "GET",
2020-02-09 18:40:43 +01:00
url: portal + "mynotifications/" + notif,
2020-02-09 17:47:25 +01:00
data: {
epoch: epoch
},
dataType: 'json',
2020-02-09 18:40:43 +01:00
error: displayError,
2020-02-09 17:47:25 +01:00
success: function(resp) {
var myDate;
if (resp.result) {
console.log('Notification:', resp.notification);
2020-02-10 10:58:48 +01:00
toggle(button, notif, epoch);
2020-02-09 17:47:25 +01:00
$('#displayNotif').html(resp.notification);
$('#notifRef').text(notif);
myDate = new Date(epoch * 1000);
$('#notifEpoch').text(myDate.toLocaleString());
return $("#explorer-button").removeAttr('hidden');
2020-02-09 17:47:25 +01:00
} else {
2020-02-09 18:22:34 +01:00
return setMsg('notificationNotFound', 'warning');
2020-02-09 17:47:25 +01:00
}
}
});
} else {
2020-03-03 19:52:42 +01:00
return setMsg('notificationRetrieveFailed', 'warning');
2020-02-09 17:47:25 +01:00
}
};
$(document).ready(function() {
2020-02-09 18:40:43 +01:00
$(".data-epoch").each(function() {
2020-02-09 17:47:25 +01:00
var myDate;
myDate = new Date($(this).text() * 1000);
return $(this).text(myDate.toLocaleString());
});
2020-02-09 18:40:43 +01:00
$('#goback').attr('href', portal);
$('body').on('click', '.btn-success', function() {
return viewNotif($(this).attr('notif'), $(this).attr('epoch'), $(this));
});
$('body').on('click', '.btn-danger', function() {
2020-02-10 10:58:48 +01:00
return toggle($(this));
2020-02-09 18:40:43 +01:00
});
return $('body').on('click', '.btn-info', function() {
2020-02-14 16:53:42 +01:00
return toggle_explorer($('#explorer').is(':visible'));
});
2020-02-09 17:47:25 +01:00
});
}).call(this);