testing west tabs
[roojs1] / Roo / bootstrap / layout / Region.js
index bf73fcd..cbfb668 100644 (file)
  * @class Roo.bootstrap.layout.Region
  * @extends Roo.bootstrap.layout.Basic
  * This class represents a region in a layout manager.
- * @cfg {Boolean}   collapsible     False to disable collapsing (defaults to true)
- * @cfg {Boolean}   collapsed       True to set the initial display to collapsed (defaults to false)
- * @cfg {Boolean}   floatable       False to disable floating (defaults to true)
  * @cfg {Object}    margins         Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
  * @cfg {Object}    cmargins        Margins for the element when collapsed (defaults to: north/south {top: 2, left: 0, right:0, bottom: 2} or east/west {top: 0, left: 2, right:2, bottom: 0})
  * @cfg {String}    tabPosition     (top|bottom) "top" or "bottom" (defaults to "bottom")
- * @cfg {String}    collapsedTitle  Optional string message to display in the collapsed block of a north or south region
  * @cfg {Boolean}   alwaysShowTabs  True to always display tabs even when there is only 1 panel (defaults to false)
  * @cfg {Boolean}   autoScroll      True to enable overflow scrolling (defaults to false)
  * @cfg {Boolean}   titlebar        True to display a title bar (defaults to true)
@@ -33,7 +30,8 @@
  *                      the space available, similar to FireFox 1.5 tabs (defaults to false)
  * @cfg {Number}    minTabWidth     The minimum tab width (defaults to 40)
  * @cfg {Number}    preferredTabWidth The preferred tab width (defaults to 150)
- * @cfg {Boolean}   showPin         True to show a pin button
+ * @cfg {String}    overflow       (hidden|visible) if you have menus in the region, then you need to set this to visible.
+
  * @cfg {Boolean}   hidden          True to start the region hidden (defaults to false)
  * @cfg {Boolean}   hideWhenEmpty   True to hide the region when it has no panels
  * @cfg {Boolean}   disableTabTips  True to disable tab tooltips
  * @cfg {Number}    height          For North/South panels
  * @cfg {Boolean}   split           To show the splitter
  * @cfg {Boolean}   toolbar         xtype configuration for a toolbar - shows on right of tabbar
+ * 
+ * @cfg {string}   cls             Extra CSS classes to add to region
+ * 
  * @cfg {Roo.bootstrap.layout.Manager}   mgr The manager
  * @cfg {string}   region  the region that it inhabits..
+ *
+
+ * @xxxcfg {Boolean}   collapsible     DISABLED False to disable collapsing (defaults to true)
+ * @xxxcfg {Boolean}   collapsed       DISABLED True to set the initial display to collapsed (defaults to false)
+
+ * @xxxcfg {String}    collapsedTitle  DISABLED Optional string message to display in the collapsed block of a north or south region
+ * @xxxxcfg {Boolean}   floatable       DISABLED False to disable floating (defaults to true)
+ * @xxxxcfg {Boolean}   showPin         True to show a pin button NOT SUPPORTED YET
  */
 Roo.bootstrap.layout.Region = function(config)
 {
-    
+    this.applyConfig(config);
+
     var mgr = config.mgr;
     var pos = config.region;
     config.skipConfig = true;
-    Roo.LayoutRegion.superclass.constructor.call(this, config);
-    var dh = Roo.DomHelper;
-    /** This region's container element 
-    * @type Roo.Element */
-    this.el = dh.append(mgr.el.dom, {tag: "div", cls: "roo-layout-panel roo-layout-panel-" + this.position}, true);
-    /** This region's title element 
-    * @type Roo.Element */
-
-    this.titleEl = dh.append(this.el.dom,
-        {
-                tag: "div",
-                unselectable: "on",
-                cls: "roo-unselectable roo-layout-panel-hd roo-layout-title-" + this.position,
-                children:[
-                    {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
-                    {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
-                ]}, true);
+    Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
     
-    this.titleEl.enableDisplayMode();
-    /** This region's title text element 
-    * @type HTMLElement */
-    this.titleTextEl = this.titleEl.dom.firstChild;
-    this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
-    
-    this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
-    this.closeBtn.enableDisplayMode();
-    this.closeBtn.on("click", this.closeClicked, this);
-    this.closeBtn.hide();
-
-    this.createBody(config);
+    if (mgr.el) {
+        this.onRender(mgr.el);   
+    }
+     
     this.visible = true;
     this.collapsed = false;
-
-    if(config.hideWhenEmpty){
-        this.hide();
-        this.on("paneladded", this.validateVisibility, this);
-        this.on("panelremoved", this.validateVisibility, this);
-    }
-    this.applyConfig(config);
+    this.unrendered_panels = [];
 };
 
 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
 
+    position: '', // set by wrapper (eg. north/south etc..)
+    unrendered_panels : null,  // unrendered panels.
+    
+    tabPosition : false,
+    
+    mgr: false, // points to 'Border'
+    
+    
     createBody : function(){
         /** This region's body element 
         * @type Roo.Element */
@@ -102,9 +90,81 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
         });
     },
 
