From: Łukasz Rekucki Date: Tue, 25 Aug 2009 16:06:51 +0000 (+0200) Subject: Panele posiadaja teraz obiekt kontroller, który trzyma ich stan. TODO: lepsza inicjal... X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/4af60771b6c6a164465057e08bdbc2de583410a8?hp=1fc8724242d7f5bbba51812a118d86aead57f32b Panele posiadaja teraz obiekt kontroller, który trzyma ich stan. TODO: lepsza inicjalizacja zachowań z wczytanego JS. --- diff --git a/project/static/js/editor.js b/project/static/js/editor.js new file mode 100644 index 00000000..3cd59f0f --- /dev/null +++ b/project/static/js/editor.js @@ -0,0 +1,31 @@ +$(function() +{ + function saveToBranch(data) { + $.log('Saving to local branch'); + var changed_panel = $('.panel-wrap.changed'); + + if( changed_panel.length == 0) + return; /* no changes */ + + if( changed_panel.length > 1) + alert('Błąd: więcej niż jeden panel został zmodyfikowany. Nie można zapisać.'); + + save_data = changed_panel.data('ctrl').saveData(); + + $.ajax({ + url: location.href, + dataType: 'json', + success: function(data, textStatus) { + $.log('Success:', data); + }, + error: function(rq, tstat, err) { + $.log('save error', rq, tstat, err); + }, + type: 'POST', + data: save_data + }); + } + + $('#toolbar-button-save').click(saveToBranch); +}); + diff --git a/project/static/js/panels.js b/project/static/js/panels.js index c53d1354..d04b4212 100644 --- a/project/static/js/panels.js +++ b/project/static/js/panels.js @@ -1,46 +1,67 @@ -function loadPanel(target, url) { - $.log('ajax', url, 'into', target); - $('.change-notification', $(target).parent()).fadeOut(); - $(document).trigger('panel:unload', target); +function Panel(target) { + var self = this; + this.target = target; + this.instanceId = Math.ceil(Math.random() * 1000000000); + $.log('new panel - target: ', this.target); + $(document).bind('panel:unload.' + this.instanceId, + function(event, data) { self.unload(event, data); }); +} + +Panel.prototype.load = function (url) { + $.log('preparing xhr load: ', this.target); + $('.change-notification', $(this.target).parent()).fadeOut(); + $(document).trigger('panel:unload', this.target); + var self = this; + $.ajax({ url: url, dataType: 'html', - success: function(data, textStatus) { - $(target).html(data); - $(document).trigger('panel:load', target); - }, + success: function(data, tstat) { + load_callback = unload_callback = null; + $(self.target).html(data); + self._onUnload = unload_callback; + + if(load_callback != null) { + $.log('Invoking panel load callback.'); + load_callback(self); + } + }, error: function(request, textStatus, errorThrown) { - $.log('ajax', url, target, 'error:', textStatus, errorThrown); + $.log('ajax', url, this.target, 'error:', textStatus, errorThrown); } }); } -// Funkcja do tworzenia nowych paneli -function panel(load, unload) { - var self = null; - var eventId = Math.ceil(Math.random() * 1000000000); - - unloadHandler = function(event, panel) { - if (self && self == panel) { - $(document).unbind('panel:unload.' + eventId); - $(panel).html(''); - unload(event, panel); - return false; - } +Panel.prototype.unload = function(event, data) { + $.log('got unload signal', this.target, ' target: ', data); + if(this.target == data) { + $(document).unbind('panel:unload.' + this.instanceId); + $(this.target).html(''); + if(this._onUnload != null) this._onUnload(this); + return false; }; - - $(document).one('panel:load', function(event, panel) { - self = panel; - $(document).bind('panel:unload.' + eventId, unloadHandler); - load(event, panel); - }); } + +/* + * Return the data that should be saved + */ +Panel.prototype.saveData = function() { + return ""; +} + + $(function() { $('#panels').makeHorizPanel({}); $('#panels').css('top', ($('#header').outerHeight() ) + 'px'); + + $('.panel-content').each(function() { + var ctrl = new Panel(this); + $(this).data('ctrl', ctrl); + }); $('.panel-toolbar select').change(function() { - loadPanel($('.panel-content', $(this).parent().parent()), $(this).val()) + var panel = $('.panel-content', $(this).parent().parent()); + $(panel).data('ctrl').load( $(this).val() ); }); }); diff --git a/project/templates/explorer/file_xml.html b/project/templates/explorer/file_xml.html index 58219def..33e88028 100644 --- a/project/templates/explorer/file_xml.html +++ b/project/templates/explorer/file_xml.html @@ -7,7 +7,7 @@ - + {% endblock extrahead %} {% block breadcrumbs %}Platforma Redakcyjna ❯ plik {{ hash }}{% endblock breadcrumbs %} diff --git a/project/templates/explorer/panels/gallery.html b/project/templates/explorer/panels/gallery.html index 60935bcd..6c44a19b 100644 --- a/project/templates/explorer/panels/gallery.html +++ b/project/templates/explorer/panels/gallery.html @@ -10,6 +10,7 @@ diff --git a/project/templates/explorer/panels/xmleditor.html b/project/templates/explorer/panels/xmleditor.html index 0c8724fd..dfe94774 100644 --- a/project/templates/explorer/panels/xmleditor.html +++ b/project/templates/explorer/panels/xmleditor.html @@ -7,6 +7,7 @@