X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=20386f7d67b2a138da3554968e2fa287b9e1218a;hb=5867507cdc8c401b17d2a4118197887de9d53c20;hp=75fa965184c907e5cf63393c80c7dee3f925e6cc;hpb=5ac2eeb4296b651f380e2d35ad35cf4bfc70c766;p=Sone.git
diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js
index 75fa965..20386f7 100644
--- a/src/main/resources/static/javascript/sone.js
+++ b/src/main/resources/static/javascript/sone.js
@@ -420,9 +420,55 @@ function ajaxifyNotification(notification) {
});
notification.find("form.dismiss button").click(function() {
$.getJSON("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
- if (data.success) {
- notification.slideUp();
- }
+ notification.slideUp();
});
});
+ 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();
+ });
+ $.each(data.removedNotifications, function(index, value) {
+ $("#sone #notification-area .notification#" + value.id).slideUp();
+ });
+ }
+ 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 = $("