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 this.commitDialog = new CommitDialog( $('#commit-dialog') );
25 // $('#split-dialog').jqm({
27 // onShow: $.fbind(self, self.loadSplitDialog)
29 // jqmAddClose('button.dialog-close-button');
34 quickSave: function(event) {
35 this.model.saveDirtyContentModel();
38 commit: function(event)
40 this.commitDialog.show( this.doCommit.bind(this) )
44 doCommit: function(message) {
45 this.model.saveDirtyContentModel(message);
48 update: function(event) {
52 merge: function(event) {
53 this.commitDialog.show( this.doMerge.bind(this) )
56 doMerge: function(message) {
57 this.model.merge(message);
60 /*loadRelatedIssues: function(hash) {
62 var c = $('#commit-dialog-related-issues');
64 $('#commit-dialog').data('context', hash.t);
66 $("div.loading-box", c).show();
67 $("div.fatal-error-box", c).hide();
68 $("div.container-box", c).hide();
70 $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
71 function(data, status)
74 $(data).each( function() {
75 fmt += '<label><input type="checkbox" checked="checked"';
76 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
78 $("div.container-box", c).html(fmt);
79 $("div.loading-box", c).hide();
80 $("div.container-box", c).show();
86 modelStateChanged: function(property, value) {
87 // Uaktualnia stan przycisków
88 if (value == 'dirty') {
89 this.quickSaveButton.attr('disabled', null);
90 this.commitButton.attr('disabled', null);
91 this.updateButton.attr('disabled', 'disabled');
92 this.mergeButton.attr('disabled', 'disabled');
93 } else if (value == 'synced' || value == 'unsynced') {
94 this.quickSaveButton.attr('disabled', 'disabled');
95 this.commitButton.attr('disabled', 'disabled');
96 this.updateButton.attr('disabled', null);
97 this.mergeButton.attr('disabled', null);
99 } else if (value == 'empty') {
100 this.quickSaveButton.attr('disabled', 'disabled');
101 this.commitButton.attr('disabled', 'disabled');
102 this.updateButton.attr('disabled', 'disabled');
103 this.mergeButton.attr('disabled', 'disabled');
104 } else if (value == 'error') {
105 this.freeze(this.model.get('error'));
106 this.quickSaveButton.attr('disabled', 'disabled');
107 this.commitButton.attr('disabled', 'disabled');
108 this.updateButton.attr('disabled', 'disabled');
109 this.mergeButton.attr('disabled', 'disabled');
114 dispose: function() {
115 $('#action-quick-save', this.element).unbind('click.editorview');
116 $('#action-commit', this.element).unbind('click.editorview');
117 $('#action-update', this.element).unbind('click.editorview');
118 $('#action-merge', this.element).unbind('click.editorview');
120 this.model.removeObserver(this);
126 var AbstractDialog = Class.extend({
127 _className: 'AbstractDialog',
129 init: function($element, modal, overlay)
131 this.$window = $element;
133 modal: modal || true,
134 overlay: overlay || 80,
136 onShow: this.onShow.bind(this),
137 onHide: this.onHide.bind(this)
142 $('.cancel-button', this.$window).click(this.cancel.bind(this));
143 $('.save-button', this.$window).click(this.accept.bind(this));
146 onShow: function(hash)
151 onHide: function(hash)
158 this.acceptCallback = null;
159 this.cancelCallback = null;
162 $('.error-messages-box', this.$window).html('').hide();
167 show: function(acall, ccall) {
168 this.acceptCallback = acall;
169 this.cancelCallback = ccall;
172 this.$window.jqmShow();
176 this.$window.jqmHide();
177 if(this.cancelCallback) this.cancelCallback(this);
185 if(!this.validate()) {
186 this.displayErrors();
190 this.$window.jqmHide();
192 if(this.acceptCallback)
193 this.acceptCallback(this);
198 validate: function() {
202 displayErrors: function() {
203 var errorDiv = $('.error-messages-box', this.$window);
204 if(errorDiv.length > 0) {
206 $.each(this.errors, function() {
207 html += '<li>' + this + '</li>';
209 errorDiv.html('<ul>' + html + '</ul>');
211 console.log('Validation errors:', html);
219 var CommitDialog = AbstractDialog.extend({
220 _className: 'CommitDialog',
224 var message = $('textarea.commit-message', this.$window).val();
226 if( message.match(/^\s*$/) ) {
227 this.errors.push("Message can't be empty.");
232 $('.related-issues-fields input:checked', this.$window).each(function() {
233 message += ' refs #' + $(this).val();
236 this.userData.message = message;
237 return this._super();