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();
34 // $('#split-dialog').jqm({
36 // onShow: $.fbind(self, self.loadSplitDialog)
38 // jqmAddClose('button.dialog-close-button');
43 quickSave: function(event) {
44 this.model.saveDirtyContentModel();
47 commit: function(event) {
48 $('#commit-dialog', this.element).jqmShow({
49 callback: this.doCommit.bind(this)
53 doCommit: function(message) {
54 this.model.saveDirtyContentModel(message);
57 update: function(event) {
61 merge: function(event) {
62 $('#commit-dialog', this.element).jqmShow({
63 callback: this.doMerge.bind(this)
67 doMerge: function(message) {
68 this.model.merge(message);
71 loadRelatedIssues: function(hash) {
73 var c = $('#commit-dialog-related-issues');
75 $('#commit-dialog-save-button').click(function(event, data)
77 if ($('#commit-dialog-message').val().match(/^\s*$/)) {
78 $('#commit-dialog-error-empty-message').fadeIn();
80 $('#commit-dialog-error-empty-message').hide();
81 $('#commit-dialog').jqmHide();
83 var message = $('#commit-dialog-message').val();
84 $('#commit-dialog-related-issues input:checked')
86 message += ' refs #' + $(this).val();
88 console.log("COMMIT APROVED", hash.t);
89 hash.t.callback(message);
94 $("div.loading-box", c).show();
95 $("div.fatal-error-box", c).hide();
96 $("div.container-box", c).hide();
98 $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
99 function(data, status)
102 $(data).each( function() {
103 fmt += '<label><input type="checkbox" checked="checked"';
104 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
106 $("div.container-box", c).html(fmt);
107 $("div.loading-box", c).hide();
108 $("div.container-box", c).show();
114 modelStateChanged: function(property, value) {
115 // Uaktualnia stan przycisków
116 if (value == 'dirty') {
117 this.quickSaveButton.attr('disabled', null);
118 this.commitButton.attr('disabled', null);
119 this.updateButton.attr('disabled', 'disabled');
120 this.mergeButton.attr('disabled', 'disabled');
121 } else if (value == 'synced') {
122 this.quickSaveButton.attr('disabled', 'disabled');
123 this.commitButton.attr('disabled', 'disabled');
124 this.updateButton.attr('disabled', null);
125 this.mergeButton.attr('disabled', null);
127 } else if (value == 'empty') {
128 this.quickSaveButton.attr('disabled', 'disabled');
129 this.commitButton.attr('disabled', 'disabled');
130 this.updateButton.attr('disabled', 'disabled');
131 this.mergeButton.attr('disabled', 'disabled');
132 } else if (value == 'error') {
133 this.freeze(this.model.get('error'));
134 this.quickSaveButton.attr('disabled', 'disabled');
135 this.commitButton.attr('disabled', 'disabled');
136 this.updateButton.attr('disabled', 'disabled');
137 this.mergeButton.attr('disabled', 'disabled');
142 dispose: function() {
143 $('#action-quick-save', this.element).unbind('click.editorview');
144 $('#action-commit', this.element).unbind('click.editorview');
145 $('#action-update', this.element).unbind('click.editorview');
146 $('#action-merge', this.element).unbind('click.editorview');
148 this.model.removeObserver(this);