Zmiana nazwy project -> platforma.
[redakcja.git] / platforma / static / js / messages.js
diff --git a/platforma/static/js/messages.js b/platforma/static/js/messages.js
new file mode 100644 (file)
index 0000000..51a457d
--- /dev/null
@@ -0,0 +1,35 @@
+/*global Editor*/
+Editor.MessageCenter = Editor.Object.extend({
+  init: function() {
+    this.messages = [];
+    this.flashMessages = [];
+    this.firstFlashMessage = null;
+  },
+  
+  addMessage: function(type, text, flash) {
+    if (!flash) {
+      flash = text;
+    }
+    this.messages.push({type: type, text: text});
+    this.flashMessages.push({type: type, text: flash});
+    if (this.flashMessages.length == 1) {
+      this.set('firstFlashMessage', this.flashMessages[0]);
+      setTimeout(this.changeFlashMessage.bind(this), 1000 * 10);
+    }
+  },
+  
+  changeFlashMessage: function() {
+    this.flashMessages.splice(0, 1);
+    if (this.flashMessages.length > 0) {
+      this.set('firstFlashMessage', this.flashMessages[0]);
+      setTimeout(this.changeFlashMessage.bind(this), 1000 * 3); // 3 seconds
+    } else {
+      this.set('firstFlashMessage', null);
+    }
+  }
+  
+});
+
+
+var messageCenter = new Editor.MessageCenter();
+