cqrs-example-0.9.0: static/js/app/notifications.js
/*global EventSource:false,define:false */
/*jslint browser: true */
define(["jquery", "toastr", "app/services"], function ($, toastr, services) {
"use strict";
var exports = { };
// Provide a function for starting up notifications.
exports.startNotifications = function (reload) {
// Set up notification listener.
services.onNotification(function (data) {
var do_reload = false;
// React
console.log("Received notifications: ", data);
$.each(data, function (i, e) {
if (e.type === "added-task") {
toastr.success("Added task '" + e.title + "'");
do_reload = true;
} else if (e.type === "archived-tasks") {
toastr.success("Archived " + e.numberOfTasks + " tasks");
do_reload = true;
} else if (e.type === "refresh") {
do_reload = true;
} else {
console.log("Notification type not supported: ", e.type);
}
});
// Reload?
if (do_reload) {
reload();
}
});
};
return exports;
});