Wydzielenie funkcji guess_mime z VersionedStorage.page_mime, żeby można było ją łatwo...
[redakcja.git] / platforma / static / js / messages.js
index 51a457d..eddb46e 100644 (file)
@@ -1,32 +1,68 @@
 /*global Editor*/
 Editor.MessageCenter = Editor.Object.extend({
-  init: function() {
-    this.messages = [];
-    this.flashMessages = [];
-    this.firstFlashMessage = null;
-  },
+    init: function() {
+        this.messages = [];
+        this.flashMessages = [];
+        this.firstFlashMessage = null;
+        this.timeout = null;
+        console.log("MSC-init:", Date(), this);
+    },
   
-  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);
-    }
-  },
+    addMessage: function(type, tag, text, flash)
+    {
+        if (!tag) tag = '#default'
+        
+        if (!flash) {
+            flash = text;
+        }
+
+        this.messages.push({
+            type: type,
+            text: text
+        });
+
+        this.flashMessages.push({
+            type: type,
+            text: flash,
+            tag: tag
+        });
+
+        if(this.timeout) {
+            if(this.flashMessages[0] && (this.flashMessages[0].tag == tag))
+            {
+                clearTimeout(this.timeout);
+                this.timeout = null;
+                this.changeFlashMessage();
+            }
+        }       
+        
+        else {
+            /* queue was empty at the start */
+            if (this.flashMessages.length == 1) {
+                console.log("MSC-added-fisrt", Date(), this);
+                this.set('firstFlashMessage', this.flashMessages[0]);
+                this.timeout = setTimeout(this.changeFlashMessage.bind(this), 3000);
+            }
+
+        }
+        
+    },
   
-  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);
+    changeFlashMessage: function() 
+    {
+        console.log("MSC-change", Date(), this);
+        var previous = this.flashMessages.splice(0, 1);
+        
+        if (this.flashMessages.length > 0) 
+        {
+            console.log("MSC-chaning-first", Date(), this);
+            this.set('firstFlashMessage', this.flashMessages[0]);            
+            this.timeout = setTimeout(this.changeFlashMessage.bind(this), 3000);
+        } else {
+            console.log("MSC-emptying", Date(), this);
+            this.set('firstFlashMessage', null);
+        }
     }
-  }
   
 });