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.wrapEl = this.el.wrap();
88 this.footer.container = this.wrapEl.createChild();
90 this.footer = Roo.factory(this.footer, Roo);
95 this.resizeEl = Roo.get(this.resizeEl, true);
97 this.resizeEl = this.el;
107 * Fires when this panel is activated.
108 * @param {Roo.ContentPanel} this
113 * Fires when this panel is activated.
114 * @param {Roo.ContentPanel} this
120 * Fires when this panel is resized if fitToFrame is true.
121 * @param {Roo.ContentPanel} this
122 * @param {Number} width The width after any component adjustments
123 * @param {Number} height The height after any component adjustments
129 * Fires when this tab is created
130 * @param {Roo.ContentPanel} this
142 this.resizeEl.setStyle("overflow", "auto");
144 // fix randome scrolling
145 this.el.on('scroll', function() {
146 Roo.log('fix random scolling');
147 this.scrollTo('top',0);
150 content = content || this.content;
152 this.setContent(content);
154 if(config && config.url){
155 this.setUrl(this.url, this.params, this.loadOnce);
160 Roo.ContentPanel.superclass.constructor.call(this);
162 if (this.view && typeof(this.view.xtype) != 'undefined') {
163 this.view.el = this.el.appendChild(document.createElement("div"));
164 this.view = Roo.factory(this.view);
165 this.view.render && this.view.render(false, '');
169 this.fireEvent('render', this);
172 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
174 setRegion : function(region){
175 this.region = region;
177 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
179 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
184 * Returns the toolbar for this Panel if one was configured.
185 * @return {Roo.Toolbar}
187 getToolbar : function(){
191 setActiveState : function(active){
192 this.active = active;
194 this.fireEvent("deactivate", this);
196 this.fireEvent("activate", this);
200 * Updates this panel's element
201 * @param {String} content The new content
202 * @param {Boolean} loadScripts (optional) true to look for and process scripts
204 setContent : function(content, loadScripts){
205 this.el.update(content, loadScripts);
208 ignoreResize : function(w, h){
209 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
212 this.lastSize = {width: w, height: h};
217 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
218 * @return {Roo.UpdateManager} The UpdateManager
220 getUpdateManager : function(){
221 return this.el.getUpdateManager();
224 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
225 * @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:
229 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
230 callback: yourFunction,
231 scope: yourObject, //(optional scope)
239 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
240 * 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.
241 * @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}
242 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
243 * @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.
244 * @return {Roo.ContentPanel} this
247 var um = this.el.getUpdateManager();
248 um.update.apply(um, arguments);
254 * 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.
255 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
256 * @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)
257 * @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)
258 * @return {Roo.UpdateManager} The UpdateManager
260 setUrl : function(url, params, loadOnce){
261 if(this.refreshDelegate){
262 this.removeListener("activate", this.refreshDelegate);
264 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
265 this.on("activate", this.refreshDelegate);
266 return this.el.getUpdateManager();
269 _handleRefresh : function(url, params, loadOnce){
270 if(!loadOnce || !this.loaded){
271 var updater = this.el.getUpdateManager();
272 updater.update(url, params, this._setLoaded.createDelegate(this));
276 _setLoaded : function(){
281 * Returns this panel's id
289 * Returns this panel's element - used by regiosn to add.
290 * @return {Roo.Element}
293 return this.wrapEl || this.el;
296 adjustForComponents : function(width, height)
298 //Roo.log('adjustForComponents ');
299 if(this.resizeEl != this.el){
300 width -= this.el.getFrameWidth('lr');
301 height -= this.el.getFrameWidth('tb');
304 var te = this.toolbar.getEl();
305 height -= te.getHeight();
309 var te = this.footer.getEl();
310 Roo.log("footer:" + te.getHeight());
312 height -= te.getHeight();
317 if(this.adjustments){
318 width += this.adjustments[0];
319 height += this.adjustments[1];
321 return {"width": width, "height": height};
324 setSize : function(width, height){
325 if(this.fitToFrame && !this.ignoreResize(width, height)){
326 if(this.fitContainer && this.resizeEl != this.el){
327 this.el.setSize(width, height);
329 var size = this.adjustForComponents(width, height);
330 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
331 this.fireEvent('resize', this, size.width, size.height);
336 * Returns this panel's title
339 getTitle : function(){
344 * Set this panel's title
345 * @param {String} title
347 setTitle : function(title){
350 this.region.updatePanelTitle(this, title);
355 * Returns true is this panel was configured to be closable
358 isClosable : function(){
359 return this.closable;
362 beforeSlide : function(){
364 this.resizeEl.clip();
367 afterSlide : function(){
369 this.resizeEl.unclip();
373 * Force a content refresh from the URL specified in the {@link #setUrl} method.
374 * Will fail silently if the {@link #setUrl} method has not been called.
375 * This does not activate the panel, just updates its content.
377 refresh : function(){
378 if(this.refreshDelegate){
380 this.refreshDelegate();
385 * Destroys this panel
387 destroy : function(){
388 this.el.removeAllListeners();
389 var tempEl = document.createElement("span");
390 tempEl.appendChild(this.el.dom);
391 tempEl.innerHTML = "";
397 * form - if the content panel contains a form - this is a reference to it.
398 * @type {Roo.form.Form}
402 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
403 * This contains a reference to it.
409 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
419 * @param {Object} cfg Xtype definition of item to add.
422 addxtype : function(cfg) {
424 if (cfg.xtype.match(/^Form$/)) {
428 // el = this.footer.container.insertSibling(false, 'before');
430 el = this.el.createChild();
433 this.form = new Roo.form.Form(cfg);
436 if ( this.form.allItems.length) this.form.render(el.dom);
439 // should only have one of theses..
440 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
441 // views.. should not be just added - used named prop 'view''
443 cfg.el = this.el.appendChild(document.createElement("div"));
446 var ret = new Roo.factory(cfg);
448 ret.render && ret.render(false, ''); // render blank..
457 * @class Roo.GridPanel
458 * @extends Roo.ContentPanel
460 * Create a new GridPanel.
461 * @param {Roo.grid.Grid} grid The grid for this panel
462 * @param {String/Object} config A string to set only the panel's title, or a config object
464 Roo.GridPanel = function(grid, config){
467 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
468 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
470 this.wrapper.dom.appendChild(grid.getGridEl().dom);
472 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
475 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
477 // xtype created footer. - not sure if will work as we normally have to render first..
478 if (this.footer && !this.footer.el && this.footer.xtype) {
480 this.footer.container = this.grid.getView().getFooterPanel(true);
481 this.footer.dataSource = this.grid.dataSource;
482 this.footer = Roo.factory(this.footer, Roo);
486 grid.monitorWindowResize = false; // turn off autosizing
487 grid.autoHeight = false;
488 grid.autoWidth = false;
490 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
493 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
499 * Returns the grid for this panel
500 * @return {Roo.grid.Grid}
502 getGrid : function(){
506 setSize : function(width, height){
507 if(!this.ignoreResize(width, height)){
508 var grid = this.grid;
509 var size = this.adjustForComponents(width, height);
510 grid.getGridEl().setSize(size.width, size.height);
515 beforeSlide : function(){
516 this.grid.getView().scroller.clip();
519 afterSlide : function(){
520 this.grid.getView().scroller.unclip();
523 destroy : function(){
526 Roo.GridPanel.superclass.destroy.call(this);
532 * @class Roo.NestedLayoutPanel
533 * @extends Roo.ContentPanel
535 * Create a new NestedLayoutPanel.
538 * @param {Roo.BorderLayout} layout The layout for this panel
539 * @param {String/Object} config A string to set only the title or a config object
541 Roo.NestedLayoutPanel = function(layout, config)
543 // construct with only one argument..
544 /* FIXME - implement nicer consturctors
547 layout = config.layout;
548 delete config.layout;
550 if (layout.xtype && !layout.getEl) {
551 // then layout needs constructing..
552 layout = Roo.factory(layout, Roo);
557 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
559 layout.monitorWindowResize = false; // turn off autosizing
560 this.layout = layout;
561 this.layout.getEl().addClass("x-layout-nested-layout");
568 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
570 setSize : function(width, height){
571 if(!this.ignoreResize(width, height)){
572 var size = this.adjustForComponents(width, height);
573 var el = this.layout.getEl();
574 el.setSize(size.width, size.height);
575 var touch = el.dom.offsetWidth;
576 this.layout.layout();
577 // ie requires a double layout on the first pass
578 if(Roo.isIE && !this.initialized){
579 this.initialized = true;
580 this.layout.layout();
585 // activate all subpanels if not currently active..
587 setActiveState : function(active){
588 this.active = active;
590 this.fireEvent("deactivate", this);
594 this.fireEvent("activate", this);
595 // not sure if this should happen before or after..
597 return; // should not happen..
600 for (var r in this.layout.regions) {
601 reg = this.layout.getRegion(r);
602 if (reg.getActivePanel()) {
603 //reg.showPanel(reg.getActivePanel()); // force it to activate..
604 reg.setActivePanel(reg.getActivePanel());
607 if (!reg.panels.length) {
610 reg.showPanel(reg.getPanel(0));
619 * Returns the nested BorderLayout for this panel
620 * @return {Roo.BorderLayout}
622 getLayout : function(){
627 * Adds a xtype elements to the layout of the nested panel
631 xtype : 'ContentPanel',
638 xtype : 'NestedLayoutPanel',
644 items : [ ... list of content panels or nested layout panels.. ]
648 * @param {Object} cfg Xtype definition of item to add.
650 addxtype : function(cfg) {
651 return this.layout.addxtype(cfg);
656 Roo.ScrollPanel = function(el, config, content){
657 config = config || {};
658 config.fitToFrame = true;
659 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
661 this.el.dom.style.overflow = "hidden";
662 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
663 this.el.removeClass("x-layout-inactive-content");
664 this.el.on("mousewheel", this.onWheel, this);
666 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
667 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
668 up.unselectable(); down.unselectable();
669 up.on("click", this.scrollUp, this);
670 down.on("click", this.scrollDown, this);
671 up.addClassOnOver("x-scroller-btn-over");
672 down.addClassOnOver("x-scroller-btn-over");
673 up.addClassOnClick("x-scroller-btn-click");
674 down.addClassOnClick("x-scroller-btn-click");
675 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
677 this.resizeEl = this.el;
678 this.el = wrap; this.up = up; this.down = down;
681 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
684 scrollUp : function(){
685 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
688 scrollDown : function(){
689 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
692 afterScroll : function(){
693 var el = this.resizeEl;
694 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
695 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
696 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
699 setSize : function(){
700 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
704 onWheel : function(e){
705 var d = e.getWheelDelta();
706 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
711 setContent : function(content, loadScripts){
712 this.resizeEl.update(content, loadScripts);
726 * @class Roo.TreePanel
727 * @extends Roo.ContentPanel
729 * Create a new TreePanel. - defaults to fit/scoll contents.
730 * @param {String/Object} config A string to set only the panel's title, or a config object
731 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
733 Roo.TreePanel = function(config){
735 var tree = config.tree;
737 delete config.el; // hopefull!
739 // wrapper for IE7 strict & safari scroll issue
741 var treeEl = el.createChild();
742 config.resizeEl = treeEl;
746 Roo.TreePanel.superclass.constructor.call(this, el, config);
749 this.tree = new Roo.tree.TreePanel(treeEl , tree);
751 this.on('activate', function()
753 if (this.tree.rendered) {
756 //console.log('render tree');
759 // this should not be needed.. - it's actually the 'el' that resizes?
760 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
762 //this.on('resize', function (cp, w, h) {
763 // this.tree.innerCt.setWidth(w);
764 // this.tree.innerCt.setHeight(h);
765 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
772 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {