Merge branch 'master' of stigma.nowoczesnapolska.org.pl:platforma
[redakcja.git] / platforma / static / js / views / flash.js
1 /*globals View render_template*/
2 var FlashView = View.extend({
3   template: 'flash-view-template',
4
5   init: function(element, model, template) {
6     this.shownMessage = null;
7     this._super(element, model, template);
8     this.setModel(model);
9   },
10   
11   setModel: function(model) {
12     if (this.model) {
13       this.model.removeObserver(this);
14     }
15     this.model = model;
16     this.shownMessage = null;
17     if (this.model) {
18       this.shownMessage = this.model.get('firstFlashMessage');
19       this.model.addObserver(this, 'firstFlashMessage', this.modelFirstFlashMessageChanged.bind(this));
20     }
21     this.render();
22   },
23   
24   render: function() {
25     this.element.html(render_template(this.template, this));
26     setTimeout(function() {}, 0);
27   },
28   
29   modelFirstFlashMessageChanged: function(property, value) {    
30     this.element.fadeOut(200, (function() {
31     
32     this.element.css({'z-index': 0});
33     this.shownMessage = value;
34     this.render();
35
36     if(this.shownMessage) {
37         this.element.css({'z-index': 1000});
38         this.element.fadeIn();
39     };
40     }).bind(this));
41   }
42 });