+    onRender: function(ctr, pos)
+    {
+        var dh = Roo.DomHelper;
+        /** This region's container element 
+        * @type Roo.Element */
+        this.el = dh.append(ctr.dom, {
+                tag: "div",
+                cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
+            }, true);
+        /** This region's title element 
+        * @type Roo.Element */
+    
+        this.titleEl = dh.append(this.el.dom,  {
+                tag: "div",
+                unselectable: "on",
+                cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
+                children:[
+                    {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
+                    {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
+                ]
+            }, true);
+        
+        this.titleEl.enableDisplayMode();
+        /** This region's title text element 
+        * @type HTMLElement */
+        this.titleTextEl = this.titleEl.dom.firstChild;
+        this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
+        /*
+        this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
+        this.closeBtn.enableDisplayMode();
+        this.closeBtn.on("click", this.closeClicked, this);
+        this.closeBtn.hide();
+    */
+        this.createBody(this.config);
+        if(this.config.hideWhenEmpty){
+            this.hide();
+            this.on("paneladded", this.validateVisibility, this);
+            this.on("panelremoved", this.validateVisibility, this);
+        }
+        if(this.autoScroll){
+            this.bodyEl.setStyle("overflow", "auto");
+        }else{
+            this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
+        }
+        //if(c.titlebar !== false){
+            if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
+                this.titleEl.hide();
+            }else{
+                this.titleEl.show();
+                if(this.config.title){
+                    this.titleTextEl.innerHTML = this.config.title;
+                }
+            }
+        //}
+        if(this.config.collapsed){
+            this.collapse(true);
+        }
+        if(this.config.hidden){
+            this.hide();
+        }
+        
+        if (this.unrendered_panels && this.unrendered_panels.length) {
+            for (var i =0;i< this.unrendered_panels.length; i++) {
+                this.add(this.unrendered_panels[i]);
+            }
+            this.unrendered_panels = null;
+            
+        }
+        
+    },
+    
     applyConfig : function(c)
     {
-        if(c.collapsible && this.position != "center" && !this.collapsedEl){
+        /*
+         *if(c.collapsible && this.position != "center" && !this.collapsedEl){
             var dh = Roo.DomHelper;
             if(c.titlebar !== false){
                 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
@@ -117,13 +177,17 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
                     this.stickBtn.on("click", this.expand, this);
                     this.stickBtn.hide();
                 }
-                */
+                
             }
+            */
             /** This region's collapsed element
             * @type Roo.Element */
+            /*
+             *
             this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
                 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
             ]}, true);
+            
             if(c.floatable !== false){
                this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
                this.collapsedEl.on("click", this.collapseClick, this);
@@ -136,41 +200,32 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
              }
             this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
             this.expandBtn.on("click", this.expand, this);
+            
         }
+        
         if(this.collapseBtn){
             this.collapseBtn.setVisible(c.collapsible == true);
         }
+        
         this.cmargins = c.cmargins || this.cmargins ||
                          (this.position == "west" || this.position == "east" ?
                              {top: 0, left: 2, right:2, bottom: 0} :
                              {top: 2, left: 0, right:0, bottom: 2});
+        */
         this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
-        this.bottomTabs = c.tabPosition != "top";
+        
+        
+        this.tabPosition = [ 'top','bottom', 'west'].indexOf(c.tabPosition) > -1 ? c.tabPosition : "top";
+        
         this.autoScroll = c.autoScroll || false;
-        if(this.autoScroll){
-            this.bodyEl.setStyle("overflow", "auto");
-        }else{
-            this.bodyEl.setStyle("overflow", "hidden");
-        }
-        //if(c.titlebar !== false){
-            if((!c.titlebar && !c.title) || c.titlebar === false){
-                this.titleEl.hide();
-            }else{
-                this.titleEl.show();
-                if(c.title){
-                    this.titleTextEl.innerHTML = c.title;
-                }
-            }
-        //}
+        
+        
+       
+        
         this.duration = c.duration || .30;
         this.slideDuration = c.slideDuration || .45;
         this.config = c;
-        if(c.collapsed){
-            this.collapse(true);
-        }
-        if(c.hidden){
-            this.hide();
-        }
+       
     },
     /**
      * Returns true if this region is currently visible.
@@ -184,27 +239,28 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
      * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
      * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&amp;#160;")
      */
-    setCollapsedTitle : function(title){
-        title = title || "&#160;";
-        if(this.collapsedTitleTextEl){
-            this.collapsedTitleTextEl.innerHTML = title;
-        }
-    },
+    //setCollapsedTitle : function(title){
+    //    title = title || "&#160;";
+     //   if(this.collapsedTitleTextEl){
+      //      this.collapsedTitleTextEl.innerHTML = title;
+       // }
+    //},
 
     getBox : function(){
         var b;
-        if(!this.collapsed){
+      //  if(!this.collapsed){
             b = this.el.getBox(false, true);
-        }else{
-            b = this.collapsedEl.getBox(false, true);
-        }
+       // }else{
+          //  b = this.collapsedEl.getBox(false, true);
+        //}
         return b;
     },
 
     getMargins : function(){
-        return this.collapsed ? this.cmargins : this.margins;
+        return this.margins;
+        //return this.collapsed ? this.cmargins : this.margins;
     },
-
+/*
     highlight : function(){
         this.el.addClass("x-layout-panel-dragover");
     },
@@ -212,8 +268,13 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
     unhighlight : function(){
         this.el.removeClass("x-layout-panel-dragover");
     },
-
-    updateBox : function(box){
+*/
+    updateBox : function(box)
+    {
+        if (!this.bodyEl) {
+            return; // not rendered yet..
+        }
+        
         this.box = box;
         if(!this.collapsed){
             this.el.dom.style.left = box.x + "px";
@@ -229,7 +290,8 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
         }
     },
 
-    updateBody : function(w, h){
+    updateBody : function(w, h)
+    {
         if(w !== null){
             this.el.setWidth(w);
             w -= this.el.getBorderWidth("rl");
@@ -237,7 +299,7 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
                 w += this.config.adjustments[0];
             }
         }
-        if(h !== null){
+        if(h !== null && h > 0){
             this.el.setHeight(h);
             h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
             h -= this.el.getBorderWidth("tb");
@@ -277,13 +339,13 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
      * Hides this region.
      */
     hide : function(){
-        if(!this.collapsed){
+        //if(!this.collapsed){
             this.el.dom.style.left = "-2000px";
             this.el.hide();
-        }else{
-            this.collapsedEl.dom.style.left = "-2000px";
-            this.collapsedEl.hide();
-        }
+        //}else{
+         //   this.collapsedEl.dom.style.left = "-2000px";
+         //   this.collapsedEl.hide();
+       // }
         this.visible = false;
         this.fireEvent("visibilitychange", this, false);
     },
@@ -292,15 +354,15 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
      * Shows this region if it was previously hidden.
      */
     show : function(){
-        if(!this.collapsed){
+        //if(!this.collapsed){
             this.el.show();
-        }else{
-            this.collapsedEl.show();
-        }
+        //}else{
+        //    this.collapsedEl.show();
+       // }
         this.visible = true;
         this.fireEvent("visibilitychange", this, true);
     },
-
+/*
     closeClicked : function(){
         if(this.activePanel){
             this.remove(this.activePanel);
@@ -316,11 +378,12 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
            this.slideOut();
         }
     },
-
+*/
     /**
      * Collapses this region.
      * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
      */
+    /*
     collapse : function(skipAnim, skipCheck = false){
         if(this.collapsed) {
             return;
@@ -345,7 +408,7 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
         }
         
     },
-
+*/
     animateCollapse : function(){
         // overridden
     },
@@ -355,6 +418,7 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
      * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
      * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
      */
+    /*
     expand : function(e, skipAnim){
         if(e) {
             e.stopPropagation();
@@ -380,22 +444,23 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
             this.fireEvent("expanded", this);
         }
     },
-
+*/
     animateExpand : function(){
         // overridden
     },
 
     initTabs : function()
     {
-        this.bodyEl.setStyle("overflow", "hidden");
-        var ts = new Roo.TabPanel(
-                this.bodyEl.dom,
-                {
-                    tabPosition: this.bottomTabs ? 'bottom' : 'top',
-                    disableTooltips: this.config.disableTabTips,
-                    toolbar : this.config.toolbar
-                }
-        );
+        //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
+        
+        var ts = new Roo.bootstrap.panel.Tabs({
+            el: this.bodyEl.dom,
+            region : this,
+            tabPosition: this.tabPosition ? this.tabPosition  : 'top',
+            disableTooltips: this.config.disableTabTips,
+            toolbar : this.config.toolbar
+        });
+        
         if(this.config.hideTabs){
             ts.stripWrap.setDisplayed(false);
         }
@@ -405,30 +470,40 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
         ts.maxTabWidth = this.config.maxTabWidth || 250;
         ts.preferredTabWidth = this.config.preferredTabWidth || 150;
         ts.monitorResize = false;
-        ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
-        ts.bodyEl.addClass('x-layout-tabs-body');
+        //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
+        ts.bodyEl.addClass('roo-layout-tabs-body');
         this.panels.each(this.initPanelAsTab, this);
     },
 
     initPanelAsTab : function(panel){
-        var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
-                    this.config.closeOnTab && panel.isClosable());
+        var ti = this.tabs.addTab(
+            panel.getEl().id,
+            panel.getTitle(),
+            null,
+            this.config.closeOnTab && panel.isClosable(),
+            panel.tpl
+        );
         if(panel.tabTip !== undefined){
             ti.setTooltip(panel.tabTip);
         }
         ti.on("activate", function(){
               this.setActivePanel(panel);
         }, this);
+        
         if(this.config.closeOnTab){
             ti.on("beforeclose", function(t, e){
                 e.cancel = true;
                 this.remove(panel);
             }, this);
         }
+        
+        panel.tabItem = ti;
+        
         return ti;
     },
 
-    updatePanelTitle : function(panel, title){
+    updatePanelTitle : function(panel, title)
+    {
         if(this.activePanel == panel){
             this.updateTitle(title);
         }
@@ -447,10 +522,13 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
         }
     },
 
-    setActivePanel : function(panel){
+    setActivePanel : function(panel)
+    {
         panel = this.getPanel(panel);
         if(this.activePanel && this.activePanel != panel){
-            this.activePanel.setActiveState(false);
+            if(this.activePanel.setActiveState(false) === false){
+                return;
+            }
         }
         this.activePanel = panel;
         panel.setActiveState(true);
@@ -514,20 +592,33 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
      * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
      * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
      */
-    add : function(panel){
+    add : function(panel)
+    {
         if(arguments.length > 1){
             for(var i = 0, len = arguments.length; i < len; i++) {
                 this.add(arguments[i]);
             }
             return null;
         }
+        
+        // if we have not been rendered yet, then we can not really do much of this..
+        if (!this.bodyEl) {
+            this.unrendered_panels.push(panel);
+            return panel;
+        }
+        
+        
+        
+        
         if(this.hasPanel(panel)){
             this.showPanel(panel);
             return panel;
         }
         panel.setRegion(this);
         this.panels.add(panel);
-        if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
+       /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
+            // sinle panel - no tab...?? would it not be better to render it with the tabs,
+            // and hide them... ???
             this.bodyEl.dom.appendChild(panel.getEl().dom);
             if(panel.background !== true){
                 this.setActivePanel(panel);
@@ -535,11 +626,14 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
             this.fireEvent("paneladded", this, panel);
             return panel;
         }
+        */
         if(!this.tabs){
             this.initTabs();
         }else{
             this.initPanelAsTab(panel);
         }
+        
+        
         if(panel.background !== true){
             this.tabs.activate(panel.getEl().id);
         }
@@ -579,7 +673,8 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
      * @param {Boolean} preservePanel Overrides the config preservePanel option
      * @return {Roo.ContentPanel} The panel that was removed
      */
-    remove : function(panel, preservePanel){
+    remove : function(panel, preservePanel)
+    {
         panel = this.getPanel(panel);
         if(!panel){
             return null;
@@ -632,9 +727,16 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
     },
 
     createTool : function(parentEl, className){
-        var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
-            children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: "&#160;"}]}, true);
-        btn.addClassOnOver("x-layout-tools-button-over");
+        var btn = Roo.DomHelper.append(parentEl, {
+            tag: "div",
+            cls: "x-layout-tools-button",
+            children: [ {
+                tag: "div",
+                cls: "roo-layout-tools-button-inner " + className,
+                html: "&#160;"
+            }]
+        }, true);
+        btn.addClassOnOver("roo-layout-tools-button-over");
         return btn;
     }
 });
\ No newline at end of file