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
18 event.data.overlay.css({
\r
19 'width': old_width + delta
\r
22 if(event.data.overlay.next) {
\r
23 var left = parseInt(event.data.overlay.next.css('left'));
\r
24 event.data.overlay.next.css('left', left+delta);
\r
30 var resize_stop = function(event) {
\r
31 $(document).unbind('mousemove', resize_changed).unbind('mouseup', resize_stop);
\r
32 // $('.panel-content', event.data.root).css('display', 'block');
\r
33 var overlays = $('.panel-content-overlay', event.data.root);
\r
34 $('.panel-content-overlay', event.data.root).each(function(i) {
\r
35 if( $(this).data('panel').hasClass('last-panel') )
\r
36 $(this).data('panel').css({
\r
37 'left': $(this).css('left'),
\r
38 'right': $(this).css('right')
\r
41 $(this).data('panel').css({
\r
42 'left': $(this).css('left'),
\r
43 'width': $(this).css('width')
\r
46 $('.panel-overlay', event.data.root).css('display', 'none');
\r
47 $(event.data.root).trigger('stopResize');
\r
51 * Prepare panels (overlays & stuff)
\r
53 /* create an overlay */
\r
54 var panel_root = self.rootDiv;
\r
55 var overlay_root = $("<div class='panel-overlay'></div>");
\r
56 panel_root.append(overlay_root);
\r
60 $('*.panel-wrap', panel_root).each( function()
\r
62 var panel = $(this);
\r
63 var handle = $('.panel-slider', panel);
\r
64 var overlay = $("<div class='panel-content-overlay panel-wrap'> </div>");
\r
65 overlay_root.append(overlay);
\r
66 overlay.data('panel', panel);
\r
67 overlay.data('next', null);
\r
69 if (prev) prev.next = overlay;
\r
71 if( panel.hasClass('last-panel') )
\r
74 'left': panel.css('left'),
\r
75 'right': panel.css('right')
\r
80 'left': panel.css('left'),
\r
81 'width': panel.css('width')
\r
83 // $.log('Has handle: ' + panel.attr('id'));
\r
84 overlay.append(handle.clone());
\r
85 /* attach the trigger */
\r
86 handle.mousedown(function(event) {
\r
90 hotspot_x: event.pageX - handle.position().left
\r
93 $(this).trigger('hpanel:panel-resize-start', touch_data);
\r
96 $('.panel-content', panel).css('right',
\r
97 (handle.outerWidth() || 10) + 'px');
\r
98 $('.panel-content-overlay', panel).css('right',
\r
99 (handle.outerWidth() || 10) + 'px');
\r
105 panel_root.bind('hpanel:panel-resize-start', resize_start);
\r
106 self.rootDiv.bind('stopResize', function() {
\r
107 self.savePanelOptions()
\r
111 * Connect panel actions
\r
113 $('#panels > *.panel-wrap').each(function() {
\r
114 var panelWrap = $(this);
\r
115 // $.log('wrap: ', panelWrap);
\r
116 var panel = new Panel(panelWrap);
\r
117 panelWrap.data('ctrl', panel); // attach controllers to wraps
\r
118 panel.load($('.panel-toolbar select', panelWrap).val());
\r
120 $('.panel-toolbar select', panelWrap).change(function() {
\r
121 var url = $(this).val();
\r
122 panelWrap.data('ctrl').load(url);
\r
123 self.savePanelOptions();
\r
126 $('.panel-toolbar button.refresh-button', panelWrap).click(
\r
132 $(document).bind('panel:contentChanged', function() {
\r
133 self.onContentChanged.apply(self, arguments)
\r
137 * Connect various buttons
\r
140 $('#toolbar-button-save').click( function (event, data) {
\r
141 self.saveToBranch();
\r
144 $('#toolbar-button-update').click( function (event, data) {
\r
145 if (self.updateUserBranch()) {
\r
146 // commit/update can be called only after proper, save
\r
147 // this means all panels are clean, and will get refreshed
\r
148 // do this only, when there are any changes to local branch
\r
149 self.refreshPanels();
\r
153 /* COMMIT DIALOG */
\r
154 $('#commit-dialog').
\r
157 trigger: '#toolbar-button-commit'
\r
160 $('#commit-dialog-cancel-button').click(function() {
\r
161 $('#commit-dialog-error-empty-message').hide();
\r
162 $('#commit-dialog').jqmHide();
\r
165 $('#commit-dialog-save-button').click( function (event, data)
\r
167 if( $('#commit-dialog-message').val().match(/^\s*$/)) {
\r
168 $('#commit-dialog-error-empty-message').fadeIn();
\r
171 $('#commit-dialog-error-empty-message').hide();
\r
172 $('#commit-dialog').jqmHide();
\r
173 self.sendMergeRequest($('#commit-dialog-message').val() );
\r
180 $('#split-dialog').jqm({
\r
182 onShow: $.fbind(self, self.loadSplitDialog)
\r
184 jqmAddClose('button.dialog-close-button');
\r
186 // $('#split-dialog').
\r
189 Editor.prototype.loadSplitDialog = function(hash)
\r
193 $("div.loading-box", hash.w).show();
\r
194 $("div.fatal-error-box", hash.w).hide();
\r
195 $('div.container-box', hash.w).hide();
\r
198 function onFailure(rq, tstat, err) {
\r
199 $('div.container-box', hash.w).html('');
\r
200 $("div.loading-box", hash.w).hide();
\r
201 $("div.fatal-error-box", hash.w).show();
\r
205 function onSuccess(data, status) {
\r
206 // put the form into the window
\r
207 $('div.container-box', hash.w).html(data);
\r
208 $("div.loading-box", hash.w).hide();
\r
209 $('form input[name=splittext]', hash.w).val(hash.t.selection);
\r
210 $('form input[name=fulltext]', hash.w).val(hash.t.fulltext);
\r
211 $('div.container-box', hash.w).show();
\r
214 $('#split-dialog-button-accept').click(function() {
\r
215 self.postSplitRequest(onSuccess, onFailure);
\r
219 $('#split-dialog-button-close').click(function() {
\r
221 $('div.container-box', hash.w).html('');
\r
225 $('#split-dialog-button-dismiss').click(function() {
\r
227 $('div.container-box', hash.w).html('');
\r
234 success: onSuccess,
\r
241 /* Refreshing routine */
\r
242 Editor.prototype.refreshPanels = function() {
\r
245 self.allPanels().each(function() {
\r
246 var panel = $(this).data('ctrl');
\r
247 $.log('Refreshing: ', this, panel);
\r
248 if ( panel.changed() )
\r
249 panel.unmarkChanged();
\r
259 Editor.prototype.showPopup = function(name, text, timeout)
\r
261 timeout = timeout || 4000;
\r
263 self.popupQueue.push( [name, text, timeout] )
\r
265 if( self.popupQueue.length > 1)
\r
268 var box = $('#message-box > #' + name);
\r
269 $('*.data', box).html(text || '');
\r
273 setTimeout( $.fbind(self, self.advancePopupQueue), timeout);
\r
276 Editor.prototype.advancePopupQueue = function() {
\r
278 var elem = this.popupQueue.shift();
\r
280 var box = $('#message-box > #' + elem[0]);
\r
282 box.fadeOut(100, function()
\r
284 $('*.data', box).html('');
\r
286 if( self.popupQueue.length > 0) {
\r
287 var ibox = $('#message-box > #' + self.popupQueue[0][0]);
\r
288 $('*.data', ibox).html(self.popupQueue[0][1] || '');
\r
290 if(self.popupQueue[0][2] > 0)
\r
291 setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);
\r