X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f1b70c0cd342b6769df2326ffc122add67ccd917..6a38c4ea4b6853116bf2302cd73d6c51f696888a:/project/static/js/messages.js?ds=sidebyside diff --git a/project/static/js/messages.js b/project/static/js/messages.js new file mode 100644 index 00000000..c64aa5bd --- /dev/null +++ b/project/static/js/messages.js @@ -0,0 +1,34 @@ +/*global Editor*/ +Editor.MessageCenter = Editor.Object.extend({ + init: function() { + this.messages = []; + this.flashMessages = []; + this.firstFlashMessage = null; + }, + + addMessage: function(type, text, flash) { + this.messages.push({type: type, text: text}); + if (flash) { + 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 * 10); + } else { + this.set('firstFlashMessage', null); + } + } + +}); + + +var messageCenter = new Editor.MessageCenter(); +