4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.bootstrap.layout.Region
14 * @extends Roo.bootstrap.layout.Basic
15 * This class represents a region in a layout manager.
17 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
18 * @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})
19 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
20 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
21 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
22 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
23 * @cfg {String} title The title for the region (overrides panel titles)
24 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
25 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
26 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
27 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
28 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
29 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
30 * the space available, similar to FireFox 1.5 tabs (defaults to false)
31 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
32 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
33 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
36 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
37 * @cfg {Boolean} disableTabTips True to disable tab tooltips
38 * @cfg {Number} width For East/West panels
39 * @cfg {Number} height For North/South panels
40 * @cfg {Boolean} split To show the splitter
41 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
43 * @cfg {string} cls Extra CSS classes to add to region
45 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
46 * @cfg {string} region the region that it inhabits..
49 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
50 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
52 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
53 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
54 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
56 Roo.bootstrap.layout.Region = function(config)
58 this.applyConfig(config);
61 var pos = config.region;
62 config.skipConfig = true;
63 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
66 this.onRender(mgr.el);
70 this.collapsed = false;
71 this.unrendered_panels = [];
74 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
76 position: '', // set by wrapper (eg. north/south etc..)
77 unrendered_panels : null, // unrendered panels.
81 mgr: false, // points to 'Border'
84 createBody : function(){
85 /** This region's body element
86 * @type Roo.Element */
87 this.bodyEl = this.el.createChild({
89 cls: "roo-layout-panel-body tab-content" // bootstrap added...
93 onRender: function(ctr, pos)
95 var dh = Roo.DomHelper;
96 /** This region's container element
97 * @type Roo.Element */
98 this.el = dh.append(ctr.dom, {
100 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
102 /** This region's title element
103 * @type Roo.Element */
105 this.titleEl = dh.append(this.el.dom, {
108 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
110 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
111 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
115 this.titleEl.enableDisplayMode();
116 /** This region's title text element
117 * @type HTMLElement */
118 this.titleTextEl = this.titleEl.dom.firstChild;
119 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
121 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
122 this.closeBtn.enableDisplayMode();
123 this.closeBtn.on("click", this.closeClicked, this);
124 this.closeBtn.hide();
126 this.createBody(this.config);
127 if(this.config.hideWhenEmpty){
129 this.on("paneladded", this.validateVisibility, this);
130 this.on("panelremoved", this.validateVisibility, this);
133 this.bodyEl.setStyle("overflow", "auto");
135 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
137 //if(c.titlebar !== false){
138 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
142 if(this.config.title){
143 this.titleTextEl.innerHTML = this.config.title;
147 if(this.config.collapsed){
150 if(this.config.hidden){
154 if (this.unrendered_panels && this.unrendered_panels.length) {
155 for (var i =0;i< this.unrendered_panels.length; i++) {
156 this.add(this.unrendered_panels[i]);
158 this.unrendered_panels = null;
164 applyConfig : function(c)
167 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
168 var dh = Roo.DomHelper;
169 if(c.titlebar !== false){
170 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
171 this.collapseBtn.on("click", this.collapse, this);
172 this.collapseBtn.enableDisplayMode();
174 if(c.showPin === true || this.showPin){
175 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
176 this.stickBtn.enableDisplayMode();
177 this.stickBtn.on("click", this.expand, this);
178 this.stickBtn.hide();
183 /** This region's collapsed element
184 * @type Roo.Element */
187 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
188 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
191 if(c.floatable !== false){
192 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
193 this.collapsedEl.on("click", this.collapseClick, this);
196 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
197 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
198 id: "message", unselectable: "on", style:{"float":"left"}});
199 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
201 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
202 this.expandBtn.on("click", this.expand, this);
206 if(this.collapseBtn){
207 this.collapseBtn.setVisible(c.collapsible == true);
210 this.cmargins = c.cmargins || this.cmargins ||
211 (this.position == "west" || this.position == "east" ?
212 {top: 0, left: 2, right:2, bottom: 0} :
213 {top: 2, left: 0, right:0, bottom: 2});
215 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
218 this.tabPosition = [ 'top','bottom', 'west'].indexOf(c.tabPosition) > -1 ? c.tabPosition : "top";
220 this.autoScroll = c.autoScroll || false;
225 this.duration = c.duration || .30;
226 this.slideDuration = c.slideDuration || .45;
231 * Returns true if this region is currently visible.
234 isVisible : function(){
239 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
240 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
242 //setCollapsedTitle : function(title){
243 // title = title || " ";
244 // if(this.collapsedTitleTextEl){
245 // this.collapsedTitleTextEl.innerHTML = title;
251 // if(!this.collapsed){
252 b = this.el.getBox(false, true);
254 // b = this.collapsedEl.getBox(false, true);
259 getMargins : function(){
261 //return this.collapsed ? this.cmargins : this.margins;
264 highlight : function(){
265 this.el.addClass("x-layout-panel-dragover");
268 unhighlight : function(){
269 this.el.removeClass("x-layout-panel-dragover");
272 updateBox : function(box)
275 return; // not rendered yet..
280 this.el.dom.style.left = box.x + "px";
281 this.el.dom.style.top = box.y + "px";
282 this.updateBody(box.width, box.height);
284 this.collapsedEl.dom.style.left = box.x + "px";
285 this.collapsedEl.dom.style.top = box.y + "px";
286 this.collapsedEl.setSize(box.width, box.height);
289 this.tabs.autoSizeTabs();
293 updateBody : function(w, h)
297 w -= this.el.getBorderWidth("rl");
298 if(this.config.adjustments){
299 w += this.config.adjustments[0];
302 if(h !== null && h > 0){
303 this.el.setHeight(h);
304 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
305 h -= this.el.getBorderWidth("tb");
306 if(this.config.adjustments){
307 h += this.config.adjustments[1];
309 this.bodyEl.setHeight(h);
311 h = this.tabs.syncHeight(h);
315 w = w !== null ? w : this.panelSize.width;
316 h = h !== null ? h : this.panelSize.height;
318 if(this.activePanel){
319 var el = this.activePanel.getEl();
320 w = w !== null ? w : el.getWidth();
321 h = h !== null ? h : el.getHeight();
322 this.panelSize = {width: w, height: h};
323 this.activePanel.setSize(w, h);
325 if(Roo.isIE && this.tabs){
326 this.tabs.el.repaint();
331 * Returns the container element for this region.
332 * @return {Roo.Element}
342 //if(!this.collapsed){
343 this.el.dom.style.left = "-2000px";
346 // this.collapsedEl.dom.style.left = "-2000px";
347 // this.collapsedEl.hide();
349 this.visible = false;
350 this.fireEvent("visibilitychange", this, false);
354 * Shows this region if it was previously hidden.
357 //if(!this.collapsed){
360 // this.collapsedEl.show();
363 this.fireEvent("visibilitychange", this, true);
366 closeClicked : function(){
367 if(this.activePanel){
368 this.remove(this.activePanel);
372 collapseClick : function(e){
383 * Collapses this region.
384 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
387 collapse : function(skipAnim, skipCheck = false){
392 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
394 this.collapsed = true;
396 this.split.el.hide();
398 if(this.config.animate && skipAnim !== true){
399 this.fireEvent("invalidated", this);
400 this.animateCollapse();
402 this.el.setLocation(-20000,-20000);
404 this.collapsedEl.show();
405 this.fireEvent("collapsed", this);
406 this.fireEvent("invalidated", this);
412 animateCollapse : function(){
417 * Expands this region if it was previously collapsed.
418 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
419 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
422 expand : function(e, skipAnim){
426 if(!this.collapsed || this.el.hasActiveFx()) {
433 this.collapsed = false;
434 if(this.config.animate && skipAnim !== true){
435 this.animateExpand();
439 this.split.el.show();
441 this.collapsedEl.setLocation(-2000,-2000);
442 this.collapsedEl.hide();
443 this.fireEvent("invalidated", this);
444 this.fireEvent("expanded", this);
448 animateExpand : function(){
452 initTabs : function()
454 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
456 var ts = new Roo.bootstrap.panel.Tabs({
459 tabPosition: this.tabPosition ? this.tabPosition : 'top',
460 disableTooltips: this.config.disableTabTips,
461 toolbar : this.config.toolbar
464 if(this.config.hideTabs){
465 ts.stripWrap.setDisplayed(false);
468 ts.resizeTabs = this.config.resizeTabs === true;
469 ts.minTabWidth = this.config.minTabWidth || 40;
470 ts.maxTabWidth = this.config.maxTabWidth || 250;
471 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
472 ts.monitorResize = false;
473 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
474 ts.bodyEl.addClass('roo-layout-tabs-body');
475 this.panels.each(this.initPanelAsTab, this);
478 initPanelAsTab : function(panel){
479 var ti = this.tabs.addTab(
483 this.config.closeOnTab && panel.isClosable(),
486 if(panel.tabTip !== undefined){
487 ti.setTooltip(panel.tabTip);
489 ti.on("activate", function(){
490 this.setActivePanel(panel);
493 if(this.config.closeOnTab){
494 ti.on("beforeclose", function(t, e){
505 updatePanelTitle : function(panel, title)
507 if(this.activePanel == panel){
508 this.updateTitle(title);
511 var ti = this.tabs.getTab(panel.getEl().id);
513 if(panel.tabTip !== undefined){
514 ti.setTooltip(panel.tabTip);
519 updateTitle : function(title){
520 if(this.titleTextEl && !this.config.title){
521 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
525 setActivePanel : function(panel)
527 panel = this.getPanel(panel);
528 if(this.activePanel && this.activePanel != panel){
529 if(this.activePanel.setActiveState(false) === false){
533 this.activePanel = panel;
534 panel.setActiveState(true);
536 panel.setSize(this.panelSize.width, this.panelSize.height);
539 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
541 this.updateTitle(panel.getTitle());
543 this.fireEvent("invalidated", this);
545 this.fireEvent("panelactivated", this, panel);
549 * Shows the specified panel.
550 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
551 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
553 showPanel : function(panel)
555 panel = this.getPanel(panel);
558 var tab = this.tabs.getTab(panel.getEl().id);
560 this.tabs.unhideTab(tab.id);
564 this.setActivePanel(panel);
571 * Get the active panel for this region.
572 * @return {Roo.ContentPanel} The active panel or null
574 getActivePanel : function(){
575 return this.activePanel;
578 validateVisibility : function(){
579 if(this.panels.getCount() < 1){
580 this.updateTitle(" ");
581 this.closeBtn.hide();
584 if(!this.isVisible()){
591 * Adds the passed ContentPanel(s) to this region.
592 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
593 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
595 add : function(panel)
597 if(arguments.length > 1){
598 for(var i = 0, len = arguments.length; i < len; i++) {
599 this.add(arguments[i]);
604 // if we have not been rendered yet, then we can not really do much of this..
606 this.unrendered_panels.push(panel);
613 if(this.hasPanel(panel)){
614 this.showPanel(panel);
617 panel.setRegion(this);
618 this.panels.add(panel);
619 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
620 // sinle panel - no tab...?? would it not be better to render it with the tabs,
621 // and hide them... ???
622 this.bodyEl.dom.appendChild(panel.getEl().dom);
623 if(panel.background !== true){
624 this.setActivePanel(panel);
626 this.fireEvent("paneladded", this, panel);
633 this.initPanelAsTab(panel);
637 if(panel.background !== true){
638 this.tabs.activate(panel.getEl().id);
640 this.fireEvent("paneladded", this, panel);
645 * Hides the tab for the specified panel.
646 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
648 hidePanel : function(panel){
649 if(this.tabs && (panel = this.getPanel(panel))){
650 this.tabs.hideTab(panel.getEl().id);
655 * Unhides the tab for a previously hidden panel.
656 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
658 unhidePanel : function(panel){
659 if(this.tabs && (panel = this.getPanel(panel))){
660 this.tabs.unhideTab(panel.getEl().id);
664 clearPanels : function(){
665 while(this.panels.getCount() > 0){
666 this.remove(this.panels.first());
671 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
672 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
673 * @param {Boolean} preservePanel Overrides the config preservePanel option
674 * @return {Roo.ContentPanel} The panel that was removed
676 remove : function(panel, preservePanel)
678 panel = this.getPanel(panel);
683 this.fireEvent("beforeremove", this, panel, e);
684 if(e.cancel === true){
687 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
688 var panelId = panel.getId();
689 this.panels.removeKey(panelId);
691 document.body.appendChild(panel.getEl().dom);
694 this.tabs.removeTab(panel.getEl().id);
695 }else if (!preservePanel){
696 this.bodyEl.dom.removeChild(panel.getEl().dom);
698 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
699 var p = this.panels.first();
700 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
701 tempEl.appendChild(p.getEl().dom);
702 this.bodyEl.update("");
703 this.bodyEl.dom.appendChild(p.getEl().dom);
705 this.updateTitle(p.getTitle());
707 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
708 this.setActivePanel(p);
710 panel.setRegion(null);
711 if(this.activePanel == panel){
712 this.activePanel = null;
714 if(this.config.autoDestroy !== false && preservePanel !== true){
715 try{panel.destroy();}catch(e){}
717 this.fireEvent("panelremoved", this, panel);
722 * Returns the TabPanel component used by this region
723 * @return {Roo.TabPanel}
725 getTabs : function(){
729 createTool : function(parentEl, className){
730 var btn = Roo.DomHelper.append(parentEl, {
732 cls: "x-layout-tools-button",
735 cls: "roo-layout-tools-button-inner " + className,
739 btn.addClassOnOver("roo-layout-tools-button-over");