1 /*global View render_template panels */
2 var EditorView = View.extend({
3 _className: 'EditorView',
8 init: function(element, model, template) {
9 this._super(element, model, template);
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));
16 this.model.addObserver(this, 'state', this.modelStateChanged.bind(this));
17 this.modelStateChanged('state', this.model.get('state'));
19 this.splitView = new SplitView('#splitview', doc);
21 // Inicjalizacja okien jQuery Modal
22 $('#commit-dialog', this.element).
25 onShow: this.loadRelatedIssues.bind(this)
28 $('#commit-dialog-cancel-button', this.element).click(function() {
29 $('#commit-dialog-error-empty-message').hide();
30 $('#commit-dialog').jqmHide();
33 $('#commit-dialog-save-button').click(function(event, data)
35 if ($('#commit-dialog-message').val().match(/^\s*$/)) {
36 $('#commit-dialog-error-empty-message').fadeIn();
38 $('#commit-dialog-error-empty-message').hide();
39 $('#commit-dialog').jqmHide();
41 var message = $('#commit-dialog-message').val();
42 $('#commit-dialog-related-issues input:checked')
44 message += ' refs #' + $(this).val();
47 var ctx = $('#commit-dialog').data('context');
48 console.log("COMMIT APROVED", ctx);
49 ctx.callback(message);
55 // $('#split-dialog').jqm({
57 // onShow: $.fbind(self, self.loadSplitDialog)
59 // jqmAddClose('button.dialog-close-button');
64 quickSave: function(event) {
65 this.model.saveDirtyContentModel();
68 commit: function(event) {
69 $('#commit-dialog', this.element).jqmShow({
70 callback: this.doCommit.bind(this)
74 doCommit: function(message) {
75 this.model.saveDirtyContentModel(message);
78 update: function(event) {
82 merge: function(event) {
83 $('#commit-dialog', this.element).jqmShow({
84 callback: this.doMerge.bind(this)
88 doMerge: function(message) {
89 this.model.merge(message);
92 loadRelatedIssues: function(hash) {
94 var c = $('#commit-dialog-related-issues');
96 $('#commit-dialog').data('context', hash.t);
98 $("div.loading-box", c).show();
99 $("div.fatal-error-box", c).hide();
100 $("div.container-box", c).hide();
102 $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
103 function(data, status)
106 $(data).each( function() {
107 fmt += '<label><input type="checkbox" checked="checked"';
108 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
110 $("div.container-box", c).html(fmt);
111 $("div.loading-box", c).hide();
112 $("div.container-box", c).show();
118 modelStateChanged: function(property, value) {
119 // Uaktualnia stan przycisków
120 if (value == 'dirty') {
121 this.quickSaveButton.attr('disabled', null);
122 this.commitButton.attr('disabled', null);
123 this.updateButton.attr('disabled', 'disabled');
124 this.mergeButton.attr('disabled', 'disabled');
125 } else if (value == 'synced' || value == 'unsynced') {
126 this.quickSaveButton.attr('disabled', 'disabled');
127 this.commitButton.attr('disabled', 'disabled');
128 this.updateButton.attr('disabled', null);
129 this.mergeButton.attr('disabled', null);
131 } else if (value == 'empty') {
132 this.quickSaveButton.attr('disabled', 'disabled');
133 this.commitButton.attr('disabled', 'disabled');
134 this.updateButton.attr('disabled', 'disabled');
135 this.mergeButton.attr('disabled', 'disabled');
136 } else if (value == 'error') {
137 this.freeze(this.model.get('error'));
138 this.quickSaveButton.attr('disabled', 'disabled');
139 this.commitButton.attr('disabled', 'disabled');
140 this.updateButton.attr('disabled', 'disabled');
141 this.mergeButton.attr('disabled', 'disabled');
146 dispose: function() {
147 $('#action-quick-save', this.element).unbind('click.editorview');
148 $('#action-commit', this.element).unbind('click.editorview');
149 $('#action-update', this.element).unbind('click.editorview');
150 $('#action-merge', this.element).unbind('click.editorview');
152 this.model.removeObserver(this);