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 // $('#split-dialog').jqm({
35 // onShow: $.fbind(self, self.loadSplitDialog)
37 // jqmAddClose('button.dialog-close-button');
42 quickSave: function(event) {
43 this.model.saveDirtyContentModel();
46 commit: function(event) {
47 $('#commit-dialog', this.element).jqmShow({
48 callback: this.doCommit.bind(this)
52 doCommit: function(message) {
53 this.model.saveDirtyContentModel(message);
56 update: function(event) {
60 merge: function(event) {
61 $('#commit-dialog', this.element).jqmShow({
62 callback: this.doMerge.bind(this)
66 doMerge: function(message) {
67 this.model.merge(message);
70 loadRelatedIssues: function(hash) {
72 var c = $('#commit-dialog-related-issues');
74 $('#commit-dialog-save-button').click(function(event, data)
76 if ($('#commit-dialog-message').val().match(/^\s*$/)) {
77 $('#commit-dialog-error-empty-message').fadeIn();
79 $('#commit-dialog-error-empty-message').hide();
80 $('#commit-dialog').jqmHide();
82 var message = $('#commit-dialog-message').val();
83 $('#commit-dialog-related-issues input:checked')
85 message += ' refs #' + $(this).val();
87 console.log("COMMIT APROVED", hash.t);
88 hash.t.callback(message);
93 $("div.loading-box", c).show();
94 $("div.fatal-error-box", c).hide();
95 $("div.container-box", c).hide();
97 $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
98 function(data, status)
101 $(data).each( function() {
102 fmt += '<label><input type="checkbox" checked="checked"';
103 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
105 $("div.container-box", c).html(fmt);
106 $("div.loading-box", c).hide();
107 $("div.container-box", c).show();
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');
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');
139 this.model.removeObserver(this);