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, View, JsonView.
349 * @param {Object} cfg Xtype definition of item to add.
352 addxtype : function(cfg) {
354 if (cfg.xtype.match(/^Form$/)) {
355 var el = this.el.createChild();
357 this.form = new Roo.form.Form(cfg);
360 if ( this.form.allItems.length) this.form.render(el.dom);
363 if (['View', 'JsonView'].indexOf(cfg.xtype) > -1) {
365 cfg.el = this.el.appendChild(document.createElement("div"));
367 var ret = new Roo[cfg.xtype](cfg);
368 ret.render(false, ''); // render blank..
378 * @class Roo.GridPanel
379 * @extends Roo.ContentPanel
381 * Create a new GridPanel.
382 * @param {Roo.grid.Grid} grid The grid for this panel
383 * @param {String/Object} config A string to set only the panel's title, or a config object
385 Roo.GridPanel = function(grid, config){
388 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
389 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
391 this.wrapper.dom.appendChild(grid.getGridEl().dom);
393 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
396 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
398 // xtype created footer. - not sure if will work as we normally have to render first..
399 if (this.footer && !this.footer.el && this.footer.xtype) {
401 this.footer.container = this.grid.getView().getFooterPanel(true);
402 this.footer.dataSource = this.grid.dataSource;
403 this.footer = Roo.factory(this.footer, Roo);
407 grid.monitorWindowResize = false; // turn off autosizing
408 grid.autoHeight = false;
409 grid.autoWidth = false;
411 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
414 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
420 * Returns the grid for this panel
421 * @return {Roo.grid.Grid}
423 getGrid : function(){
427 setSize : function(width, height){
428 if(!this.ignoreResize(width, height)){
429 var grid = this.grid;
430 var size = this.adjustForComponents(width, height);
431 grid.getGridEl().setSize(size.width, size.height);
436 beforeSlide : function(){
437 this.grid.getView().scroller.clip();
440 afterSlide : function(){
441 this.grid.getView().scroller.unclip();
444 destroy : function(){
447 Roo.GridPanel.superclass.destroy.call(this);
453 * @class Roo.NestedLayoutPanel
454 * @extends Roo.ContentPanel
456 * Create a new NestedLayoutPanel.
459 * @param {Roo.BorderLayout} layout The layout for this panel
460 * @param {String/Object} config A string to set only the title or a config object
462 Roo.NestedLayoutPanel = function(layout, config)
464 // construct with only one argument..
465 /* FIXME - implement nicer consturctors
468 layout = config.layout;
469 delete config.layout;
471 if (layout.xtype && !layout.getEl) {
472 // then layout needs constructing..
473 layout = Roo.factory(layout, Roo);
477 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
479 layout.monitorWindowResize = false; // turn off autosizing
480 this.layout = layout;
481 this.layout.getEl().addClass("x-layout-nested-layout");
487 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
489 setSize : function(width, height){
490 if(!this.ignoreResize(width, height)){
491 var size = this.adjustForComponents(width, height);
492 var el = this.layout.getEl();
493 el.setSize(size.width, size.height);
494 var touch = el.dom.offsetWidth;
495 this.layout.layout();
496 // ie requires a double layout on the first pass
497 if(Roo.isIE && !this.initialized){
498 this.initialized = true;
499 this.layout.layout();
504 // activate all subpanels if not currently active..
506 setActiveState : function(active){
507 this.active = active;
509 this.fireEvent("deactivate", this);
513 this.fireEvent("activate", this);
514 // not sure if this should happen before or after..
516 return; // should not happen..
519 for (var r in this.layout.regions) {
520 reg = this.layout.getRegion(r);
521 if (reg.getActivePanel()) {
522 //reg.showPanel(reg.getActivePanel()); // force it to activate..
523 reg.setActivePanel(reg.getActivePanel());
526 if (!reg.panels.length) {
529 reg.showPanel(reg.getPanel(0));
538 * Returns the nested BorderLayout for this panel
539 * @return {Roo.BorderLayout}
541 getLayout : function(){
546 * Adds a xtype elements to the layout of the nested panel
550 xtype : 'ContentPanel',
557 xtype : 'NestedLayoutPanel',
563 items : [ ... list of content panels or nested layout panels.. ]
567 * @param {Object} cfg Xtype definition of item to add.
569 addxtype : function(cfg) {
570 return this.layout.addxtype(cfg);
575 Roo.ScrollPanel = function(el, config, content){
576 config = config || {};
577 config.fitToFrame = true;
578 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
580 this.el.dom.style.overflow = "hidden";
581 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
582 this.el.removeClass("x-layout-inactive-content");
583 this.el.on("mousewheel", this.onWheel, this);
585 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
586 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
587 up.unselectable(); down.unselectable();
588 up.on("click", this.scrollUp, this);
589 down.on("click", this.scrollDown, this);
590 up.addClassOnOver("x-scroller-btn-over");
591 down.addClassOnOver("x-scroller-btn-over");
592 up.addClassOnClick("x-scroller-btn-click");
593 down.addClassOnClick("x-scroller-btn-click");
594 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
596 this.resizeEl = this.el;
597 this.el = wrap; this.up = up; this.down = down;
600 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
603 scrollUp : function(){
604 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
607 scrollDown : function(){
608 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
611 afterScroll : function(){
612 var el = this.resizeEl;
613 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
614 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
615 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
618 setSize : function(){
619 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
623 onWheel : function(e){
624 var d = e.getWheelDelta();
625 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
630 setContent : function(content, loadScripts){
631 this.resizeEl.update(content, loadScripts);
645 * @class Roo.TreePanel
646 * @extends Roo.ContentPanel
648 * Create a new TreePanel.
649 * @param {String/Object} config A string to set only the panel's title, or a config object
650 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
652 Roo.TreePanel = function(config){
654 var tree = config.tree;
656 delete config.el; // hopefull!
657 Roo.TreePanel.superclass.constructor.call(this, el, config);
658 var treeEl = el.createChild();
659 this.tree = new Roo.tree.TreePanel(treeEl , tree);
661 this.on('activate', function()
663 if (this.tree.rendered) {
666 //console.log('render tree');
670 this.on('resize', function (cp, w, h) {
671 this.tree.innerCt.setWidth(w);
672 this.tree.innerCt.setHeight(h);
673 this.tree.innerCt.setStyle('overflow-y', 'auto');
680 Roo.extend(Roo.TreePanel, Roo.ContentPanel);