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">
12 * @class Roo.ContentPanel
13 * @extends Roo.util.Observable
14 * A basic ContentPanel element.
15 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
16 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
17 * @cfg {Boolean/Object} autoCreate True to auto generate the DOM element for this panel, or a {@link Roo.DomHelper} config of the element to create
18 * @cfg {Boolean} closable True if the panel can be closed/removed
19 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
20 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
21 * @cfg {Toolbar} toolbar A toolbar for this panel
22 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
23 * @cfg {String} title The title for this panel
24 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
25 * @cfg {String} url Calls {@link #setUrl} with this value
26 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
27 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
29 * Create a new ContentPanel.
30 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
31 * @param {String/Object} config A string to set only the title or a config object
32 * @param {String} content (optional) Set the HTML content for this panel
33 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
35 Roo.ContentPanel = function(el, config, content){
39 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
43 if (config && config.parentLayout) {
44 el = config.parentLayout.el.createChild();
47 if(el.autoCreate){ // xtype is available if this is called from factory
51 this.el = Roo.get(el);
52 if(!this.el && config && config.autoCreate){
53 if(typeof config.autoCreate == "object"){
54 if(!config.autoCreate.id){
55 config.autoCreate.id = config.id||el;
57 this.el = Roo.DomHelper.append(document.body,
58 config.autoCreate, true);
60 this.el = Roo.DomHelper.append(document.body,
61 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
64 this.closable = false;
67 if(typeof config == "string"){
70 Roo.apply(this, config);
73 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
74 this.wrapEl = this.el.wrap();
75 this.toolbar = new Roo.Toolbar(this.el.insertSibling(false, 'before'), [] , this.toolbar);
82 this.resizeEl = Roo.get(this.resizeEl, true);
84 this.resizeEl = this.el;
89 * Fires when this panel is activated.
90 * @param {Roo.ContentPanel} this
95 * Fires when this panel is activated.
96 * @param {Roo.ContentPanel} this
102 * Fires when this panel is resized if fitToFrame is true.
103 * @param {Roo.ContentPanel} this
104 * @param {Number} width The width after any component adjustments
105 * @param {Number} height The height after any component adjustments
110 this.resizeEl.setStyle("overflow", "auto");
112 content = content || this.content;
114 this.setContent(content);
116 if(config && config.url){
117 this.setUrl(this.url, this.params, this.loadOnce);
122 Roo.ContentPanel.superclass.constructor.call(this);
125 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
127 setRegion : function(region){
128 this.region = region;
130 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
132 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
137 * Returns the toolbar for this Panel if one was configured.
138 * @return {Roo.Toolbar}
140 getToolbar : function(){
144 setActiveState : function(active){
145 this.active = active;
147 this.fireEvent("deactivate", this);
149 this.fireEvent("activate", this);
153 * Updates this panel's element
154 * @param {String} content The new content
155 * @param {Boolean} loadScripts (optional) true to look for and process scripts
157 setContent : function(content, loadScripts){
158 this.el.update(content, loadScripts);
161 ignoreResize : function(w, h){
162 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
165 this.lastSize = {width: w, height: h};
170 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
171 * @return {Roo.UpdateManager} The UpdateManager
173 getUpdateManager : function(){
174 return this.el.getUpdateManager();
177 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
178 * @param {Object/String/Function} url The url for this request or a function to call to get the url or a config object containing any of the following options:
182 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
183 callback: yourFunction,
184 scope: yourObject, //(optional scope)
192 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
193 * are shorthand for <i>disableCaching</i>, <i>indicatorText</i> and <i>loadScripts</i> and are used to set their associated property on this panel UpdateManager instance.
194 * @param {String/Object} params (optional) The parameters to pass as either a URL encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
195 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
196 * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used URL. If true, it will not store the URL.
197 * @return {Roo.ContentPanel} this
200 var um = this.el.getUpdateManager();
201 um.update.apply(um, arguments);
207 * Set a URL to be used to load the content for this panel. When this panel is activated, the content will be loaded from that URL.
208 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
209 * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Roo.UpdateManager#update} for more details. (Defaults to null)
210 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this panel is activated. (Defaults to false)
211 * @return {Roo.UpdateManager} The UpdateManager
213 setUrl : function(url, params, loadOnce){
214 if(this.refreshDelegate){
215 this.removeListener("activate", this.refreshDelegate);
217 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
218 this.on("activate", this.refreshDelegate);
219 return this.el.getUpdateManager();
222 _handleRefresh : function(url, params, loadOnce){
223 if(!loadOnce || !this.loaded){
224 var updater = this.el.getUpdateManager();
225 updater.update(url, params, this._setLoaded.createDelegate(this));
229 _setLoaded : function(){
234 * Returns this panel's id
242 * Returns this panel's element - used by regiosn to add.
243 * @return {Roo.Element}
246 return this.wrapEl || this.el;
249 adjustForComponents : function(width, height){
250 if(this.resizeEl != this.el){
251 width -= this.el.getFrameWidth('lr');
252 height -= this.el.getFrameWidth('tb');
255 var te = this.toolbar.getEl();
256 height -= te.getHeight();
259 if(this.adjustments){
260 width += this.adjustments[0];
261 height += this.adjustments[1];
263 return {"width": width, "height": height};
266 setSize : function(width, height){
267 if(this.fitToFrame && !this.ignoreResize(width, height)){
268 if(this.fitContainer && this.resizeEl != this.el){
269 this.el.setSize(width, height);
271 var size = this.adjustForComponents(width, height);
272 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
273 this.fireEvent('resize', this, size.width, size.height);
278 * Returns this panel's title
281 getTitle : function(){
286 * Set this panel's title
287 * @param {String} title
289 setTitle : function(title){
292 this.region.updatePanelTitle(this, title);
297 * Returns true is this panel was configured to be closable
300 isClosable : function(){
301 return this.closable;
304 beforeSlide : function(){
306 this.resizeEl.clip();
309 afterSlide : function(){
311 this.resizeEl.unclip();
315 * Force a content refresh from the URL specified in the {@link #setUrl} method.
316 * Will fail silently if the {@link #setUrl} method has not been called.
317 * This does not activate the panel, just updates its content.
319 refresh : function(){
320 if(this.refreshDelegate){
322 this.refreshDelegate();
327 * Destroys this panel
329 destroy : function(){
330 this.el.removeAllListeners();
331 var tempEl = document.createElement("span");
332 tempEl.appendChild(this.el.dom);
333 tempEl.innerHTML = "";
339 * Adds a xtype elements to the panel - currently only supports Forms.
349 * @param {Object} cfg Xtype definition of item to add.
352 addxtype : function(cfg) {
354 if (!cfg.xtype.match(/^Form$/)) {
357 var el = this.el.createChild();
358 this.form = new Roo.form.Form(cfg);
360 if ( this.form.allItems.length) this.form.render(el.dom);
367 * @class Roo.GridPanel
368 * @extends Roo.ContentPanel
370 * Create a new GridPanel.
371 * @param {Roo.grid.Grid} grid The grid for this panel
372 * @param {String/Object} config A string to set only the panel's title, or a config object
374 Roo.GridPanel = function(grid, config){
375 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
376 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
377 this.wrapper.dom.appendChild(grid.getGridEl().dom);
378 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
382 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
384 // xtype created footer. - not sure if will work as we normally have to render first..
385 if (this.footer && !this.footer.el && this.footer.xtype) {
387 this.footer.container = this.grid.getView().getFooterPanel(true);
388 this.footer.dataSource = this.grid.dataSource;
389 this.footer = Roo.factory(this.footer, Roo);
393 grid.monitorWindowResize = false; // turn off autosizing
394 grid.autoHeight = false;
395 grid.autoWidth = false;
397 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
400 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
406 * Returns the grid for this panel
407 * @return {Roo.grid.Grid}
409 getGrid : function(){
413 setSize : function(width, height){
414 if(!this.ignoreResize(width, height)){
415 var grid = this.grid;
416 var size = this.adjustForComponents(width, height);
417 grid.getGridEl().setSize(size.width, size.height);
422 beforeSlide : function(){
423 this.grid.getView().scroller.clip();
426 afterSlide : function(){
427 this.grid.getView().scroller.unclip();
430 destroy : function(){
433 Roo.GridPanel.superclass.destroy.call(this);
439 * @class Roo.NestedLayoutPanel
440 * @extends Roo.ContentPanel
442 * Create a new NestedLayoutPanel.
445 * @param {Roo.BorderLayout} layout The layout for this panel
446 * @param {String/Object} config A string to set only the title or a config object
448 Roo.NestedLayoutPanel = function(layout, config)
450 // construct with only one argument..
451 /* FIXME - implement nicer consturctors
454 layout = config.layout;
455 delete config.layout;
457 if (layout.xtype && !layout.getEl) {
458 // then layout needs constructing..
459 layout = Roo.factory(layout, Roo);
463 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
465 layout.monitorWindowResize = false; // turn off autosizing
466 this.layout = layout;
467 this.layout.getEl().addClass("x-layout-nested-layout");
473 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
475 setSize : function(width, height){
476 if(!this.ignoreResize(width, height)){
477 var size = this.adjustForComponents(width, height);
478 var el = this.layout.getEl();
479 el.setSize(size.width, size.height);
480 var touch = el.dom.offsetWidth;
481 this.layout.layout();
482 // ie requires a double layout on the first pass
483 if(Roo.isIE && !this.initialized){
484 this.initialized = true;
485 this.layout.layout();
490 // activate all subpanels if not currently active..
492 setActiveState : function(active){
493 this.active = active;
495 this.fireEvent("deactivate", this);
499 this.fireEvent("activate", this);
500 // not sure if this should happen before or after..
502 return; // should not happen..
505 for (var r in this.layout.regions) {
506 reg = this.layout.getRegion(r);
507 if (reg.getActivePanel()) {
508 //reg.showPanel(reg.getActivePanel()); // force it to activate..
509 reg.setActivePanel(reg.getActivePanel());
512 if (!reg.panels.length) {
515 reg.showPanel(reg.getPanel(0));
524 * Returns the nested BorderLayout for this panel
525 * @return {Roo.BorderLayout}
527 getLayout : function(){
532 * Adds a xtype elements to the layout of the nested panel
536 xtype : 'ContentPanel',
543 xtype : 'NestedLayoutPanel',
549 items : [ ... list of content panels or nested layout panels.. ]
553 * @param {Object} cfg Xtype definition of item to add.
555 addxtype : function(cfg) {
556 return this.layout.addxtype(cfg);
561 Roo.ScrollPanel = function(el, config, content){
562 config = config || {};
563 config.fitToFrame = true;
564 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
566 this.el.dom.style.overflow = "hidden";
567 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
568 this.el.removeClass("x-layout-inactive-content");
569 this.el.on("mousewheel", this.onWheel, this);
571 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
572 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
573 up.unselectable(); down.unselectable();
574 up.on("click", this.scrollUp, this);
575 down.on("click", this.scrollDown, this);
576 up.addClassOnOver("x-scroller-btn-over");
577 down.addClassOnOver("x-scroller-btn-over");
578 up.addClassOnClick("x-scroller-btn-click");
579 down.addClassOnClick("x-scroller-btn-click");
580 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
582 this.resizeEl = this.el;
583 this.el = wrap; this.up = up; this.down = down;
586 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
589 scrollUp : function(){
590 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
593 scrollDown : function(){
594 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
597 afterScroll : function(){
598 var el = this.resizeEl;
599 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
600 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
601 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
604 setSize : function(){
605 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
609 onWheel : function(e){
610 var d = e.getWheelDelta();
611 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
616 setContent : function(content, loadScripts){
617 this.resizeEl.update(content, loadScripts);
631 * @class Roo.TreePanel
632 * @extends Roo.ContentPanel
634 * Create a new TreePanel.
635 * @param {String/Object} config A string to set only the panel's title, or a config object
636 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
638 Roo.TreePanel = function(config){
640 var tree = config.tree;
642 delete config.el; // hopefull!
643 Roo.TreePanel.superclass.constructor.call(this, el, config);
644 var treeEl = el.createChild();
645 this.tree = new Roo.tree.TreePanel(treeEl , tree);
647 this.on('activate', function()
649 if (this.tree.rendered) {
652 //console.log('render tree');
656 this.on('resize', function (cp, w, h) {
657 this.tree.innerCt.setWidth(w);
658 this.tree.innerCt.setHeight(h);
659 this.tree.innerCt.setStyle('overflow-y', 'auto');
666 Roo.extend(Roo.TreePanel, Roo.ContentPanel);