X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/7aa07c7bcc96b144ed562f58dde3dce717524985..6362e543ec8e1a2661a58d440cb595b17ad4cca0:/project/static/js/views/flash.js?ds=sidebyside 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)); + } +});