// 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) { return setMsg('notificationRetreiveFailed', 'warning'); }; toggle = function(button, notif, epoch) { setMsg(msg, 'positive'); $(".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) { $("#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'); button.removeClass('btn-success'); button.addClass('btn-danger'); return $("#myNotification").removeAttr('hidden'); } else { return $("#myNotification").attr('hidden', 'true'); } }; 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, notif, epoch); $('#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)); }); }); }).call(this);