From: zuber Date: Wed, 30 Sep 2009 14:47:20 +0000 (+0200) Subject: Dodanie flash messages. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/6a38c4ea4b6853116bf2302cd73d6c51f696888a?ds=sidebyside;hp=--cc Dodanie flash messages. --- 6a38c4ea4b6853116bf2302cd73d6c51f696888a 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(); + diff --git a/project/static/js/models.js b/project/static/js/models.js index b5b9c541..9938eb07 100644 --- a/project/static/js/models.js +++ b/project/static/js/models.js @@ -1,4 +1,4 @@ -/*globals Editor fileId SplitView PanelContainerView EditorView*/ +/*globals Editor fileId SplitView PanelContainerView EditorView FlashView messageCenter*/ var documentsUrl = '/api/documents/'; @@ -375,6 +375,7 @@ $(function() { doc = new Editor.DocumentModel(); var editor = new EditorView('#body-wrap', doc); editor.freeze(); + var flashView = new FlashView('#flashview', messageCenter); var splitView = new SplitView('#splitview', doc); leftPanelView = new PanelContainerView('#left-panel-container', doc); rightPanelContainer = new PanelContainerView('#right-panel-container', doc); diff --git a/project/static/js/views/flash.js b/project/static/js/views/flash.js new file mode 100644 index 00000000..3f4f4759 --- /dev/null +++ b/project/static/js/views/flash.js @@ -0,0 +1,35 @@ +/*globals View render_template*/ +var FlashView = View.extend({ + template: 'flash-view-template', + + init: function(element, model, template) { + this.shownMessage = null; + this._super(element, model, template); + this.setModel(model); + }, + + setModel: function(model) { + if (this.model) { + this.model.removeObserver(this); + } + this.model = model; + this.shownMessage = null; + if (this.model) { + this.shownMessage = this.model.get('firstFlashMessage'); + this.model.addObserver(this, 'firstFlashMessage', this.modelFirstFlashMessageChanged.bind(this)); + } + this.render(); + }, + + render: function() { + this.element.html(render_template(this.template, this)); + }, + + modelFirstFlashMessageChanged: function(property, value) { + this.element.fadeOut('slow', function() { + this.shownMessage = value; + this.render(); + this.element.fadeIn('slow'); + }.bind(this)); + } +}); diff --git a/project/templates/explorer/editor.html b/project/templates/explorer/editor.html index c38dfc4f..ff37c24b 100644 --- a/project/templates/explorer/editor.html +++ b/project/templates/explorer/editor.html @@ -16,7 +16,9 @@ {# App and views #} + + @@ -49,7 +51,15 @@ - + +