Prototypization of NotificationController

This commit is contained in:
Vince 2012-09-16 14:41:47 +02:00
parent 6d0b2eb9e2
commit 362d8ef262
2 changed files with 39 additions and 37 deletions

View File

@ -1,39 +1,39 @@
/*
* @provide pskl.NotificationService
*
*/
$.namespace("pskl");
(function () {
var ns = $.namespace("pskl.controller");
pskl.NotificationService = (function() {
ns.NotificationController = function () {};
/**
* @private
*/
var displayMessage_ = function (evt, messageInfo) {
var message = document.createElement('div');
message.id = "user-message";
message.className = "user-message";
message.innerHTML = messageInfo.content;
message.innerHTML = message.innerHTML + "<div title='Close message' class='close'>x</div>";
document.body.appendChild(message);
$(message).find(".close").click(removeMessage_);
if(messageInfo.behavior) messageInfo.behavior(message);
};
/**
* @private
*/
ns.NotificationController.prototype.displayMessage_ = function (evt, messageInfo) {
var message = document.createElement('div');
message.id = "user-message";
message.className = "user-message";
message.innerHTML = messageInfo.content;
message.innerHTML = message.innerHTML + "<div title='Close message' class='close'>x</div>";
document.body.appendChild(message);
$(message).find(".close").click($.proxy(this.removeMessage_, this));
if(messageInfo.behavior) {
messageInfo.behavior(message);
}
};
/**
* @private
*/
var removeMessage_ = function (evt) {
var message = $("#user-message");
if (message.length) {
message.remove();
}
};
/**
* @private
*/
ns.NotificationController.prototype.removeMessage_ = function (evt) {
var message = $("#user-message");
if (message.length) {
message.remove();
}
};
return {
init: function() {
$.subscribe(Events.SHOW_NOTIFICATION, displayMessage_);
$.subscribe(Events.HIDE_NOTIFICATION, removeMessage_);
}
};
/**
* @public
*/
ns.NotificationController.prototype.init = function() {
$.subscribe(Events.SHOW_NOTIFICATION, $.proxy(this.displayMessage_, this));
$.subscribe(Events.HIDE_NOTIFICATION, $.proxy(this.removeMessage_, this));
};
})();

View File

@ -69,10 +69,12 @@ $.namespace("pskl");
this.historyService = new pskl.service.HistoryService(frameSheet);
this.historyService.init();
this.KeyboardEventService = new pskl.service.KeyboardEventService();
this.KeyboardEventService.init();
this.keyboardEventService = new pskl.service.KeyboardEventService();
this.keyboardEventService.init();
this.notificationController = new pskl.controller.NotificationController();
this.notificationController.init();
pskl.NotificationService.init();
this.localStorageService = new pskl.service.LocalStorageService(frameSheet);
this.localStorageService.init();