2 * UI related Editor methods
\r
4 Editor.prototype.setupUI = function() {
\r
5 // set up the UI visually and attach callbacks
\r
8 var resize_start = function(event, mydata) {
\r
9 $(document).bind('mousemove', mydata, resize_changed).
\r
10 bind('mouseup', mydata, resize_stop);
\r
12 $('.panel-overlay', mydata.root).css('display', 'block');
\r
15 var resize_changed = function(event) {
\r
16 var old_width = parseInt(event.data.overlay.css('width'));
\r
17 var delta = event.pageX + event.data.hotspot_x - old_width;
\r
19 if(old_width + delta < 12) delta = 12 - old_width;
\r
20 if(old_width + delta > $(window).width())
\r
21 delta = $(window).width() - old_width;
\r
23 event.data.overlay.css({
\r
24 'width': old_width + delta
\r
27 if(event.data.overlay.next) {
\r
28 var left = parseInt(event.data.overlay.next.css('left'));
\r
29 event.data.overlay.next.css('left', left+delta);
\r
35 var resize_stop = function(event) {
\r
36 $(document).unbind('mousemove', resize_changed).unbind('mouseup', resize_stop);
\r
37 // $('.panel-content', event.data.root).css('display', 'block');
\r
38 var overlays = $('.panel-content-overlay', event.data.root);
\r
39 $('.panel-content-overlay', event.data.root).each(function(i) {
\r
40 if( $(this).data('panel').hasClass('last-panel') )
\r
41 $(this).data('panel').css({
\r
42 'left': $(this).css('left'),
\r
43 'right': $(this).css('right')
\r
46 $(this).data('panel').css({
\r
47 'left': $(this).css('left'),
\r
48 'width': $(this).css('width')
\r
51 $('.panel-overlay', event.data.root).css('display', 'none');
\r
52 $(event.data.root).trigger('stopResize');
\r
56 * Prepare panels (overlays & stuff)
\r
58 /* create an overlay */
\r
59 var panel_root = self.rootDiv;
\r
60 var overlay_root = $("<div class='panel-overlay'></div>");
\r
61 panel_root.append(overlay_root);
\r
65 $('*.panel-wrap', panel_root).each( function()
\r
67 var panel = $(this);
\r
68 var handle = $('.panel-slider', panel);
\r
69 var overlay = $("<div class='panel-content-overlay panel-wrap'> </div>");
\r
70 overlay_root.append(overlay);
\r
71 overlay.data('panel', panel);
\r
72 overlay.data('next', null);
\r
74 if (prev) prev.next = overlay;
\r
76 if( panel.hasClass('last-panel') )
\r
79 'left': panel.css('left'),
\r
80 'right': panel.css('right')
\r
85 'left': panel.css('left'),
\r
86 'width': panel.css('width')
\r
88 // $.log('Has handle: ' + panel.attr('id'));
\r
89 overlay.append(handle.clone());
\r
90 /* attach the trigger */
\r
91 handle.mousedown(function(event) {
\r
95 hotspot_x: event.pageX - handle.position().left
\r
98 $(this).trigger('hpanel:panel-resize-start', touch_data);
\r
101 $('.panel-content', panel).css('right',
\r
102 (handle.outerWidth() || 10) + 'px');
\r
103 $('.panel-content-overlay', panel).css('right',
\r
104 (handle.outerWidth() || 10) + 'px');
\r
110 panel_root.bind('hpanel:panel-resize-start', resize_start);
\r
111 self.rootDiv.bind('stopResize', function() {
\r
112 self.savePanelOptions();
\r
116 * Connect panel actions
\r
118 $('#panels > *.panel-wrap').each(function() {
\r
119 var panelWrap = $(this);
\r
120 // $.log('wrap: ', panelWrap);
\r
121 var panel = new Panel(panelWrap);
\r
122 panelWrap.data('ctrl', panel); // attach controllers to wraps
\r
123 panel.load($('.panel-toolbar select', panelWrap).val());
\r
125 $('.panel-toolbar select', panelWrap).change(function() {
\r
126 var url = $(this).val();
\r
127 panelWrap.data('ctrl').load(url);
\r
128 self.savePanelOptions();
\r
131 $('.panel-toolbar button.refresh-button', panelWrap).click(
\r
136 self.rootDiv.bind('stopResize', function() {
\r
137 panel.callHook('toolbarResized');
\r
141 $(document).bind('panel:contentChanged', function() {
\r
142 self.onContentChanged.apply(self, arguments)
\r
146 * Connect various buttons
\r
149 $('#toolbar-button-quick-save').click( function (event, data) {
\r
150 self.saveToBranch();
\r
153 $('#toolbar-button-save').click( function (event, data) {
\r
154 $('#commit-dialog').jqmShow( {callback: $.fbind(self, self.saveToBranch)} );
\r
157 $('#toolbar-button-update').click( function (event, data) {
\r
158 if (self.updateUserBranch()) {
\r
159 // commit/update can be called only after proper, save
\r
160 // this means all panels are clean, and will get refreshed
\r
161 // do this only, when there are any changes to local branch
\r
162 self.refreshPanels();
\r
166 /* COMMIT DIALOG */
\r
167 $('#commit-dialog').
\r
170 onShow: $.fbind(self, self.loadRelatedIssues)
\r
173 $('#toolbar-button-commit').click( function (event, data) {
\r
174 $('#commit-dialog').jqmShow( {callback: $.fbind(self, self.sendMergeRequest)} );
\r
178 $('#commit-dialog-cancel-button').click(function() {
\r
179 $('#commit-dialog-error-empty-message').hide();
\r
180 $('#commit-dialog').jqmHide();
\r
185 $('#split-dialog').jqm({
\r
187 onShow: $.fbind(self, self.loadSplitDialog)
\r
189 jqmAddClose('button.dialog-close-button');
\r
191 // $('#split-dialog').
\r
194 Editor.prototype.loadRelatedIssues = function(hash)
\r
197 var c = $('#commit-dialog-related-issues');
\r
199 $('#commit-dialog-save-button').click( function (event, data)
\r
201 if( $('#commit-dialog-message').val().match(/^\s*$/)) {
\r
202 $('#commit-dialog-error-empty-message').fadeIn();
\r
205 $('#commit-dialog-error-empty-message').hide();
\r
206 $('#commit-dialog').jqmHide();
\r
208 var message = $('#commit-dialog-message').val();
\r
209 $('#commit-dialog-related-issues input:checked').
\r
210 each(function() { message += ' refs #' + $(this).val(); });
\r
211 $.log("COMMIT APROVED", hash.t);
\r
212 hash.t.callback(message);
\r
218 $("div.loading-box", c).show();
\r
219 $("div.fatal-error-box", c).hide();
\r
220 $("div.container-box", c).hide();
\r
222 $.getJSON( c.attr('ui:ajax-src') + '?callback=?',
\r
223 function(data, status)
\r
226 $(data).each( function() {
\r
227 fmt += '<label><input type="checkbox" checked="checked"'
\r
228 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n'
\r
230 $("div.container-box", c).html(fmt);
\r
231 $("div.loading-box", c).hide();
\r
232 $("div.container-box", c).show();
\r
238 Editor.prototype.loadSplitDialog = function(hash)
\r
242 $("div.loading-box", hash.w).show();
\r
243 $("div.fatal-error-box", hash.w).hide();
\r
244 $('div.container-box', hash.w).hide();
\r
247 function onFailure(rq, tstat, err) {
\r
248 $('div.container-box', hash.w).html('');
\r
249 $("div.loading-box", hash.w).hide();
\r
250 $("div.fatal-error-box", hash.w).show();
\r
254 function onSuccess(data, status) {
\r
255 // put the form into the window
\r
256 $('div.container-box', hash.w).html(data);
\r
257 $("div.loading-box", hash.w).hide();
\r
258 $('form input[name=splitform-splittext]', hash.w).val(hash.t.selection);
\r
259 $('form input[name=splitform-fulltext]', hash.w).val(hash.t.fulltext);
\r
260 $('div.container-box', hash.w).show();
\r
263 $('#split-dialog-button-accept').click(function() {
\r
264 self.postSplitRequest(onSuccess, onFailure);
\r
268 $('#split-dialog-button-close').click(function() {
\r
270 $('div.container-box', hash.w).html('');
\r
274 $('#split-dialog-button-dismiss').click(function() {
\r
276 $('div.container-box', hash.w).html('');
\r
280 /* if($('#id_splitform-autoxml').is(':checked'))
\r
281 $('#split-form-dc-subform').show();
\r
283 $('#split-form-dc-subform').hide();
\r
285 $('#id_splitform-autoxml').change(function() {
\r
286 if( $(this).is(':checked') )
\r
287 $('#split-form-dc-subform').show();
\r
289 $('#split-form-dc-subform').hide();
\r
296 success: onSuccess,
\r
303 /* Refreshing routine */
\r
304 Editor.prototype.refreshPanels = function() {
\r
307 self.allPanels().each(function() {
\r
308 var panel = $(this).data('ctrl');
\r
309 $.log('Refreshing: ', this, panel);
\r
310 if ( panel.changed() )
\r
311 panel.unmarkChanged();
\r
316 $('button.provides-save').attr('disabled', 'disabled');
\r
317 $('button.requires-save').removeAttr('disabled');
\r
323 Editor.prototype.showPopup = function(name, text, timeout)
\r
325 timeout = timeout || 4000;
\r
327 self.popupQueue.push( [name, text, timeout] )
\r
329 if( self.popupQueue.length > 1)
\r
332 var box = $('#message-box > #' + name);
\r
333 $('*.data', box).html(text || '');
\r
337 setTimeout( $.fbind(self, self.advancePopupQueue), timeout);
\r
340 Editor.prototype.advancePopupQueue = function() {
\r
342 var elem = this.popupQueue.shift();
\r
344 var box = $('#message-box > #' + elem[0]);
\r
346 box.fadeOut(100, function()
\r
348 $('*.data', box).html('');
\r
350 if( self.popupQueue.length > 0) {
\r
351 var ibox = $('#message-box > #' + self.popupQueue[0][0]);
\r
352 $('*.data', ibox).html(self.popupQueue[0][1] || '');
\r
354 if(self.popupQueue[0][2] > 0)
\r
355 setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);
\r