X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/c7917ce18f0f62eac89e1eb4b6ae6d8c48133600..96647893c5a1e2c675fc2b1bf1d7ca16fe3253b8:/project/static/js/panels.js diff --git a/project/static/js/panels.js b/project/static/js/panels.js index d5fc757d..d04b4212 100644 --- a/project/static/js/panels.js +++ b/project/static/js/panels.js @@ -1,52 +1,67 @@ -function loadPanel(target, url) { - $.log('ajax', url, 'into', target); - $(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) { - $.log(target, 'ajax success'); - $(target).html(data); - $.log(target, 'triggering panel:load'); - $(document).trigger('panel:load', target); - // panel(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) { - $.log('Panel', panel, 'unloading'); - $(document).unbind('panel:unload.' + eventId); - $(panel).html(''); - unload(event, panel); - $.log('Panel', panel, 'unloaded'); - 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; - $.log('Panel', panel, 'loading'); - $(document).bind('panel:unload.' + eventId, unloadHandler); - load(event, panel); - $.log('Panel', panel, 'loaded'); - }); } + +/* + * 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() ); }); });