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
29 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
32 * Create a new ContentPanel.
33 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
34 * @param {String/Object} config A string to set only the title or a config object
35 * @param {String} content (optional) Set the HTML content for this panel
36 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
38 Roo.ContentPanel = function(el, config, content){
42 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
46 if (config && config.parentLayout) {
47 el = config.parentLayout.el.createChild();
50 if(el.autoCreate){ // xtype is available if this is called from factory
54 this.el = Roo.get(el);
55 if(!this.el && config && config.autoCreate){
56 if(typeof config.autoCreate == "object"){
57 if(!config.autoCreate.id){
58 config.autoCreate.id = config.id||el;
60 this.el = Roo.DomHelper.append(document.body,
61 config.autoCreate, true);
63 this.el = Roo.DomHelper.append(document.body,
64 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
67 this.closable = false;
70 if(typeof config == "string"){
73 Roo.apply(this, config);
76 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
77 this.wrapEl = this.el.wrap();
78 this.toolbar.container = this.el.insertSibling(false, 'before');
79 this.toolbar = new Roo.Toolbar(this.toolbar);
82 // xtype created footer. - not sure if will work as we normally have to render first..
83 if (this.footer && !this.footer.el && this.footer.xtype) {
85 this.footer.container = this.el;
86 this.footer = Roo.factory(this.footer, Roo);
91 this.resizeEl = Roo.get(this.resizeEl, true);
93 this.resizeEl = this.el;
98 * Fires when this panel is activated.
99 * @param {Roo.ContentPanel} this
104 * Fires when this panel is activated.
105 * @param {Roo.ContentPanel} this
111 * Fires when this panel is resized if fitToFrame is true.
112 * @param {Roo.ContentPanel} this
113 * @param {Number} width The width after any component adjustments
114 * @param {Number} height The height after any component adjustments
120 * Fires when this tab is created
121 * @param {Roo.ContentPanel} this
129 this.resizeEl.setStyle("overflow", "auto");
131 // fix randome scrolling
132 this.el.on('scroll', function() {
133 Roo.log('fix random scolling');
134 this.scrollTo('top',0);
137 content = content || this.content;
139 this.setContent(content);
141 if(config && config.url){
142 this.setUrl(this.url, this.params, this.loadOnce);
147 Roo.ContentPanel.superclass.constructor.call(this);
149 this.fireEvent('render', this);
152 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
154 setRegion : function(region){
155 this.region = region;
157 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
159 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
164 * Returns the toolbar for this Panel if one was configured.
165 * @return {Roo.Toolbar}
167 getToolbar : function(){
171 setActiveState : function(active){
172 this.active = active;
174 this.fireEvent("deactivate", this);
176 this.fireEvent("activate", this);
180 * Updates this panel's element
181 * @param {String} content The new content
182 * @param {Boolean} loadScripts (optional) true to look for and process scripts
184 setContent : function(content, loadScripts){
185 this.el.update(content, loadScripts);
188 ignoreResize : function(w, h){
189 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
192 this.lastSize = {width: w, height: h};
197 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
198 * @return {Roo.UpdateManager} The UpdateManager
200 getUpdateManager : function(){
201 return this.el.getUpdateManager();
204 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
205 * @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:
209 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
210 callback: yourFunction,
211 scope: yourObject, //(optional scope)
219 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
220 * 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.
221 * @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}
222 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
223 * @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.
224 * @return {Roo.ContentPanel} this
227 var um = this.el.getUpdateManager();
228 um.update.apply(um, arguments);
234 * 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.
235 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
236 * @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)
237 * @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)
238 * @return {Roo.UpdateManager} The UpdateManager
240 setUrl : function(url, params, loadOnce){
241 if(this.refreshDelegate){
242 this.removeListener("activate", this.refreshDelegate);
244 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
245 this.on("activate", this.refreshDelegate);
246 return this.el.getUpdateManager();
249 _handleRefresh : function(url, params, loadOnce){
250 if(!loadOnce || !this.loaded){
251 var updater = this.el.getUpdateManager();
252 updater.update(url, params, this._setLoaded.createDelegate(this));
256 _setLoaded : function(){
261 * Returns this panel's id
269 * Returns this panel's element - used by regiosn to add.
270 * @return {Roo.Element}
273 return this.wrapEl || this.el;
276 adjustForComponents : function(width, height){
277 if(this.resizeEl != this.el){
278 width -= this.el.getFrameWidth('lr');
279 height -= this.el.getFrameWidth('tb');
282 var te = this.toolbar.getEl();
283 height -= te.getHeight();
286 if(this.adjustments){
287 width += this.adjustments[0];
288 height += this.adjustments[1];
290 return {"width": width, "height": height};
293 setSize : function(width, height){
294 if(this.fitToFrame && !this.ignoreResize(width, height)){
295 if(this.fitContainer && this.resizeEl != this.el){
296 this.el.setSize(width, height);
298 var size = this.adjustForComponents(width, height);
299 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
300 this.fireEvent('resize', this, size.width, size.height);
305 * Returns this panel's title
308 getTitle : function(){
313 * Set this panel's title
314 * @param {String} title
316 setTitle : function(title){
319 this.region.updatePanelTitle(this, title);
324 * Returns true is this panel was configured to be closable
327 isClosable : function(){
328 return this.closable;
331 beforeSlide : function(){
333 this.resizeEl.clip();
336 afterSlide : function(){
338 this.resizeEl.unclip();
342 * Force a content refresh from the URL specified in the {@link #setUrl} method.
343 * Will fail silently if the {@link #setUrl} method has not been called.
344 * This does not activate the panel, just updates its content.
346 refresh : function(){
347 if(this.refreshDelegate){
349 this.refreshDelegate();
354 * Destroys this panel
356 destroy : function(){
357 this.el.removeAllListeners();
358 var tempEl = document.createElement("span");
359 tempEl.appendChild(this.el.dom);
360 tempEl.innerHTML = "";
366 * form - if the content panel contains a form - this is a reference to it.
367 * @type {Roo.form.Form}
371 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
372 * This contains a reference to it.
378 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
388 * @param {Object} cfg Xtype definition of item to add.
391 addxtype : function(cfg) {
393 if (cfg.xtype.match(/^Form$/)) {
394 var el = this.el.createChild();
396 this.form = new Roo.form.Form(cfg);
399 if ( this.form.allItems.length) this.form.render(el.dom);
402 // should only have one of theses..
403 if (['View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
405 cfg.el = this.el.appendChild(document.createElement("div"));
408 var ret = new Roo.factory(cfg);
409 ret.render && ret.render(false, ''); // render blank..
418 * @class Roo.GridPanel
419 * @extends Roo.ContentPanel
421 * Create a new GridPanel.
422 * @param {Roo.grid.Grid} grid The grid for this panel
423 * @param {String/Object} config A string to set only the panel's title, or a config object
425 Roo.GridPanel = function(grid, config){
428 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
429 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
431 this.wrapper.dom.appendChild(grid.getGridEl().dom);
433 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
436 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
438 // xtype created footer. - not sure if will work as we normally have to render first..
439 if (this.footer && !this.footer.el && this.footer.xtype) {
441 this.footer.container = this.grid.getView().getFooterPanel(true);
442 this.footer.dataSource = this.grid.dataSource;
443 this.footer = Roo.factory(this.footer, Roo);
447 grid.monitorWindowResize = false; // turn off autosizing
448 grid.autoHeight = false;
449 grid.autoWidth = false;
451 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
454 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
460 * Returns the grid for this panel
461 * @return {Roo.grid.Grid}
463 getGrid : function(){
467 setSize : function(width, height){
468 if(!this.ignoreResize(width, height)){
469 var grid = this.grid;
470 var size = this.adjustForComponents(width, height);
471 grid.getGridEl().setSize(size.width, size.height);
476 beforeSlide : function(){
477 this.grid.getView().scroller.clip();
480 afterSlide : function(){
481 this.grid.getView().scroller.unclip();
484 destroy : function(){
487 Roo.GridPanel.superclass.destroy.call(this);
493 * @class Roo.NestedLayoutPanel
494 * @extends Roo.ContentPanel
496 * Create a new NestedLayoutPanel.
499 * @param {Roo.BorderLayout} layout The layout for this panel
500 * @param {String/Object} config A string to set only the title or a config object
502 Roo.NestedLayoutPanel = function(layout, config)
504 // construct with only one argument..
505 /* FIXME - implement nicer consturctors
508 layout = config.layout;
509 delete config.layout;
511 if (layout.xtype && !layout.getEl) {
512 // then layout needs constructing..
513 layout = Roo.factory(layout, Roo);
518 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
520 layout.monitorWindowResize = false; // turn off autosizing
521 this.layout = layout;
522 this.layout.getEl().addClass("x-layout-nested-layout");
529 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
531 setSize : function(width, height){
532 if(!this.ignoreResize(width, height)){
533 var size = this.adjustForComponents(width, height);
534 var el = this.layout.getEl();
535 el.setSize(size.width, size.height);
536 var touch = el.dom.offsetWidth;
537 this.layout.layout();
538 // ie requires a double layout on the first pass
539 if(Roo.isIE && !this.initialized){
540 this.initialized = true;
541 this.layout.layout();
546 // activate all subpanels if not currently active..
548 setActiveState : function(active){
549 this.active = active;
551 this.fireEvent("deactivate", this);
555 this.fireEvent("activate", this);
556 // not sure if this should happen before or after..
558 return; // should not happen..
561 for (var r in this.layout.regions) {
562 reg = this.layout.getRegion(r);
563 if (reg.getActivePanel()) {
564 //reg.showPanel(reg.getActivePanel()); // force it to activate..
565 reg.setActivePanel(reg.getActivePanel());
568 if (!reg.panels.length) {
571 reg.showPanel(reg.getPanel(0));
580 * Returns the nested BorderLayout for this panel
581 * @return {Roo.BorderLayout}
583 getLayout : function(){
588 * Adds a xtype elements to the layout of the nested panel
592 xtype : 'ContentPanel',
599 xtype : 'NestedLayoutPanel',
605 items : [ ... list of content panels or nested layout panels.. ]
609 * @param {Object} cfg Xtype definition of item to add.
611 addxtype : function(cfg) {
612 return this.layout.addxtype(cfg);
617 Roo.ScrollPanel = function(el, config, content){
618 config = config || {};
619 config.fitToFrame = true;
620 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
622 this.el.dom.style.overflow = "hidden";
623 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
624 this.el.removeClass("x-layout-inactive-content");
625 this.el.on("mousewheel", this.onWheel, this);
627 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
628 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
629 up.unselectable(); down.unselectable();
630 up.on("click", this.scrollUp, this);
631 down.on("click", this.scrollDown, this);
632 up.addClassOnOver("x-scroller-btn-over");
633 down.addClassOnOver("x-scroller-btn-over");
634 up.addClassOnClick("x-scroller-btn-click");
635 down.addClassOnClick("x-scroller-btn-click");
636 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
638 this.resizeEl = this.el;
639 this.el = wrap; this.up = up; this.down = down;
642 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
645 scrollUp : function(){
646 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
649 scrollDown : function(){
650 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
653 afterScroll : function(){
654 var el = this.resizeEl;
655 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
656 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
657 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
660 setSize : function(){
661 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
665 onWheel : function(e){
666 var d = e.getWheelDelta();
667 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
672 setContent : function(content, loadScripts){
673 this.resizeEl.update(content, loadScripts);
687 * @class Roo.TreePanel
688 * @extends Roo.ContentPanel
690 * Create a new TreePanel. - defaults to fit/scoll contents.
691 * @param {String/Object} config A string to set only the panel's title, or a config object
692 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
694 Roo.TreePanel = function(config){
696 var tree = config.tree;
698 delete config.el; // hopefull!
700 // wrapper for IE7 strict & safari scroll issue
702 var treeEl = el.createChild();
703 config.resizeEl = treeEl;
707 Roo.TreePanel.superclass.constructor.call(this, el, config);
710 this.tree = new Roo.tree.TreePanel(treeEl , tree);
712 this.on('activate', function()
714 if (this.tree.rendered) {
717 //console.log('render tree');
720 // this should not be needed.. - it's actually the 'el' that resizes?
721 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
723 //this.on('resize', function (cp, w, h) {
724 // this.tree.innerCt.setWidth(w);
725 // this.tree.innerCt.setHeight(h);
726 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
733 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {