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-save').click( function (event, data) {
\r
150 self.saveToBranch();
\r
153 $('#toolbar-button-update').click( function (event, data) {
\r
154 if (self.updateUserBranch()) {
\r
155 // commit/update can be called only after proper, save
\r
156 // this means all panels are clean, and will get refreshed
\r
157 // do this only, when there are any changes to local branch
\r
158 self.refreshPanels();
\r
162 /* COMMIT DIALOG */
\r
163 $('#commit-dialog').
\r
166 onShow: $.fbind(self, self.loadRelatedIssues),
\r
167 trigger: '#toolbar-button-commit'
\r
171 $('#commit-dialog-cancel-button').click(function() {
\r
172 $('#commit-dialog-error-empty-message').hide();
\r
173 $('#commit-dialog').jqmHide();
\r
176 $('#commit-dialog-save-button').click( function (event, data)
\r
178 if( $('#commit-dialog-message').val().match(/^\s*$/)) {
\r
179 $('#commit-dialog-error-empty-message').fadeIn();
\r
182 $('#commit-dialog-error-empty-message').hide();
\r
183 $('#commit-dialog').jqmHide();
\r
184 self.sendMergeRequest($('#commit-dialog-message').val() );
\r
192 $('#split-dialog').jqm({
\r
194 onShow: $.fbind(self, self.loadSplitDialog)
\r
196 jqmAddClose('button.dialog-close-button');
\r
198 // $('#split-dialog').
\r
201 Editor.prototype.loadRelatedIssues = function(hash)
\r
204 var c = $('#commit-dialog-related-issues');
\r
206 $("div.loading-box", c).show();
\r
207 $("div.fatal-error-box", c).hide();
\r
208 $("div.container-box", c).hide();
\r
210 $.getJSON( c.attr('ui:ajax-src') + '?callback=?',
\r
211 function(data, status)
\r
214 $(data).each( function() {
\r
215 fmt += '<label><input type="checkbox" checked="checked"'
\r
216 fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n'
\r
218 $("div.container-box", c).html(fmt);
\r
219 $("div.loading-box", c).hide();
\r
220 $("div.container-box", c).show();
\r
226 Editor.prototype.loadSplitDialog = function(hash)
\r
230 $("div.loading-box", hash.w).show();
\r
231 $("div.fatal-error-box", hash.w).hide();
\r
232 $('div.container-box', hash.w).hide();
\r
235 function onFailure(rq, tstat, err) {
\r
236 $('div.container-box', hash.w).html('');
\r
237 $("div.loading-box", hash.w).hide();
\r
238 $("div.fatal-error-box", hash.w).show();
\r
242 function onSuccess(data, status) {
\r
243 // put the form into the window
\r
244 $('div.container-box', hash.w).html(data);
\r
245 $("div.loading-box", hash.w).hide();
\r
246 $('form input[name=splitform-splittext]', hash.w).val(hash.t.selection);
\r
247 $('form input[name=splitform-fulltext]', hash.w).val(hash.t.fulltext);
\r
248 $('div.container-box', hash.w).show();
\r
251 $('#split-dialog-button-accept').click(function() {
\r
252 self.postSplitRequest(onSuccess, onFailure);
\r
256 $('#split-dialog-button-close').click(function() {
\r
258 $('div.container-box', hash.w).html('');
\r
262 $('#split-dialog-button-dismiss').click(function() {
\r
264 $('div.container-box', hash.w).html('');
\r
268 if($('#id_splitform-autoxml').is(':checked'))
\r
269 $('#split-form-dc-subform').show();
\r
271 $('#split-form-dc-subform').hide();
\r
273 $('#id_splitform-autoxml').change(function() {
\r
274 if( $(this).is(':checked') )
\r
275 $('#split-form-dc-subform').show();
\r
277 $('#split-form-dc-subform').hide();
\r
284 success: onSuccess,
\r
291 /* Refreshing routine */
\r
292 Editor.prototype.refreshPanels = function() {
\r
295 self.allPanels().each(function() {
\r
296 var panel = $(this).data('ctrl');
\r
297 $.log('Refreshing: ', this, panel);
\r
298 if ( panel.changed() )
\r
299 panel.unmarkChanged();
\r
304 $('#toolbar-button-save').attr('disabled', 'disabled');
\r
305 $('#toolbar-button-commit').removeAttr('disabled');
\r
306 $('#toolbar-button-update').removeAttr('disabled');
\r
312 Editor.prototype.showPopup = function(name, text, timeout)
\r
314 timeout = timeout || 4000;
\r
316 self.popupQueue.push( [name, text, timeout] )
\r
318 if( self.popupQueue.length > 1)
\r
321 var box = $('#message-box > #' + name);
\r
322 $('*.data', box).html(text || '');
\r
326 setTimeout( $.fbind(self, self.advancePopupQueue), timeout);
\r
329 Editor.prototype.advancePopupQueue = function() {
\r
331 var elem = this.popupQueue.shift();
\r
333 var box = $('#message-box > #' + elem[0]);
\r
335 box.fadeOut(100, function()
\r
337 $('*.data', box).html('');
\r
339 if( self.popupQueue.length > 0) {
\r
340 var ibox = $('#message-box > #' + self.popupQueue[0][0]);
\r
341 $('*.data', ibox).html(self.popupQueue[0][1] || '');
\r
343 if(self.popupQueue[0][2] > 0)
\r
344 setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);
\r