Quote escape dla tooltipów.
[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     
11         this.quickSaveButton = $('#action-quick-save', this.element).bind('click.editorview', this.quickSave.bind(this));
12         this.commitButton = $('#action-commit', this.element).bind('click.editorview', this.commit.bind(this));
13         this.updateButton = $('#action-update', this.element).bind('click.editorview', this.update.bind(this));
14         this.mergeButton = $('#action-merge', this.element).bind('click.editorview', this.merge.bind(this));
15     
16         this.model.addObserver(this, 'state', this.modelStateChanged.bind(this));
17         this.modelStateChanged('state', this.model.get('state'));        
18
19         this.splitView = new SplitView('#splitview', doc);
20         
21         // Inicjalizacja okien jQuery Modal
22         $('#commit-dialog', this.element).
23         jqm({
24             modal: true,
25             onShow: this.loadRelatedIssues.bind(this)
26         });
27     
28         $('#commit-dialog-cancel-button', this.element).click(function() {
29             $('#commit-dialog-error-empty-message').hide();
30             $('#commit-dialog').jqmHide();
31         });
32     
33         // $('#split-dialog').jqm({
34         //      modal: true,
35         //      onShow: $.fbind(self, self.loadSplitDialog)
36         //  }).
37         //  jqmAddClose('button.dialog-close-button');
38     
39         this.model.load();
40     },
41   
42     quickSave: function(event) {
43         this.model.saveDirtyContentModel();
44     },
45   
46     commit: function(event) {
47         $('#commit-dialog', this.element).jqmShow({
48             callback: this.doCommit.bind(this)
49             });
50     },
51   
52     doCommit: function(message) {
53         this.model.saveDirtyContentModel(message);
54     },
55   
56     update: function(event) {
57         this.model.update();
58     },
59   
60     merge: function(event) {
61         $('#commit-dialog', this.element).jqmShow({
62             callback: this.doMerge.bind(this)
63             });
64     },
65   
66     doMerge: function(message) {
67         this.model.merge(message);
68     },
69   
70     loadRelatedIssues: function(hash) {
71         var self = this;
72         var c = $('#commit-dialog-related-issues');
73
74         $('#commit-dialog-save-button').click(function(event, data)
75         {
76             if ($('#commit-dialog-message').val().match(/^\s*$/)) {
77                 $('#commit-dialog-error-empty-message').fadeIn();
78             } else {
79                 $('#commit-dialog-error-empty-message').hide();
80                 $('#commit-dialog').jqmHide();
81
82                 var message = $('#commit-dialog-message').val();
83                 $('#commit-dialog-related-issues input:checked')
84                 .each(function() {
85                     message += ' refs #' + $(this).val();
86                 });
87                 console.log("COMMIT APROVED", hash.t);
88                 hash.t.callback(message);
89             }
90             return false;
91         });
92
93         $("div.loading-box", c).show();
94         $("div.fatal-error-box", c).hide();
95         $("div.container-box", c).hide();
96     
97         $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
98             function(data, status)
99             {
100                 var fmt = '';
101                 $(data).each( function() {
102                     fmt += '<label><input type="checkbox" checked="checked"';
103                     fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
104                 });
105                 $("div.container-box", c).html(fmt);
106                 $("div.loading-box", c).hide();
107                 $("div.container-box", c).show();
108             });
109     
110         hash.w.show();
111     },
112   
113     modelStateChanged: function(property, value) {
114         // Uaktualnia stan przycisków
115         if (value == 'dirty') {
116             this.quickSaveButton.attr('disabled', null);
117             this.commitButton.attr('disabled', null);
118             this.updateButton.attr('disabled', 'disabled');
119             this.mergeButton.attr('disabled', 'disabled');
120         } else if (value == 'synced') {
121             this.quickSaveButton.attr('disabled', 'disabled');
122             this.commitButton.attr('disabled', 'disabled');
123             this.updateButton.attr('disabled', null);
124             this.mergeButton.attr('disabled', null);
125         } else if (value == 'empty') {
126             this.quickSaveButton.attr('disabled', 'disabled');
127             this.commitButton.attr('disabled', 'disabled');
128             this.updateButton.attr('disabled', 'disabled');
129             this.mergeButton.attr('disabled', 'disabled');
130         }
131     },
132   
133     dispose: function() {
134         $('#action-quick-save', this.element).unbind('click.editorview');
135         $('#action-commit', this.element).unbind('click.editorview');
136         $('#action-update', this.element).unbind('click.editorview');
137         $('#action-merge', this.element).unbind('click.editorview');
138
139         this.model.removeObserver(this);
140         this._super();
141     }    
142 });