+ $("#sone .reply#" + replyId + " .status-line .likes > span").attr("title", generateSoneList(data.sones));
+ }
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
+ });
+}
+
+/**
+ * Posts a reply and calls the given callback when the request finishes.
+ *
+ * @param postId
+ * The ID of the post the reply refers to
+ * @param text
+ * The text to post
+ * @param callbackFunction
+ * The callback function to call when the request finishes (takes 3
+ * parameters: success, error, replyId)
+ */
+function postReply(postId, text, callbackFunction) {
+ $.getJSON("ajax/createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) {
+ if (data == null) {
+ /* TODO - show error */
+ return;
+ }
+ if (data.success) {
+ callbackFunction(true, null, data.reply);
+ } else {
+ callbackFunction(false, data.error);
+ }
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
+ });
+}
+
+/**
+ * Requests information about the reply with the given ID.
+ *
+ * @param replyId
+ * The ID of the reply
+ * @param callbackFunction
+ * A callback function (parameters soneId, soneName, replyTime,
+ * replyDisplayTime, text, html)
+ */
+function getReply(replyId, callbackFunction) {
+ $.getJSON("ajax/getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
+ if ((data != null) && data.success) {
+ callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html);
+ }
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
+ });
+}
+
+/**
+ * Ajaxifies the given notification by replacing the form with AJAX.
+ *
+ * @param notification
+ * jQuery object representing the notification.
+ */
+function ajaxifyNotification(notification) {
+ notification.find("form.dismiss").submit(function() {
+ return false;
+ });
+ notification.find("form.dismiss button").click(function() {
+ $.getJSON("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
+ /* dismiss in case of error, too. */
+ notification.slideUp();
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
+ });
+ });
+ return notification;
+}
+
+/**
+ * Retrieves all changed notifications.
+ */
+function getNotifications() {
+ $.getJSON("ajax/getNotifications.ajax", {}, function(data, textStatus) {
+ if ((data != null) && 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.replaceWith(notification.show());
+ } else {
+ $("#sone #notification-area").append(notification);
+ notification.slideDown();
+ }
+ });
+ $.each(data.removedNotifications, function(index, value) {
+ $("#sone #notification-area .notification#" + value.id).slideUp();
+ });
+ setTimeout(getNotifications, 5000);
+ } else {
+ setTimeout(getNotifications, 30000);