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 // Inicjalizacja okien jQuery Modal
20 $('#commit-dialog', this.element).
23 onShow: this.loadRelatedIssues.bind(this)
26 $('#commit-dialog-cancel-button', this.element).click(function() {
27 $('#commit-dialog-error-empty-message').hide();
28 $('#commit-dialog').jqmHide();
31 // $('#split-dialog').jqm({
33 // onShow: $.fbind(self, self.loadSplitDialog)
35 // jqmAddClose('button.dialog-close-button');
40 quickSave: function(event) {
41 this.model.saveDirtyContentModel();
44 commit: function(event) {
45 $('#commit-dialog', this.element).jqmShow({callback: this.doCommit.bind(this)});
48 doCommit: function(message) {
49 this.model.saveDirtyContentModel(message);
52 update: function(event) {
56 merge: function(event) {
57 $('#commit-dialog', this.element).jqmShow({callback: this.doMerge.bind(this)});
60 doMerge: function(message) {
61 this.model.merge(message);
64 loadRelatedIssues: function(hash) {
66 var c = $('#commit-dialog-related-issues');
68 $('#commit-dialog-save-button').click(function(event, data)
70 if ($('#commit-dialog-message').val().match(/^\s*$/)) {
71 $('#commit-dialog-error-empty-message').fadeIn();
73 $('#commit-dialog-error-empty-message').hide();
74 $('#commit-dialog').jqmHide();
76 var message = $('#commit-dialog-message').val();
77 $('#commit-dialog-related-issues input:checked')
78 .each(function() { message += ' refs #' + $(this).val(); });
79 console.log("COMMIT APROVED", hash.t);
80 hash.t.callback(message);
85 $("div.loading-box", c).show();
86 $("div.fatal-error-box", c).hide();
87 $("div.container-box", c).hide();
89 $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
90 function(data, status)
93 $(data).each( function() {
94 fmt += '<label><input type="checkbox" checked="checked"';
95 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
97 $("div.container-box", c).html(fmt);
98 $("div.loading-box", c).hide();
99 $("div.container-box", c).show();
105 modelStateChanged: function(property, value) {
106 // Uaktualnia stan przycisków
107 if (value == 'dirty') {
108 this.quickSaveButton.attr('disabled', null);
109 this.commitButton.attr('disabled', null);
110 this.updateButton.attr('disabled', 'disabled');
111 this.mergeButton.attr('disabled', 'disabled');
112 } else if (value == 'synced') {
113 this.quickSaveButton.attr('disabled', 'disabled');
114 this.commitButton.attr('disabled', 'disabled');
115 this.updateButton.attr('disabled', null);
116 this.mergeButton.attr('disabled', null);
117 } else if (value == 'empty') {
118 this.quickSaveButton.attr('disabled', 'disabled');
119 this.commitButton.attr('disabled', 'disabled');
120 this.updateButton.attr('disabled', 'disabled');
121 this.mergeButton.attr('disabled', 'disabled');
125 dispose: function() {
126 $('#action-quick-save', this.element).unbind('click.editorview');
127 $('#action-commit', this.element).unbind('click.editorview');
128 $('#action-update', this.element).unbind('click.editorview');
129 $('#action-merge', this.element).unbind('click.editorview');
131 this.model.removeObserver(this);