Ulepszenie obsługi błędów (dodanie stanu error dla paneli).
[redakcja.git] / project / static / js / views / html.js
1 /*global View render_template panels */
2 var HTMLView = View.extend({
3   _className: 'HTMLView',
4   element: null,
5   model: null,
6   template: 'html-view-template',
7   
8   init: function(element, model, parent, template) {
9     this._super(element, model, template);
10     this.parent = parent;
11     
12     this.model
13       .addObserver(this, 'data', this.modelDataChanged.bind(this))
14       .addObserver(this, 'state', this.modelStateChanged.bind(this));
15       
16     $('.htmlview', this.element).html(this.model.get('data'));
17     this.modelStateChanged('state', this.model.get('state'));
18     this.model.load();
19   },
20   
21   modelDataChanged: function(property, value) {
22     $('.htmlview', this.element).html(value);
23   },
24   
25   modelStateChanged: function(property, value) {
26     if (value == 'synced' || value == 'dirty') {
27       this.parent.unfreeze();
28     } else if (value == 'unsynced') {
29       this.parent.freeze('Niezsynchronizowany...');
30     } else if (value == 'loading') {
31       this.parent.freeze('Ładowanie...');
32     } else if (value == 'saving') {
33       this.parent.freeze('Zapisywanie...');
34     } else if (value == 'error') {
35       this.parent.freeze(this.model.get('error'));
36     }
37   },
38   
39   dispose: function() {
40     this.model.removeObserver(this);
41     this._super();
42   }
43 });
44
45 // Register view
46 panels['html'] = HTMLView;