Zapisywanie i odczytywanie ustawień paneli z cookie. Potrzebne jest jeszcze ustawiani...
[redakcja.git] / project / static / js / editor.js
index 4e867b7..8d75525 100644 (file)
@@ -106,26 +106,85 @@ Editor.prototype.setupUI = function() {
        var panelRoot = $('#panels');
        self.rootDiv = panelRoot;
 
+    // Set panel widths from options.panels
+    if (self.options && self.options.panels) {
+        var totalWidth = 0;
+        $('.panel-wrap', panelRoot).each(function(index) {
+            var panelWidth = self.options.panels[index].ratio * panelRoot.width();
+            if ($(this).hasClass('last-panel')) {
+                $(this).css({
+                    left: totalWidth,
+                    right: 0,
+                });
+            } else {
+                $(this).css({
+                    left: totalWidth,
+                    width: panelWidth,
+                });
+                totalWidth += panelWidth;               
+            }
+            $('.panel-toolbar select', this).val(
+                $('.panel-toolbar option[name=' + self.options.panels[index].name + ']', this).attr('value')
+            )
+        });
+    }
+    
        panelRoot.makeHorizPanel({}); // TODO: this probably doesn't belong into jQuery
     panelRoot.css('top', ($('#header').outerHeight() ) + 'px');
-
+    
        $('#panels > *.panel-wrap').each(function() {
                var panelWrap = $(this);
                $.log('wrap: ', panelWrap);
-               panelWrap.data('ctrl', new Panel(panelWrap)); // attach controllers to wraps
-
+               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() {
-                       panelWrap.data('ctrl').load( $(this).val() );
+               var url = $(this).val();
+                       panelWrap.data('ctrl').load(url);
+                       var panels = [];
+                       $('.panel-wrap', panelRoot).not('.panel-content-overlay').each(function(index) {
+                panels.push({
+                    name: $('.panel-toolbar option:selected', this).attr('name'),
+                    ratio: $(this).width() / panelRoot.width()
+                })
+                       });
+                       self.options.panels = panels;
+            $.log($.toJSON(self.options));
+            $.cookie('options', $.toJSON(self.options), { expires: 7, path: '/'});
            });
        });     
-
+    
        $('#toolbar-button-save').click( function (event, data) { self.saveToBranch(); } );
-
-
+    
+    panelRoot.bind('stopResize', function() {
+        var panels = [];
+        $('.panel-wrap', panelRoot).not('.panel-content-overlay').each(function() {
+            panels.push({
+                name: $('.panel-toolbar option:selected', this).attr('name'),
+                ratio: $(this).width() / panelRoot.width()
+            })
+        });
+        self.options.panels = panels;
+        $.log($.toJSON(self.options));
+        $.cookie('options', $.toJSON(self.options), { expires: 7, path: '/'});
+    });
 }
 
 Editor.prototype.loadConfig = function() {
-       // load options from cookie 
+    // Load options from cookie
+    try {
+       var cookie = $.cookie('options');
+        this.options = $.secureEvalJSON(cookie);
+    } catch (e) {        
+        this.options = {
+            panels: [
+                {name: 'htmleditor', ratio: 0.5},
+                {name: 'gallery', ratio: 0.5}
+            ]
+        }
+    }
+    $.log(this.options);
 }
 
 Editor.prototype.saveToBranch = function() {