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)
34 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
36 * @cfg {Boolean} disableTabTips True to disable tab tooltips
37 * @cfg {Number} width For East/West panels
38 * @cfg {Number} height For North/South panels
39 * @cfg {Boolean} split To show the splitter
40 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
42 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
43 * @cfg {string} region the region that it inhabits..
46 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
47 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
49 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
50 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
51 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
53 Roo.bootstrap.layout.Region = function(config)
57 var pos = config.region;
58 config.skipConfig = true;
59 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
60 var dh = Roo.DomHelper;
61 /** This region's container element
62 * @type Roo.Element */
63 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "roo-layout-panel roo-layout-panel-" + this.position}, true);
64 /** This region's title element
65 * @type Roo.Element */
67 this.titleEl = dh.append(this.el.dom,
71 cls: "roo-unselectable roo-layout-panel-hd roo-layout-title-" + this.position,
73 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
74 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
77 this.titleEl.enableDisplayMode();
78 /** This region's title text element
79 * @type HTMLElement */
80 this.titleTextEl = this.titleEl.dom.firstChild;
81 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
83 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
84 this.closeBtn.enableDisplayMode();
85 this.closeBtn.on("click", this.closeClicked, this);
88 this.createBody(config);
90 this.collapsed = false;
92 if(config.hideWhenEmpty){
94 this.on("paneladded", this.validateVisibility, this);
95 this.on("panelremoved", this.validateVisibility, this);
97 this.applyConfig(config);
100 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
102 createBody : function(){
103 /** This region's body element
104 * @type Roo.Element */
105 this.bodyEl = this.el.createChild({
107 cls: "roo-layout-panel-body tab-content" // bootstrap added...
111 applyConfig : function(c)
114 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
115 var dh = Roo.DomHelper;
116 if(c.titlebar !== false){
117 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
118 this.collapseBtn.on("click", this.collapse, this);
119 this.collapseBtn.enableDisplayMode();
121 if(c.showPin === true || this.showPin){
122 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
123 this.stickBtn.enableDisplayMode();
124 this.stickBtn.on("click", this.expand, this);
125 this.stickBtn.hide();
130 /** This region's collapsed element
131 * @type Roo.Element */
134 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
135 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
138 if(c.floatable !== false){
139 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
140 this.collapsedEl.on("click", this.collapseClick, this);
143 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
144 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
145 id: "message", unselectable: "on", style:{"float":"left"}});
146 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
148 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
149 this.expandBtn.on("click", this.expand, this);
153 if(this.collapseBtn){
154 this.collapseBtn.setVisible(c.collapsible == true);
157 this.cmargins = c.cmargins || this.cmargins ||
158 (this.position == "west" || this.position == "east" ?
159 {top: 0, left: 2, right:2, bottom: 0} :
160 {top: 2, left: 0, right:0, bottom: 2});
162 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
165 this.bottomTabs = c.tabPosition != "top";
167 this.autoScroll = c.autoScroll || false;
169 this.bodyEl.setStyle("overflow", "auto");
171 this.bodyEl.setStyle("overflow", "hidden");
173 //if(c.titlebar !== false){
174 if((!c.titlebar && !c.title) || c.titlebar === false){
179 this.titleTextEl.innerHTML = c.title;
183 this.duration = c.duration || .30;
184 this.slideDuration = c.slideDuration || .45;
194 * Returns true if this region is currently visible.
197 isVisible : function(){
202 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
203 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
205 //setCollapsedTitle : function(title){
206 // title = title || " ";
207 // if(this.collapsedTitleTextEl){
208 // this.collapsedTitleTextEl.innerHTML = title;
214 // if(!this.collapsed){
215 b = this.el.getBox(false, true);
217 // b = this.collapsedEl.getBox(false, true);
222 getMargins : function(){
224 //return this.collapsed ? this.cmargins : this.margins;
227 highlight : function(){
228 this.el.addClass("x-layout-panel-dragover");
231 unhighlight : function(){
232 this.el.removeClass("x-layout-panel-dragover");
235 updateBox : function(box)
239 this.el.dom.style.left = box.x + "px";
240 this.el.dom.style.top = box.y + "px";
241 this.updateBody(box.width, box.height);
243 this.collapsedEl.dom.style.left = box.x + "px";
244 this.collapsedEl.dom.style.top = box.y + "px";
245 this.collapsedEl.setSize(box.width, box.height);
248 this.tabs.autoSizeTabs();
252 updateBody : function(w, h)
256 w -= this.el.getBorderWidth("rl");
257 if(this.config.adjustments){
258 w += this.config.adjustments[0];
262 this.el.setHeight(h);
263 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
264 h -= this.el.getBorderWidth("tb");
265 if(this.config.adjustments){
266 h += this.config.adjustments[1];
268 this.bodyEl.setHeight(h);
270 h = this.tabs.syncHeight(h);
274 w = w !== null ? w : this.panelSize.width;
275 h = h !== null ? h : this.panelSize.height;
277 if(this.activePanel){
278 var el = this.activePanel.getEl();
279 w = w !== null ? w : el.getWidth();
280 h = h !== null ? h : el.getHeight();
281 this.panelSize = {width: w, height: h};
282 this.activePanel.setSize(w, h);
284 if(Roo.isIE && this.tabs){
285 this.tabs.el.repaint();
290 * Returns the container element for this region.
291 * @return {Roo.Element}
301 //if(!this.collapsed){
302 this.el.dom.style.left = "-2000px";
305 // this.collapsedEl.dom.style.left = "-2000px";
306 // this.collapsedEl.hide();
308 this.visible = false;
309 this.fireEvent("visibilitychange", this, false);
313 * Shows this region if it was previously hidden.
316 //if(!this.collapsed){
319 // this.collapsedEl.show();
322 this.fireEvent("visibilitychange", this, true);
325 closeClicked : function(){
326 if(this.activePanel){
327 this.remove(this.activePanel);
331 collapseClick : function(e){
342 * Collapses this region.
343 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
346 collapse : function(skipAnim, skipCheck = false){
351 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
353 this.collapsed = true;
355 this.split.el.hide();
357 if(this.config.animate && skipAnim !== true){
358 this.fireEvent("invalidated", this);
359 this.animateCollapse();
361 this.el.setLocation(-20000,-20000);
363 this.collapsedEl.show();
364 this.fireEvent("collapsed", this);
365 this.fireEvent("invalidated", this);
371 animateCollapse : function(){
376 * Expands this region if it was previously collapsed.
377 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
378 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
381 expand : function(e, skipAnim){
385 if(!this.collapsed || this.el.hasActiveFx()) {
392 this.collapsed = false;
393 if(this.config.animate && skipAnim !== true){
394 this.animateExpand();
398 this.split.el.show();
400 this.collapsedEl.setLocation(-2000,-2000);
401 this.collapsedEl.hide();
402 this.fireEvent("invalidated", this);
403 this.fireEvent("expanded", this);
407 animateExpand : function(){
411 initTabs : function()
413 this.bodyEl.setStyle("overflow", "hidden");
414 var ts = new Roo.bootstrap.panel.Tabs({
416 tabPosition: this.bottomTabs ? 'bottom' : 'top',
417 disableTooltips: this.config.disableTabTips,
418 toolbar : this.config.toolbar
421 if(this.config.hideTabs){
422 ts.stripWrap.setDisplayed(false);
425 ts.resizeTabs = this.config.resizeTabs === true;
426 ts.minTabWidth = this.config.minTabWidth || 40;
427 ts.maxTabWidth = this.config.maxTabWidth || 250;
428 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
429 ts.monitorResize = false;
430 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
431 ts.bodyEl.addClass('roo-layout-tabs-body');
432 this.panels.each(this.initPanelAsTab, this);
435 initPanelAsTab : function(panel){
436 var ti = this.tabs.addTab(
438 panel.getTitle(), null,
439 this.config.closeOnTab && panel.isClosable()
441 if(panel.tabTip !== undefined){
442 ti.setTooltip(panel.tabTip);
444 ti.on("activate", function(){
445 this.setActivePanel(panel);
448 if(this.config.closeOnTab){
449 ti.on("beforeclose", function(t, e){
457 updatePanelTitle : function(panel, title)
459 if(this.activePanel == panel){
460 this.updateTitle(title);
463 var ti = this.tabs.getTab(panel.getEl().id);
465 if(panel.tabTip !== undefined){
466 ti.setTooltip(panel.tabTip);
471 updateTitle : function(title){
472 if(this.titleTextEl && !this.config.title){
473 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
477 setActivePanel : function(panel)
479 panel = this.getPanel(panel);
480 if(this.activePanel && this.activePanel != panel){
481 this.activePanel.setActiveState(false);
483 this.activePanel = panel;
484 panel.setActiveState(true);
486 panel.setSize(this.panelSize.width, this.panelSize.height);
489 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
491 this.updateTitle(panel.getTitle());
493 this.fireEvent("invalidated", this);
495 this.fireEvent("panelactivated", this, panel);
499 * Shows the specified panel.
500 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
501 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
503 showPanel : function(panel)
505 panel = this.getPanel(panel);
508 var tab = this.tabs.getTab(panel.getEl().id);
510 this.tabs.unhideTab(tab.id);
514 this.setActivePanel(panel);
521 * Get the active panel for this region.
522 * @return {Roo.ContentPanel} The active panel or null
524 getActivePanel : function(){
525 return this.activePanel;
528 validateVisibility : function(){
529 if(this.panels.getCount() < 1){
530 this.updateTitle(" ");
531 this.closeBtn.hide();
534 if(!this.isVisible()){
541 * Adds the passed ContentPanel(s) to this region.
542 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
543 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
545 add : function(panel){
546 if(arguments.length > 1){
547 for(var i = 0, len = arguments.length; i < len; i++) {
548 this.add(arguments[i]);
552 if(this.hasPanel(panel)){
553 this.showPanel(panel);
556 panel.setRegion(this);
557 this.panels.add(panel);
558 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
559 this.bodyEl.dom.appendChild(panel.getEl().dom);
560 if(panel.background !== true){
561 this.setActivePanel(panel);
563 this.fireEvent("paneladded", this, panel);
569 this.initPanelAsTab(panel);
571 if(panel.background !== true){
572 this.tabs.activate(panel.getEl().id);
574 this.fireEvent("paneladded", this, panel);
579 * Hides the tab for the specified panel.
580 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
582 hidePanel : function(panel){
583 if(this.tabs && (panel = this.getPanel(panel))){
584 this.tabs.hideTab(panel.getEl().id);
589 * Unhides the tab for a previously hidden panel.
590 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
592 unhidePanel : function(panel){
593 if(this.tabs && (panel = this.getPanel(panel))){
594 this.tabs.unhideTab(panel.getEl().id);
598 clearPanels : function(){
599 while(this.panels.getCount() > 0){
600 this.remove(this.panels.first());
605 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
606 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
607 * @param {Boolean} preservePanel Overrides the config preservePanel option
608 * @return {Roo.ContentPanel} The panel that was removed
610 remove : function(panel, preservePanel)
612 panel = this.getPanel(panel);
617 this.fireEvent("beforeremove", this, panel, e);
618 if(e.cancel === true){
621 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
622 var panelId = panel.getId();
623 this.panels.removeKey(panelId);
625 document.body.appendChild(panel.getEl().dom);
628 this.tabs.removeTab(panel.getEl().id);
629 }else if (!preservePanel){
630 this.bodyEl.dom.removeChild(panel.getEl().dom);
632 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
633 var p = this.panels.first();
634 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
635 tempEl.appendChild(p.getEl().dom);
636 this.bodyEl.update("");
637 this.bodyEl.dom.appendChild(p.getEl().dom);
639 this.updateTitle(p.getTitle());
641 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
642 this.setActivePanel(p);
644 panel.setRegion(null);
645 if(this.activePanel == panel){
646 this.activePanel = null;
648 if(this.config.autoDestroy !== false && preservePanel !== true){
649 try{panel.destroy();}catch(e){}
651 this.fireEvent("panelremoved", this, panel);
656 * Returns the TabPanel component used by this region
657 * @return {Roo.TabPanel}
659 getTabs : function(){
663 createTool : function(parentEl, className){
664 var btn = Roo.DomHelper.append(parentEl, {
666 cls: "x-layout-tools-button",
669 cls: "roo-layout-tools-button-inner " + className,
673 btn.addClassOnOver("roo-layout-tools-button-over");