Fix #102: Nie można zmienić domyślnych paneli.
[redakcja.git] / project / static / js / editor.js
index f7f4cf3..1157437 100644 (file)
@@ -85,6 +85,10 @@ Panel.prototype.unload = function(event, data) {
     if( data == this ) {
         $.log('unloading', this);
         $(this.contentDiv).html('');
+
+        // disconnect the toolbar
+        $('div.panel-toolbar span.panel-toolbar-extra', this.wrap).empty();
+        
         this.callHook('unload');
         this.hooks = null; // flush the hooks
         return false;
@@ -137,6 +141,13 @@ Panel.prototype.connectToolbar = function()
     $.log('Connecting toolbar', toolbar);
     if(toolbar.length == 0) return;
 
+    // move the extra
+    var extra_buttons = $('span.panel-toolbar-extra', toolbar);
+    var placeholder = $('div.panel-toolbar span.panel-toolbar-extra', this.wrap);
+    placeholder.replaceWith(extra_buttons);
+
+    var action_buttons = $('button', extra_buttons);
+
     // connect group-switch buttons
     var group_buttons = $('*.toolbar-tabs-container button', toolbar);
 
@@ -165,8 +176,11 @@ Panel.prototype.connectToolbar = function()
     });
 
     // connect action buttons
-    var action_buttons = $('*.toolbar-button-groups-container button', toolbar);
-    action_buttons.each(function() {
+    var allbuttons = $.makeArray(action_buttons)
+    $.merge(allbuttons,
+        $.makeArray($('*.toolbar-button-groups-container button', toolbar)) );
+        
+    $(allbuttons).each(function() {
         var button = $(this);
         var hk = button.attr('ui:hotkey');
         if(hk) hk = new Hotkey( parseInt(hk) );
@@ -254,7 +268,7 @@ Editor.prototype.setupUI = function() {
     var self = this;
    
     self.rootDiv.makeHorizPanel({}); // TODO: this probably doesn't belong into jQuery
-    // self.rootDiv.css('top', ($('#header').outerHeight() ) + 'px');
+    // self.rootcDiv.css('top', ($('#header').outerHeight() ) + 'px');
     
     $('#panels > *.panel-wrap').each(function() {
         var panelWrap = $(this);
@@ -265,8 +279,8 @@ Editor.prototype.setupUI = function() {
         
         $('.panel-toolbar select', panelWrap).change(function() {
             var url = $(this).val();
-            panelWrap.data('ctrl').load(url);
             self.savePanelOptions();
+            panelWrap.data('ctrl').load(url);
         });
 
         $('.panel-toolbar button.refresh-button', panelWrap).click(
@@ -353,9 +367,11 @@ Editor.prototype.loadPanelOptions = function() {
             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'));
+            }
+        });
     });   
 }
 
@@ -364,7 +380,7 @@ Editor.prototype.savePanelOptions = function() {
     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()
         })
     });