1 // TODO Rename those objects to TaskBar*
  2 
  3 /**
  4  * Creates a new StatusBarView.
  5  * 
  6  * @constructor
  7  */
  8 mindmaps.StatusBarView = function() {
  9 	var self = this;
 10 	var $statusbar = $("#statusbar");
 11 
 12 	this.init = function() {
 13 	};
 14 
 15 	/**
 16 	 * Creates and adds a new button to the stats baar.
 17 	 * 
 18 	 * @param {String} id
 19 	 * @param {String} text
 20 	 * @returns {jQuery}
 21 	 */
 22 	this.createButton = function(id, text) {
 23 		return $("<button/>", {
 24 			id : "statusbar-button-" + id
 25 		}).button({
 26 			label : text
 27 		}).click(function() {
 28 			if (self.buttonClicked) {
 29 				self.buttonClicked(id);
 30 			}
 31 		}).prependTo($statusbar.find(".buttons"));
 32 	};
 33 
 34 	/**
 35 	 * Returns the underlying jquery object.
 36 	 * 
 37 	 * @returns {jQuery}
 38 	 */
 39 	this.getContent = function() {
 40 		return $statusbar;
 41 	};
 42 };
 43 
 44 /**
 45  * Creates a new StatusBarPresenter. This object provides buttons for the
 46  * floating panels for a taskbar-like behaviour.
 47  * 
 48  * @constructor
 49  * @param {mindmaps.EventBus} eventBus
 50  * @param {mindmaps.StatusBarView} view
 51  */
 52 mindmaps.StatusBarPresenter = function(eventBus, view) {
 53 	var buttonCounter = 0;
 54 	var buttonIdPanelMap = {};
 55 	var statusController = new mindmaps.StatusNotificationController(eventBus,
 56 			view.getContent());
 57 
 58 	view.buttonClicked = function(id) {
 59 		buttonIdPanelMap[id].toggle();
 60 	};
 61 
 62 	this.go = function() {
 63 		view.init();
 64 
 65 	};
 66 
 67 	/**
 68 	 * Adds a new button for a panel to the statusbar and registers the button
 69 	 * as a hide target for the panel.
 70 	 * 
 71 	 * @param {mindmaps.FloatPanel} panel
 72 	 */
 73 	this.addEntry = function(panel) {
 74 		var id = buttonCounter++;
 75 		var $button = view.createButton(id, panel.caption);
 76 		panel.setHideTarget($button);
 77 		buttonIdPanelMap[id] = panel;
 78 	};
 79 };
 80 
 81 /**
 82  * This object subscribes to some events and displays status messages in the
 83  * bottom right corner.
 84  * 
 85  * @constructor
 86  * @param {mindmaps.EventBus} eventBus
 87  * @param {mindmaps.StatusBarView} view
 88  */
 89 mindmaps.StatusNotificationController = function(eventBus, view) {
 90 	var $anchor = $("<div class='notification-anchor'/>").css({
 91 		position : "absolute",
 92 		right : 20
 93 	}).appendTo(view);
 94 
 95 	eventBus.subscribe(mindmaps.Event.DOCUMENT_SAVED, function() {
 96 		var n = new mindmaps.Notification($anchor, {
 97 			position : "topRight",
 98 			expires : 2500,
 99 			content : "Mind map saved"
100 		});
101 	});
102 	
103 	eventBus.subscribe(mindmaps.Event.NOTIFICATION_INFO, function(message) {
104 		var n = new mindmaps.Notification($anchor, {
105 			position : "topRight",
106 			content : message,
107 			expires : 2500,
108 			type: "info"
109 		});
110 	});
111 	
112 	eventBus.subscribe(mindmaps.Event.NOTIFICATION_WARN, function(message) {
113 		var n = new mindmaps.Notification($anchor, {
114 			position : "topRight",
115 			title: "Warning",
116 			content : message,
117 			expires : 3000,
118 			type: "warn"
119 		});
120 	});
121 	
122 	
123 	eventBus.subscribe(mindmaps.Event.NOTIFICATION_ERROR, function(message) {
124 		var n = new mindmaps.Notification($anchor, {
125 			position : "topRight",
126 			title: "Error",
127 			content : message,
128 			expires : 3500,
129 			type: "error"
130 		});
131 	});
132 };
133