From: David ‘Bombe’ Roden Date: Mon, 15 Nov 2010 05:34:42 +0000 (+0100) Subject: Add methods to retrieve new notification and create their HTML. X-Git-Tag: 0.3-RC1~48 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=cef457bbc84ea303973018a1996d286c2c8effab;p=Sone.git Add methods to retrieve new notification and create their HTML. --- diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 8c6db31..5c3415b 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -425,3 +425,47 @@ function ajaxifyNotification(notification) { }); return notification; } + +/** + * Retrieves all changed notifications. + */ +function getNotifications() { + $.getJSON("ajax/getNotifications.ajax", {}, function(data, textStatus) { + if (data.success) { + $.each(data.notifications, function(index, value) { + oldNotification = $("#sone #notification-area .notification#" + value.id); + notification = ajaxifyNotification(createNotification(value.id, value.text, value.dismissable)).hide(); + if (oldNotification.length != 0) { + oldNotification.slideUp(); + notification.insertBefore(oldNotification); + } else { + $("#sone #notification-area").append(notification); + } + notification.slideDown(); + }); + } + setTimeout(getNotifications, 5000); + }); +} + +/** + * Creates a new notification. + * + * @param id + * The ID of the notificaiton + * @param text + * The text of the notification + * @param dismissable + * true if the notification can be dismissed by the + * user + */ +function createNotification(id, text, dismissable) { + notification = $("
").addClass("notification").attr("id", id); + if (dismissable) { + dismissForm = $("#sone #notification-area #notification-dismiss-template").clone().removeClass("hidden").removeAttr("id") + dismissForm.find("input[name=notification]").val(id); + notification.append(dismissForm); + } + notification.append(text); + return notification; +}