From cef457bbc84ea303973018a1996d286c2c8effab Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 15 Nov 2010 06:34:42 +0100 Subject: [PATCH] Add methods to retrieve new notification and create their HTML. --- src/main/resources/static/javascript/sone.js | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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; +} -- 2.7.4