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} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
27 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
28 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
30 * Create a new ContentPanel.
31 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
32 * @param {String/Object} config A string to set only the title or a config object
33 * @param {String} content (optional) Set the HTML content for this panel
34 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36 Roo.ContentPanel = function(el, config, content){
40 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
44 if (config && config.parentLayout) {
45 el = config.parentLayout.el.createChild();
48 if(el.autoCreate){ // xtype is available if this is called from factory
52 this.el = Roo.get(el);
53 if(!this.el && config && config.autoCreate){
54 if(typeof config.autoCreate == "object"){
55 if(!config.autoCreate.id){
56 config.autoCreate.id = config.id||el;
58 this.el = Roo.DomHelper.append(document.body,
59 config.autoCreate, true);
61 this.el = Roo.DomHelper.append(document.body,
62 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
65 this.closable = false;
68 if(typeof config == "string"){
71 Roo.apply(this, config);
74 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
75 this.wrapEl = this.el.wrap();
76 this.toolbar = new Roo.Toolbar(this.el.insertSibling(false, 'before'), [] , this.toolbar);
83 this.resizeEl = Roo.get(this.resizeEl, true);
85 this.resizeEl = this.el;
90 * Fires when this panel is activated.
91 * @param {Roo.ContentPanel} this
96 * Fires when this panel is activated.
97 * @param {Roo.ContentPanel} this
103 * Fires when this panel is resized if fitToFrame is true.
104 * @param {Roo.ContentPanel} this
105 * @param {Number} width The width after any component adjustments
106 * @param {Number} height The height after any component adjustments
111 this.resizeEl.setStyle("overflow", "auto");
113 this.el.on('scroll', this.el.scrollTop);
115 content = content || this.content;
117 this.setContent(content);
119 if(config && config.url){
120 this.setUrl(this.url, this.params, this.loadOnce);
125 Roo.ContentPanel.superclass.constructor.call(this);
128 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
130 setRegion : function(region){
131 this.region = region;
133 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
135 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
140 * Returns the toolbar for this Panel if one was configured.
141 * @return {Roo.Toolbar}
143 getToolbar : function(){
147 setActiveState : function(active){
148 this.active = active;
150 this.fireEvent("deactivate", this);
152 this.fireEvent("activate", this);
156 * Updates this panel's element
157 * @param {String} content The new content
158 * @param {Boolean} loadScripts (optional) true to look for and process scripts
160 setContent : function(content, loadScripts){
161 this.el.update(content, loadScripts);
164 ignoreResize : function(w, h){
165 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
168 this.lastSize = {width: w, height: h};
173 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
174 * @return {Roo.UpdateManager} The UpdateManager
176 getUpdateManager : function(){
177 return this.el.getUpdateManager();
180 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
181 * @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:
185 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
186 callback: yourFunction,
187 scope: yourObject, //(optional scope)
195 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
196 * 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.
197 * @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}
198 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
199 * @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.
200 * @return {Roo.ContentPanel} this
203 var um = this.el.getUpdateManager();
204 um.update.apply(um, arguments);
210 * 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.
211 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
212 * @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)
213 * @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)
214 * @return {Roo.UpdateManager} The UpdateManager
216 setUrl : function(url, params, loadOnce){
217 if(this.refreshDelegate){
218 this.removeListener("activate", this.refreshDelegate);
220 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
221 this.on("activate", this.refreshDelegate);
222 return this.el.getUpdateManager();
225 _handleRefresh : function(url, params, loadOnce){
226 if(!loadOnce || !this.loaded){
227 var updater = this.el.getUpdateManager();
228 updater.update(url, params, this._setLoaded.createDelegate(this));
232 _setLoaded : function(){
237 * Returns this panel's id
245 * Returns this panel's element - used by regiosn to add.
246 * @return {Roo.Element}
249 return this.wrapEl || this.el;
252 adjustForComponents : function(width, height){
253 if(this.resizeEl != this.el){
254 width -= this.el.getFrameWidth('lr');
255 height -= this.el.getFrameWidth('tb');
258 var te = this.toolbar.getEl();
259 height -= te.getHeight();
262 if(this.adjustments){
263 width += this.adjustments[0];
264 height += this.adjustments[1];
266 return {"width": width, "height": height};
269 setSize : function(width, height){
270 if(this.fitToFrame && !this.ignoreResize(width, height)){
271 if(this.fitContainer && this.resizeEl != this.el){
272 this.el.setSize(width, height);
274 var size = this.adjustForComponents(width, height);
275 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
276 this.fireEvent('resize', this, size.width, size.height);
281 * Returns this panel's title
284 getTitle : function(){
289 * Set this panel's title
290 * @param {String} title
292 setTitle : function(title){
295 this.region.updatePanelTitle(this, title);
300 * Returns true is this panel was configured to be closable
303 isClosable : function(){
304 return this.closable;
307 beforeSlide : function(){
309 this.resizeEl.clip();
312 afterSlide : function(){
314 this.resizeEl.unclip();
318 * Force a content refresh from the URL specified in the {@link #setUrl} method.
319 * Will fail silently if the {@link #setUrl} method has not been called.
320 * This does not activate the panel, just updates its content.
322 refresh : function(){
323 if(this.refreshDelegate){
325 this.refreshDelegate();
330 * Destroys this panel
332 destroy : function(){
333 this.el.removeAllListeners();
334 var tempEl = document.createElement("span");
335 tempEl.appendChild(this.el.dom);
336 tempEl.innerHTML = "";
342 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
352 * @param {Object} cfg Xtype definition of item to add.
355 addxtype : function(cfg) {
357 if (cfg.xtype.match(/^Form$/)) {
358 var el = this.el.createChild();
360 this.form = new Roo.form.Form(cfg);
363 if ( this.form.allItems.length) this.form.render(el.dom);
366 if (['View', 'JsonView'].indexOf(cfg.xtype) > -1) {
368 cfg.el = this.el.appendChild(document.createElement("div"));
370 var ret = new Roo[cfg.xtype](cfg);
371 ret.render(false, ''); // render blank..
381 * @class Roo.GridPanel
382 * @extends Roo.ContentPanel
384 * Create a new GridPanel.
385 * @param {Roo.grid.Grid} grid The grid for this panel
386 * @param {String/Object} config A string to set only the panel's title, or a config object
388 Roo.GridPanel = function(grid, config){
391 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
392 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
394 this.wrapper.dom.appendChild(grid.getGridEl().dom);
396 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
399 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
401 // xtype created footer. - not sure if will work as we normally have to render first..
402 if (this.footer && !this.footer.el && this.footer.xtype) {
404 this.footer.container = this.grid.getView().getFooterPanel(true);
405 this.footer.dataSource = this.grid.dataSource;
406 this.footer = Roo.factory(this.footer, Roo);
410 grid.monitorWindowResize = false; // turn off autosizing
411 grid.autoHeight = false;
412 grid.autoWidth = false;
414 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
417 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
423 * Returns the grid for this panel
424 * @return {Roo.grid.Grid}
426 getGrid : function(){
430 setSize : function(width, height){
431 if(!this.ignoreResize(width, height)){
432 var grid = this.grid;
433 var size = this.adjustForComponents(width, height);
434 grid.getGridEl().setSize(size.width, size.height);
439 beforeSlide : function(){
440 this.grid.getView().scroller.clip();
443 afterSlide : function(){
444 this.grid.getView().scroller.unclip();
447 destroy : function(){
450 Roo.GridPanel.superclass.destroy.call(this);
456 * @class Roo.NestedLayoutPanel
457 * @extends Roo.ContentPanel
459 * Create a new NestedLayoutPanel.
462 * @param {Roo.BorderLayout} layout The layout for this panel
463 * @param {String/Object} config A string to set only the title or a config object
465 Roo.NestedLayoutPanel = function(layout, config)
467 // construct with only one argument..
468 /* FIXME - implement nicer consturctors
471 layout = config.layout;
472 delete config.layout;
474 if (layout.xtype && !layout.getEl) {
475 // then layout needs constructing..
476 layout = Roo.factory(layout, Roo);
481 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
483 layout.monitorWindowResize = false; // turn off autosizing
484 this.layout = layout;
485 this.layout.getEl().addClass("x-layout-nested-layout");
492 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
494 setSize : function(width, height){
495 if(!this.ignoreResize(width, height)){
496 var size = this.adjustForComponents(width, height);
497 var el = this.layout.getEl();
498 el.setSize(size.width, size.height);
499 var touch = el.dom.offsetWidth;
500 this.layout.layout();
501 // ie requires a double layout on the first pass
502 if(Roo.isIE && !this.initialized){
503 this.initialized = true;
504 this.layout.layout();
509 // activate all subpanels if not currently active..
511 setActiveState : function(active){
512 this.active = active;
514 this.fireEvent("deactivate", this);
518 this.fireEvent("activate", this);
519 // not sure if this should happen before or after..
521 return; // should not happen..
524 for (var r in this.layout.regions) {
525 reg = this.layout.getRegion(r);
526 if (reg.getActivePanel()) {
527 //reg.showPanel(reg.getActivePanel()); // force it to activate..
528 reg.setActivePanel(reg.getActivePanel());
531 if (!reg.panels.length) {
534 reg.showPanel(reg.getPanel(0));
543 * Returns the nested BorderLayout for this panel
544 * @return {Roo.BorderLayout}
546 getLayout : function(){
551 * Adds a xtype elements to the layout of the nested panel
555 xtype : 'ContentPanel',
562 xtype : 'NestedLayoutPanel',
568 items : [ ... list of content panels or nested layout panels.. ]
572 * @param {Object} cfg Xtype definition of item to add.
574 addxtype : function(cfg) {
575 return this.layout.addxtype(cfg);
580 Roo.ScrollPanel = function(el, config, content){
581 config = config || {};
582 config.fitToFrame = true;
583 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
585 this.el.dom.style.overflow = "hidden";
586 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
587 this.el.removeClass("x-layout-inactive-content");
588 this.el.on("mousewheel", this.onWheel, this);
590 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
591 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
592 up.unselectable(); down.unselectable();
593 up.on("click", this.scrollUp, this);
594 down.on("click", this.scrollDown, this);
595 up.addClassOnOver("x-scroller-btn-over");
596 down.addClassOnOver("x-scroller-btn-over");
597 up.addClassOnClick("x-scroller-btn-click");
598 down.addClassOnClick("x-scroller-btn-click");
599 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
601 this.resizeEl = this.el;
602 this.el = wrap; this.up = up; this.down = down;
605 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
608 scrollUp : function(){
609 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
612 scrollDown : function(){
613 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
616 afterScroll : function(){
617 var el = this.resizeEl;
618 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
619 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
620 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
623 setSize : function(){
624 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
628 onWheel : function(e){
629 var d = e.getWheelDelta();
630 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
635 setContent : function(content, loadScripts){
636 this.resizeEl.update(content, loadScripts);
650 * @class Roo.TreePanel
651 * @extends Roo.ContentPanel
653 * Create a new TreePanel. - defaults to fit/scoll contents.
654 * @param {String/Object} config A string to set only the panel's title, or a config object
655 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
657 Roo.TreePanel = function(config){
659 var tree = config.tree;
661 delete config.el; // hopefull!
663 // wrapper for IE7 strict & safari scroll issue
665 var treeEl = el.createChild();
666 config.resizeEl = treeEl;
670 Roo.TreePanel.superclass.constructor.call(this, el, config);
673 this.tree = new Roo.tree.TreePanel(treeEl , tree);
675 this.on('activate', function()
677 if (this.tree.rendered) {
680 //console.log('render tree');
684 this.on('resize', function (cp, w, h) {
685 this.tree.innerCt.setWidth(w);
686 this.tree.innerCt.setHeight(h);
687 this.tree.innerCt.setStyle('overflow-y', 'auto');
694 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {