Usunięcie niepotrzebnych console.log (teraz śledzimy tylko stany modeli) i dodanie...
[redakcja.git] / project / static / js / views / editor.js
1 /*global View render_template panels */
2 var EditorView = View.extend({
3   _className: 'EditorView',
4   element: null,
5   model: null,
6   template: null,
7   
8   init: function(element, model, template) {
9     this._super(element, model, template);
10     this.model.load();
11     
12     this.quickSaveButton = $('#action-quick-save', this.element).bind('click.editorview', this.quickSave.bind(this));
13     this.commitButton = $('#action-commit', this.element).bind('click.editorview', this.commit.bind(this));
14     this.updateButton = $('#action-update', this.element).bind('click.editorview', this.update.bind(this));
15     this.mergeButton = $('#action-merge', this.element).bind('click.editorview', this.merge.bind(this));
16     
17     this.model.addObserver(this, 'state', this.modelStateChanged.bind(this));
18     this.modelStateChanged('state', this.model.get('state'));
19   },
20   
21   quickSave: function(event) {
22     this.model.quickSave();
23   },
24   
25   commit: function(event) {
26   },
27   
28   update: function(event) {
29   },
30   
31   merge: function(event) {
32   },
33   
34   modelStateChanged: function(property, value) {
35     // Uaktualnia stan przycisków
36     if (value == 'dirty') {
37       this.quickSaveButton.attr('disabled', null);
38       this.commitButton.attr('disabled', null);
39       this.updateButton.attr('disabled', 'disabled');
40       this.mergeButton.attr('disabled', 'disabled');
41     } else if (value == 'synced') {
42       this.quickSaveButton.attr('disabled', 'disabled');
43       this.commitButton.attr('disabled', 'disabled');
44       this.updateButton.attr('disabled', null);
45       this.mergeButton.attr('disabled', null);      
46     } else if (value == 'empty') {
47       this.quickSaveButton.attr('disabled', 'disabled');
48       this.commitButton.attr('disabled', 'disabled');
49       this.updateButton.attr('disabled', 'disabled');
50       this.mergeButton.attr('disabled', 'disabled');
51     }
52   },
53   
54   dispose: function() {
55     $('#action-quick-save', this.element).unbind('click.editorview');
56     $('#action-commit', this.element).unbind('click.editorview');
57     $('#action-update', this.element).unbind('click.editorview');
58     $('#action-merge', this.element).unbind('click.editorview');
59
60     this.model.removeObserver(this);
61     this._super();
62   }
63 });