From: Łukasz Rekucki Date: Thu, 10 Sep 2009 15:02:03 +0000 (+0200) Subject: Merge branch 'master' of git@stigma:platforma X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/f31bb368a2cad9a61e4fc652fa4b40c4114a128c?ds=sidebyside;hp=-c Merge branch 'master' of git@stigma:platforma Conflicts: project/static/js/editor.js setupUI przeniesione do editor.ui.js --- f31bb368a2cad9a61e4fc652fa4b40c4114a128c diff --combined project/static/js/editor.js index 36dfcf27,11574373..46d39419 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@@ -6,6 -6,7 +6,6 @@@ function Hotkey(code) this.character = String.fromCharCode(code & 0xff) } - Hotkey.prototype.toString = function() { mods = [] if(this.has_alt) mods.push('Alt') @@@ -21,7 -22,7 +21,7 @@@ function Panel(panelWrap) self.wrap = panelWrap; self.contentDiv = $('.panel-content', panelWrap); self.instanceId = Math.ceil(Math.random() * 1000000000); - $.log('new panel - wrap: ', self.wrap); + // $.log('new panel - wrap: ', self.wrap); $(document).bind('panel:unload.' + self.instanceId, function(event, data) { @@@ -45,7 -46,7 +45,7 @@@ Panel.prototype.callHook = function() var noHookAction = args.splice(0,1)[0] var result = false; - $.log('calling hook: ', hookName, 'with args: ', args); + // $.log('calling hook: ', hookName, 'with args: ', args); if(this.hooks && this.hooks[hookName]) result = this.hooks[hookName].apply(this, args); else if (noHookAction instanceof Function) @@@ -54,7 -55,7 +54,7 @@@ } Panel.prototype.load = function (url) { - $.log('preparing xhr load: ', this.wrap); + // $.log('preparing xhr load: ', this.wrap); $(document).trigger('panel:unload', this); var self = this; self.current_url = url; @@@ -79,8 -80,10 +79,8 @@@ } Panel.prototype.unload = function(event, data) { - $.log('got unload signal', this, ' target: ', data); - - if( data == this ) { - $.log('unloading', this); + // $.log('got unload signal', this, ' target: ', data); + if( data == this ) { $(this.contentDiv).html(''); // disconnect the toolbar @@@ -105,7 -108,7 +105,7 @@@ Panel.prototype.refresh = function(even } Panel.prototype.otherPanelChanged = function(other) { - $.log('panel ', other, ' changed.'); + $.log('Panel ', this, ' is aware that ', other, ' changed.'); if(!this.callHook('dirty')) $('.change-notification', this.wrap).fadeIn(); } @@@ -135,7 -138,7 +135,7 @@@ Panel.prototype.connectToolbar = functi // check if there is a one var toolbar = $("div.toolbar", this.contentDiv); - $.log('Connecting toolbar', toolbar); + // $.log('Connecting toolbar', toolbar); if(toolbar.length == 0) return; // move the extra @@@ -185,9 -188,9 +185,9 @@@ try { var params = $.evalJSON(button.attr('ui:action-params')); } catch(object) { - $.log('JSON exception in ', button, ': ', object); - button.attr('disabled', 'disabled'); - return; + $.log('JSON exception in ', button, ': ', object); + button.attr('disabled', 'disabled'); + return; } var callback = function() { @@@ -200,7 -203,7 +200,7 @@@ // connect hotkey if(hk) { self.hotkeys[hk.code] = callback; - $.log('hotkey', hk); + // $.log('hotkey', hk); } // tooltip @@@ -260,6 -263,60 +260,6 @@@ function Editor( this.scriplets = {}; } -Editor.prototype.setupUI = function() { - // set up the UI visually and attach callbacks - var self = this; - - self.rootDiv.makeHorizPanel({}); // TODO: this probably doesn't belong into jQuery - // self.rootcDiv.css('top', ($('#header').outerHeight() ) + 'px'); - - $('#panels > *.panel-wrap').each(function() { - var panelWrap = $(this); - $.log('wrap: ', panelWrap); - var panel = new Panel(panelWrap); - panelWrap.data('ctrl', panel); // attach controllers to wraps - panel.load($('.panel-toolbar select', panelWrap).val()); - - $('.panel-toolbar select', panelWrap).change(function() { - var url = $(this).val(); - self.savePanelOptions(); - panelWrap.data('ctrl').load(url); - }); - - $('.panel-toolbar button.refresh-button', panelWrap).click( - function() { - panel.refresh(); - } ); - }); - - $(document).bind('panel:contentChanged', function() { - self.onContentChanged.apply(self, arguments) - }); - - $('#toolbar-button-save').click( function (event, data) { - self.saveToBranch(); - } ); - - $('#toolbar-button-update').click( function (event, data) { - if (self.updateUserBranch()) { - // commit/update can be called only after proper, save - // this means all panels are clean, and will get refreshed - // do this only, when there are any changes to local branch - self.refreshPanels(); - } - } ); - - $('#toolbar-button-commit').click( function (event, data) { - self.sendPullRequest(); - event.preventDefault(); - event.stopPropagation(); - return false; - } ); - self.rootDiv.bind('stopResize', function() { - self.savePanelOptions() - }); -} - Editor.prototype.loadConfig = function() { // Load options from cookie var defaultOptions = { @@@ -310,9 -367,11 +310,11 @@@ Editor.prototype.loadPanelOptions = fun totalWidth += panelWidth; } $.log('panel:', this, $(this).css('left')); - $('.panel-toolbar select', this).val( - $('.panel-toolbar option[name=' + self.options.panels[index].name + ']', this).attr('value') - ) + $('.panel-toolbar option', this).each(function() { + if ($(this).attr('p:panel-name') == self.options.panels[index].name) { + $(this).parent('select').val($(this).attr('value')); + } + }); }); } @@@ -321,7 -380,7 +323,7 @@@ Editor.prototype.savePanelOptions = fun var panels = []; $('.panel-wrap', self.rootDiv).not('.panel-content-overlay').each(function() { panels.push({ - name: $('.panel-toolbar option:selected', this).attr('name'), + name: $('.panel-toolbar option:selected', this).attr('p:panel-name'), ratio: $(this).width() / self.rootDiv.width() }) }); @@@ -421,6 -480,20 +423,6 @@@ Editor.prototype.onContentChanged = fun }, 300000 ); }; -Editor.prototype.refreshPanels = function() { - var self = this; - - self.allPanels().each(function() { - var panel = $(this).data('ctrl'); - $.log('Refreshing: ', this, panel); - if ( panel.changed() ) - panel.unmarkChanged(); - else - panel.refresh(); - }); -}; - - Editor.prototype.updateUserBranch = function() { if( $('.panel-wrap.changed').length != 0) alert("There are unsaved changes - can't update."); @@@ -428,81 -501,108 +430,81 @@@ var self = this; $.ajax({ url: $('#toolbar-button-update').attr('ui:ajax-action'), - dataType: 'json', - success: function(data, textStatus) { - switch(data.result) { - case 'done': - self.showPopup('generic-yes', 'Plik uaktualniony.'); - self.refreshPanels() - break; - case 'nothing-to-do': - self.showPopup('generic-info', 'Brak zmian do uaktualnienia.'); - break; - default: - self.showPopup('generic-error', data.errors && data.errors[0]); - } - }, - error: function(rq, tstat, err) { - self.showPopup('generic-error', 'Błąd serwera: ' + err); - }, - type: 'POST', - data: {} + dataType: 'json', + success: function(data, textStatus) { + switch(data.result) { + case 'done': + self.showPopup('generic-yes', 'Plik uaktualniony.'); + self.refreshPanels() + break; + case 'nothing-to-do': + self.showPopup('generic-info', 'Brak zmian do uaktualnienia.'); + break; + default: + self.showPopup('generic-error', data.errors && data.errors[0]); + } + }, + error: function(rq, tstat, err) { + self.showPopup('generic-error', 'Błąd serwera: ' + err); + }, + type: 'POST', + data: {} }); } -Editor.prototype.sendPullRequest = function () { +Editor.prototype.sendMergeRequest = function (message) { if( $('.panel-wrap.changed').length != 0) alert("There are unsaved changes - can't commit."); var self = this; - - /* this.showPopup('not-implemented'); */ - - $.log('URL !: ', $('#toolbar-commit-form').attr('action')); + $.log('URL !: ', $('#commit-dialog form').attr('action')); $.ajax({ - url: $('#toolbar-commit-form').attr('action'), - dataType: 'json', - success: function(data, textStatus) { - switch(data.result) { - case 'done': - self.showPopup('generic-yes', 'Łączenie zmian powiodło się.'); - - if(data.localmodified) - self.refreshPanels() + url: $('#commit-dialog form').attr('action'), + dataType: 'json', + success: function(data, textStatus) { + switch(data.result) { + case 'done': + self.showPopup('generic-yes', 'Łączenie zmian powiodło się.'); + + if(data.localmodified) + self.refreshPanels() - break; - case 'nothing-to-do': - self.showPopup('generic-info', 'Brak zmian do połaczenia.'); - break; - default: - self.showPopup('generic-error', data.errors && data.errors[0]); - } - }, - error: function(rq, tstat, err) { - self.showPopup('generic-error', 'Błąd serwera: ' + err); - }, - type: 'POST', - data: {'message': $('#toolbar-commit-message').val() } + break; + case 'nothing-to-do': + self.showPopup('generic-info', 'Brak zmian do połaczenia.'); + break; + default: + self.showPopup('generic-error', data.errors && data.errors[0]); + } + }, + error: function(rq, tstat, err) { + self.showPopup('generic-error', 'Błąd serwera: ' + err); + }, + type: 'POST', + data: { + 'message': message + } }); } -Editor.prototype.showPopup = function(name, text, timeout) +Editor.prototype.postSplitRequest = function(s, f) { - timeout = timeout || 4000; - var self = this; - self.popupQueue.push( [name, text, timeout] ) - - if( self.popupQueue.length > 1) - return; - - var box = $('#message-box > #' + name); - $('*.data', box).html(text || ''); - box.fadeIn(100); - - if(timeout > 0) - setTimeout( $.fbind(self, self.advancePopupQueue), timeout); + $.ajax({ + url: $('#split-dialog form').attr('action'), + dataType: 'html', + success: s, + error: f, + type: 'POST', + data: $('#split-dialog form').serialize() + }); }; -Editor.prototype.advancePopupQueue = function() { - var self = this; - var elem = this.popupQueue.shift(); - if(elem) { - var box = $('#message-box > #' + elem[0]); - - box.fadeOut(100, function() - { - $('*.data', box).html(''); - - if( self.popupQueue.length > 0) { - var ibox = $('#message-box > #' + self.popupQueue[0][0]); - $('*.data', ibox).html(self.popupQueue[0][1] || ''); - ibox.fadeIn(100); - if(self.popupQueue[0][2] > 0) - setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]); - } - }); - } -}; Editor.prototype.allPanels = function() { return $('#' + this.rootDiv.attr('id') +' > *.panel-wrap', this.rootDiv.parent()); } - Editor.prototype.registerScriptlet = function(scriptlet_id, scriptlet_func) { // I briefly assume, that it's verified not to break the world on SS diff --combined project/static/js/editor.ui.js index b27daace,00000000..59c3f754 mode 100755,000000..100755 --- a/project/static/js/editor.ui.js +++ b/project/static/js/editor.ui.js @@@ -1,297 -1,0 +1,297 @@@ +/* + * UI related Editor methods + */ +Editor.prototype.setupUI = function() { + // set up the UI visually and attach callbacks + var self = this; + + var resize_start = function(event, mydata) { + $(document).bind('mousemove', mydata, resize_changed). + bind('mouseup', mydata, resize_stop); + + $('.panel-overlay', mydata.root).css('display', 'block'); + return false; + } + var resize_changed = function(event) { + var old_width = parseInt(event.data.overlay.css('width')); + var delta = event.pageX + event.data.hotspot_x - old_width; + event.data.overlay.css({ + 'width': old_width + delta + }); + + if(event.data.overlay.next) { + var left = parseInt(event.data.overlay.next.css('left')); + event.data.overlay.next.css('left', left+delta); + } + + return false; + }; + + var resize_stop = function(event) { + $(document).unbind('mousemove', resize_changed).unbind('mouseup', resize_stop); + // $('.panel-content', event.data.root).css('display', 'block'); + var overlays = $('.panel-content-overlay', event.data.root); + $('.panel-content-overlay', event.data.root).each(function(i) { + if( $(this).data('panel').hasClass('last-panel') ) + $(this).data('panel').css({ + 'left': $(this).css('left'), + 'right': $(this).css('right') + }); + else + $(this).data('panel').css({ + 'left': $(this).css('left'), + 'width': $(this).css('width') + }); + }); + $('.panel-overlay', event.data.root).css('display', 'none'); + $(event.data.root).trigger('stopResize'); + }; + + /* + * Prepare panels (overlays & stuff) + */ + /* create an overlay */ + var panel_root = self.rootDiv; + var overlay_root = $("
"); + panel_root.append(overlay_root); + + var prev = null; + + $('*.panel-wrap', panel_root).each( function() + { + var panel = $(this); + var handle = $('.panel-slider', panel); + var overlay = $("
 
"); + overlay_root.append(overlay); + overlay.data('panel', panel); + overlay.data('next', null); + + if (prev) prev.next = overlay; + + if( panel.hasClass('last-panel') ) + { + overlay.css({ + 'left': panel.css('left'), + 'right': panel.css('right') + }); + } + else { + overlay.css({ + 'left': panel.css('left'), + 'width': panel.css('width') + }); + // $.log('Has handle: ' + panel.attr('id')); + overlay.append(handle.clone()); + /* attach the trigger */ + handle.mousedown(function(event) { + var touch_data = { + root: panel_root, + overlay: overlay, + hotspot_x: event.pageX - handle.position().left + }; + + $(this).trigger('hpanel:panel-resize-start', touch_data); + return false; + }); + $('.panel-content', panel).css('right', + (handle.outerWidth() || 10) + 'px'); + $('.panel-content-overlay', panel).css('right', + (handle.outerWidth() || 10) + 'px'); + }; + + prev = overlay; + }); + + panel_root.bind('hpanel:panel-resize-start', resize_start); + self.rootDiv.bind('stopResize', function() { + self.savePanelOptions() + }); - ++ + /* + * Connect panel actions + */ + $('#panels > *.panel-wrap').each(function() { + var panelWrap = $(this); + // $.log('wrap: ', panelWrap); + var panel = new Panel(panelWrap); + panelWrap.data('ctrl', panel); // attach controllers to wraps + panel.load($('.panel-toolbar select', panelWrap).val()); + + $('.panel-toolbar select', panelWrap).change(function() { + var url = $(this).val(); + panelWrap.data('ctrl').load(url); + self.savePanelOptions(); + }); + + $('.panel-toolbar button.refresh-button', panelWrap).click( + function() { + panel.refresh(); + } ); + }); + + $(document).bind('panel:contentChanged', function() { + self.onContentChanged.apply(self, arguments) + }); + + /* + * Connect various buttons + */ + + $('#toolbar-button-save').click( function (event, data) { + self.saveToBranch(); + } ); + + $('#toolbar-button-update').click( function (event, data) { + if (self.updateUserBranch()) { + // commit/update can be called only after proper, save + // this means all panels are clean, and will get refreshed + // do this only, when there are any changes to local branch + self.refreshPanels(); + } + } ); + + /* COMMIT DIALOG */ + $('#commit-dialog'). + jqm({ + modal: true, + trigger: '#toolbar-button-commit' + }); + + $('#commit-dialog-cancel-button').click(function() { + $('#commit-dialog-error-empty-message').hide(); + $('#commit-dialog').jqmHide(); + }); + + $('#commit-dialog-save-button').click( function (event, data) + { + if( $('#commit-dialog-message').val().match(/^\s*$/)) { + $('#commit-dialog-error-empty-message').fadeIn(); + } + else { + $('#commit-dialog-error-empty-message').hide(); + $('#commit-dialog').jqmHide(); + self.sendMergeRequest($('#commit-dialog-message').val() ); + } + + return false; + }); + + /* SPLIT DIALOG */ + $('#split-dialog').jqm({ + modal: true, + onShow: $.fbind(self, self.loadSplitDialog) + }). + jqmAddClose('button.dialog-close-button'); + +// $('#split-dialog'). +} + +Editor.prototype.loadSplitDialog = function(hash) +{ + var self = this; + + $("div.loading-box", hash.w).show(); + $("div.fatal-error-box", hash.w).hide(); + $('div.container-box', hash.w).hide(); + hash.w.show(); + + function onFailure(rq, tstat, err) { + $('div.container-box', hash.w).html(''); + $("div.loading-box", hash.w).hide(); + $("div.fatal-error-box", hash.w).show(); + hash.t.failure(); + }; + + function onSuccess(data, status) { + // put the form into the window + $('div.container-box', hash.w).html(data); + $("div.loading-box", hash.w).hide(); + $('form input[name=splittext]', hash.w).val(hash.t.selection); + $('form input[name=fulltext]', hash.w).val(hash.t.fulltext); + $('div.container-box', hash.w).show(); + + // connect buttons + $('#split-dialog-button-accept').click(function() { + self.postSplitRequest(onSuccess, onFailure); + return false; + }); + + $('#split-dialog-button-close').click(function() { + hash.w.jqmHide(); + $('div.container-box', hash.w).html(''); + hash.t.failure(); + }); + + $('#split-dialog-button-dismiss').click(function() { + hash.w.jqmHide(); + $('div.container-box', hash.w).html(''); + }); + }; + + $.ajax({ + url: 'split', + dataType: 'html', + success: onSuccess, + error: onFailure, + type: 'GET', + data: {} + }); +} + +/* Refreshing routine */ +Editor.prototype.refreshPanels = function() { + var self = this; + + self.allPanels().each(function() { + var panel = $(this).data('ctrl'); + $.log('Refreshing: ', this, panel); + if ( panel.changed() ) + panel.unmarkChanged(); + else + panel.refresh(); + }); +}; + + +/* + * Pop-up messages + */ +Editor.prototype.showPopup = function(name, text, timeout) +{ + timeout = timeout || 4000; + var self = this; + self.popupQueue.push( [name, text, timeout] ) + + if( self.popupQueue.length > 1) + return; + + var box = $('#message-box > #' + name); + $('*.data', box).html(text || ''); + box.fadeIn(100); + + if(timeout > 0) + setTimeout( $.fbind(self, self.advancePopupQueue), timeout); +}; + +Editor.prototype.advancePopupQueue = function() { + var self = this; + var elem = this.popupQueue.shift(); + if(elem) { + var box = $('#message-box > #' + elem[0]); + + box.fadeOut(100, function() + { + $('*.data', box).html(''); + + if( self.popupQueue.length > 0) { + var ibox = $('#message-box > #' + self.popupQueue[0][0]); + $('*.data', ibox).html(self.popupQueue[0][1] || ''); + ibox.fadeIn(100); + if(self.popupQueue[0][2] > 0) + setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]); + } + }); + } +}; + + diff --combined project/templates/explorer/editor.html index 2263f02e,2aaf26e9..b37d5be6 --- a/project/templates/explorer/editor.html +++ b/project/templates/explorer/editor.html @@@ -2,17 -2,15 +2,17 @@@ {% block extrahead %} + - + - - + + + {% endblock extrahead %} {% block extrabody %} @@@ -32,8 -30,10 +32,8 @@@ {% block header-toolbar %} -
- - -
+ + @@@ -61,7 -61,7 +61,7 @@@

@@@ -79,27 -79,4 +79,27 @@@ {% endfor %} +

+
+ + +

Wiadomość nie może być pusta.

+

+ + +

+
+
+ +
+
+ + +
{% endblock maincontent %}