X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/78644811ca0c6042212788dc67add42bc41fb74c..91a84926407f9f10739b2423c449bc98a57ea424:/platforma/static/js/messages.js diff --git a/platforma/static/js/messages.js b/platforma/static/js/messages.js index 51a457dd..eddb46e4 100644 --- a/platforma/static/js/messages.js +++ b/platforma/static/js/messages.js @@ -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); + } } - } });