Dodanie funkcji panel do tworzenia nowych paneli edytora i refaktoring xmleditor...
[redakcja.git] / project / static / js / panels.js
index e502861..eb1380d 100644 (file)
@@ -1,3 +1,39 @@
+function loadPanel(target, url) {
+    console.log('ajax', url, 'into', target);
+    $(document).trigger('panel:unload', target);
+    $.ajax({
+        url: url,
+        dataType: 'html',
+        success: function(data, textStatus) {
+            $(target).html(data);
+            $(document).trigger('panel:load', target);
+            // panel(target);
+        },
+        error: function(request, textStatus, errorThrown) {
+            console.log('ajax', url, 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, unloadHandler);
+            unload(event, panel);
+        }
+    };
+    
+    $(document).one('panel:load', function(event, panel) {
+        self = panel;
+        $(document).bind('panel:unload.' + eventId, unloadHandler);
+        load(event, panel);
+    });
+}
+
 $(function() {
     // ========================
     // = Resizable panels =
@@ -17,7 +53,7 @@ $(function() {
     resizePanels();
     
     $('.panel-toolbar select').change(function() {
-        console.log('loading panel', $(this).val(), 'into', $('.panel-contents', $(this).parent()));
+        loadPanel($('.panel-contents', $(this).parent().parent()), $(this).val())
     });
     // $('#id_folders').change(function() {
     //     $('#images').load('{% url folder_image_ajax %}' + $('#id_folders').val() + '/', function() {