96 lines
2.7 KiB
JavaScript
96 lines
2.7 KiB
JavaScript
// Generated by CoffeeScript 1.12.7
|
|
|
|
/*
|
|
LemonLDAP::NG Notifications script
|
|
*/
|
|
|
|
(function() {
|
|
var displayError, msg, setMsg, toggle, viewNotif;
|
|
|
|
msg = $('#msg').attr('trspan');
|
|
|
|
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) {
|
|
var res;
|
|
console.log('Error', err);
|
|
res = JSON.parse(j.responseText);
|
|
if (res && res.error) {
|
|
console.log('Returned error', res);
|
|
return setMsg(res, 'warning');
|
|
}
|
|
};
|
|
|
|
toggle = function(button, verif) {
|
|
setMsg(msg, 'positive');
|
|
if (verif) {
|
|
$("#myNotification").attr('hidden', 'true');
|
|
button.removeClass('btn-danger');
|
|
return button.addClass('btn-success');
|
|
} else {
|
|
$("#myNotification").removeAttr('hidden');
|
|
$(".btn-danger").each(function() {
|
|
$(this).removeClass('btn-danger');
|
|
return $(this).addClass('btn-success');
|
|
});
|
|
button.removeClass('btn-success');
|
|
return button.addClass('btn-danger');
|
|
}
|
|
};
|
|
|
|
viewNotif = function(notif, epoch, button) {
|
|
console.log('Ref:', notif, 'epoch:', epoch);
|
|
if (notif && epoch) {
|
|
console.log('Send AJAX request');
|
|
return $.ajax({
|
|
type: "GET",
|
|
url: portal + "mynotifications/" + notif,
|
|
data: {
|
|
epoch: epoch
|
|
},
|
|
dataType: 'json',
|
|
error: displayError,
|
|
success: function(resp) {
|
|
var myDate;
|
|
if (resp.result) {
|
|
console.log('Notification:', resp.notification);
|
|
toggle(button, 0);
|
|
$('#displayNotif').html(resp.notification);
|
|
$('#notifRef').text(notif);
|
|
myDate = new Date(epoch * 1000);
|
|
return $('#notifEpoch').text(myDate.toLocaleString());
|
|
} else {
|
|
return setMsg('notificationNotFound', 'warning');
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
return setMsg('notificationRetreiveFailed', 'warning');
|
|
}
|
|
};
|
|
|
|
$(document).ready(function() {
|
|
$(".data-epoch").each(function() {
|
|
var myDate;
|
|
myDate = new Date($(this).text() * 1000);
|
|
return $(this).text(myDate.toLocaleString());
|
|
});
|
|
$('#goback').attr('href', portal);
|
|
$('body').on('click', '.btn-success', function() {
|
|
return viewNotif($(this).attr('notif'), $(this).attr('epoch'), $(this));
|
|
});
|
|
return $('body').on('click', '.btn-danger', function() {
|
|
return toggle($(this), 1);
|
|
});
|
|
});
|
|
|
|
}).call(this);
|