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
92 // var touch_data = {
\r
93 // root: panel_root,
\r
94 // overlay: overlay,
\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
192 Editor.prototype.loadRelatedIssues = function(hash)
\r
195 var c = $('#commit-dialog-related-issues');
\r
197 $('#commit-dialog-save-button').click( function (event, data)
\r
199 if( $('#commit-dialog-message').val().match(/^\s*$/)) {
\r
200 $('#commit-dialog-error-empty-message').fadeIn();
\r
203 $('#commit-dialog-error-empty-message').hide();
\r
204 $('#commit-dialog').jqmHide();
\r
206 var message = $('#commit-dialog-message').val();
\r
207 $('#commit-dialog-related-issues input:checked').
\r
208 each(function() { message += ' refs #' + $(this).val(); });
\r
209 $.log("COMMIT APROVED", hash.t);
\r
210 hash.t.callback(message);
\r
216 $("div.loading-box", c).show();
\r
217 $("div.fatal-error-box", c).hide();
\r
218 $("div.container-box", c).hide();
\r
220 $.getJSON( c.attr('ui:ajax-src') + '?callback=?',
\r
221 function(data, status)
\r
224 $(data).each( function() {
\r
225 fmt += '<label><input type="checkbox" checked="checked"'
\r
226 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n'
\r
228 $("div.container-box", c).html(fmt);
\r
229 $("div.loading-box", c).hide();
\r
230 $("div.container-box", c).show();
\r
236 Editor.prototype.loadSplitDialog = function(hash)
\r
240 $("div.loading-box", hash.w).show();
\r
241 $("div.fatal-error-box", hash.w).hide();
\r
242 $('div.container-box', hash.w).hide();
\r
245 function onFailure(rq, tstat, err) {
\r
246 $('div.container-box', hash.w).html('');
\r
247 $("div.loading-box", hash.w).hide();
\r
248 $("div.fatal-error-box", hash.w).show();
\r
252 function onSuccess(data, status) {
\r
253 // put the form into the window
\r
254 $('div.container-box', hash.w).html(data);
\r
255 $("div.loading-box", hash.w).hide();
\r
256 $('form input[name=splitform-splittext]', hash.w).val(hash.t.selection);
\r
257 $('form input[name=splitform-fulltext]', hash.w).val(hash.t.fulltext);
\r
258 $('div.container-box', hash.w).show();
\r
261 $('#split-dialog-button-accept').click(function() {
\r
262 self.postSplitRequest(onSuccess, onFailure);
\r
266 $('#split-dialog-button-close').click(function() {
\r
268 $('div.container-box', hash.w).html('');
\r
272 $('#split-dialog-button-dismiss').click(function() {
\r
274 $('div.container-box', hash.w).html('');
\r
278 /* if($('#id_splitform-autoxml').is(':checked'))
\r
279 $('#split-form-dc-subform').show();
\r
281 $('#split-form-dc-subform').hide();
\r
283 $('#id_splitform-autoxml').change(function() {
\r
284 if( $(this).is(':checked') )
\r
285 $('#split-form-dc-subform').show();
\r
287 $('#split-form-dc-subform').hide();
\r
294 success: onSuccess,
\r
301 /* Refreshing routine */
\r
302 Editor.prototype.refreshPanels = function() {
\r
305 self.allPanels().each(function() {
\r
306 var panel = $(this).data('ctrl');
\r
307 $.log('Refreshing: ', this, panel);
\r
308 if ( panel.changed() )
\r
309 panel.unmarkChanged();
\r
314 $('button.provides-save').attr('disabled', 'disabled');
\r
315 $('button.requires-save').removeAttr('disabled');
\r
321 Editor.prototype.showPopup = function(name, text, timeout)
\r
323 timeout = timeout || 4000;
\r
325 self.popupQueue.push( [name, text, timeout] )
\r
327 if( self.popupQueue.length > 1)
\r
330 var box = $('#message-box > #' + name);
\r
331 $('*.data', box).html(text || '');
\r
335 setTimeout( $.fbind(self, self.advancePopupQueue), timeout);
\r
338 Editor.prototype.advancePopupQueue = function() {
\r
340 var elem = this.popupQueue.shift();
\r
342 var box = $('#message-box > #' + elem[0]);
\r
344 box.fadeOut(100, function()
\r
346 $('*.data', box).html('');
\r
348 if( self.popupQueue.length > 0) {
\r
349 var ibox = $('#message-box > #' + self.popupQueue[0][0]);
\r
350 $('*.data', ibox).html(self.popupQueue[0][1] || '');
\r
352 if(self.popupQueue[0][2] > 0)
\r
353 setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);
\r