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);
86 this.resizeEl = Roo.get(this.resizeEl, true);
88 this.resizeEl = this.el;
93 * Fires when this panel is activated.
94 * @param {Roo.ContentPanel} this
99 * Fires when this panel is activated.
100 * @param {Roo.ContentPanel} this
106 * Fires when this panel is resized if fitToFrame is true.
107 * @param {Roo.ContentPanel} this
108 * @param {Number} width The width after any component adjustments
109 * @param {Number} height The height after any component adjustments
115 * Fires when this tab is created
116 * @param {Roo.ContentPanel} this
124 this.resizeEl.setStyle("overflow", "auto");
126 // fix randome scrolling
127 this.el.on('scroll', function() {
128 Roo.log('fix random scolling');
129 this.scrollTo('top',0);
132 content = content || this.content;
134 this.setContent(content);
136 if(config && config.url){
137 this.setUrl(this.url, this.params, this.loadOnce);
142 Roo.ContentPanel.superclass.constructor.call(this);
144 this.fireEvent('render', this);
147 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
149 setRegion : function(region){
150 this.region = region;
152 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
154 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
159 * Returns the toolbar for this Panel if one was configured.
160 * @return {Roo.Toolbar}
162 getToolbar : function(){
166 setActiveState : function(active){
167 this.active = active;
169 this.fireEvent("deactivate", this);
171 this.fireEvent("activate", this);
175 * Updates this panel's element
176 * @param {String} content The new content
177 * @param {Boolean} loadScripts (optional) true to look for and process scripts
179 setContent : function(content, loadScripts){
180 this.el.update(content, loadScripts);
183 ignoreResize : function(w, h){
184 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
187 this.lastSize = {width: w, height: h};
192 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
193 * @return {Roo.UpdateManager} The UpdateManager
195 getUpdateManager : function(){
196 return this.el.getUpdateManager();
199 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
200 * @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:
204 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
205 callback: yourFunction,
206 scope: yourObject, //(optional scope)
214 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
215 * 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.
216 * @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}
217 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
218 * @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.
219 * @return {Roo.ContentPanel} this
222 var um = this.el.getUpdateManager();
223 um.update.apply(um, arguments);
229 * 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.
230 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
231 * @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)
232 * @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)
233 * @return {Roo.UpdateManager} The UpdateManager
235 setUrl : function(url, params, loadOnce){
236 if(this.refreshDelegate){
237 this.removeListener("activate", this.refreshDelegate);
239 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
240 this.on("activate", this.refreshDelegate);
241 return this.el.getUpdateManager();
244 _handleRefresh : function(url, params, loadOnce){
245 if(!loadOnce || !this.loaded){
246 var updater = this.el.getUpdateManager();
247 updater.update(url, params, this._setLoaded.createDelegate(this));
251 _setLoaded : function(){
256 * Returns this panel's id
264 * Returns this panel's element - used by regiosn to add.
265 * @return {Roo.Element}
268 return this.wrapEl || this.el;
271 adjustForComponents : function(width, height){
272 if(this.resizeEl != this.el){
273 width -= this.el.getFrameWidth('lr');
274 height -= this.el.getFrameWidth('tb');
277 var te = this.toolbar.getEl();
278 height -= te.getHeight();
281 if(this.adjustments){
282 width += this.adjustments[0];
283 height += this.adjustments[1];
285 return {"width": width, "height": height};
288 setSize : function(width, height){
289 if(this.fitToFrame && !this.ignoreResize(width, height)){
290 if(this.fitContainer && this.resizeEl != this.el){
291 this.el.setSize(width, height);
293 var size = this.adjustForComponents(width, height);
294 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
295 this.fireEvent('resize', this, size.width, size.height);
300 * Returns this panel's title
303 getTitle : function(){
308 * Set this panel's title
309 * @param {String} title
311 setTitle : function(title){
314 this.region.updatePanelTitle(this, title);
319 * Returns true is this panel was configured to be closable
322 isClosable : function(){
323 return this.closable;
326 beforeSlide : function(){
328 this.resizeEl.clip();
331 afterSlide : function(){
333 this.resizeEl.unclip();
337 * Force a content refresh from the URL specified in the {@link #setUrl} method.
338 * Will fail silently if the {@link #setUrl} method has not been called.
339 * This does not activate the panel, just updates its content.
341 refresh : function(){
342 if(this.refreshDelegate){
344 this.refreshDelegate();
349 * Destroys this panel
351 destroy : function(){
352 this.el.removeAllListeners();
353 var tempEl = document.createElement("span");
354 tempEl.appendChild(this.el.dom);
355 tempEl.innerHTML = "";
361 * form - if the content panel contains a form - this is a reference to it.
362 * @type {Roo.form.Form}
366 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
367 * This contains a reference to it.
373 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
383 * @param {Object} cfg Xtype definition of item to add.
386 addxtype : function(cfg) {
388 if (cfg.xtype.match(/^Form$/)) {
389 var el = this.el.createChild();
391 this.form = new Roo.form.Form(cfg);
394 if ( this.form.allItems.length) this.form.render(el.dom);
397 // should only have one of theses..
398 if (['View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
400 cfg.el = this.el.appendChild(document.createElement("div"));
403 var ret = new Roo.factory(cfg);
404 ret.render && ret.render(false, ''); // render blank..
413 * @class Roo.GridPanel
414 * @extends Roo.ContentPanel
416 * Create a new GridPanel.
417 * @param {Roo.grid.Grid} grid The grid for this panel
418 * @param {String/Object} config A string to set only the panel's title, or a config object
420 Roo.GridPanel = function(grid, config){
423 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
424 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
426 this.wrapper.dom.appendChild(grid.getGridEl().dom);
428 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
431 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
433 // xtype created footer. - not sure if will work as we normally have to render first..
434 if (this.footer && !this.footer.el && this.footer.xtype) {
436 this.footer.container = this.grid.getView().getFooterPanel(true);
437 this.footer.dataSource = this.grid.dataSource;
438 this.footer = Roo.factory(this.footer, Roo);
442 grid.monitorWindowResize = false; // turn off autosizing
443 grid.autoHeight = false;
444 grid.autoWidth = false;
446 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
449 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
455 * Returns the grid for this panel
456 * @return {Roo.grid.Grid}
458 getGrid : function(){
462 setSize : function(width, height){
463 if(!this.ignoreResize(width, height)){
464 var grid = this.grid;
465 var size = this.adjustForComponents(width, height);
466 grid.getGridEl().setSize(size.width, size.height);
471 beforeSlide : function(){
472 this.grid.getView().scroller.clip();
475 afterSlide : function(){
476 this.grid.getView().scroller.unclip();
479 destroy : function(){
482 Roo.GridPanel.superclass.destroy.call(this);
488 * @class Roo.NestedLayoutPanel
489 * @extends Roo.ContentPanel
491 * Create a new NestedLayoutPanel.
494 * @param {Roo.BorderLayout} layout The layout for this panel
495 * @param {String/Object} config A string to set only the title or a config object
497 Roo.NestedLayoutPanel = function(layout, config)
499 // construct with only one argument..
500 /* FIXME - implement nicer consturctors
503 layout = config.layout;
504 delete config.layout;
506 if (layout.xtype && !layout.getEl) {
507 // then layout needs constructing..
508 layout = Roo.factory(layout, Roo);
513 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
515 layout.monitorWindowResize = false; // turn off autosizing
516 this.layout = layout;
517 this.layout.getEl().addClass("x-layout-nested-layout");
524 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
526 setSize : function(width, height){
527 if(!this.ignoreResize(width, height)){
528 var size = this.adjustForComponents(width, height);
529 var el = this.layout.getEl();
530 el.setSize(size.width, size.height);
531 var touch = el.dom.offsetWidth;
532 this.layout.layout();
533 // ie requires a double layout on the first pass
534 if(Roo.isIE && !this.initialized){
535 this.initialized = true;
536 this.layout.layout();
541 // activate all subpanels if not currently active..
543 setActiveState : function(active){
544 this.active = active;
546 this.fireEvent("deactivate", this);
550 this.fireEvent("activate", this);
551 // not sure if this should happen before or after..
553 return; // should not happen..
556 for (var r in this.layout.regions) {
557 reg = this.layout.getRegion(r);
558 if (reg.getActivePanel()) {
559 //reg.showPanel(reg.getActivePanel()); // force it to activate..
560 reg.setActivePanel(reg.getActivePanel());
563 if (!reg.panels.length) {
566 reg.showPanel(reg.getPanel(0));
575 * Returns the nested BorderLayout for this panel
576 * @return {Roo.BorderLayout}
578 getLayout : function(){
583 * Adds a xtype elements to the layout of the nested panel
587 xtype : 'ContentPanel',
594 xtype : 'NestedLayoutPanel',
600 items : [ ... list of content panels or nested layout panels.. ]
604 * @param {Object} cfg Xtype definition of item to add.
606 addxtype : function(cfg) {
607 return this.layout.addxtype(cfg);
612 Roo.ScrollPanel = function(el, config, content){
613 config = config || {};
614 config.fitToFrame = true;
615 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
617 this.el.dom.style.overflow = "hidden";
618 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
619 this.el.removeClass("x-layout-inactive-content");
620 this.el.on("mousewheel", this.onWheel, this);
622 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
623 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
624 up.unselectable(); down.unselectable();
625 up.on("click", this.scrollUp, this);
626 down.on("click", this.scrollDown, this);
627 up.addClassOnOver("x-scroller-btn-over");
628 down.addClassOnOver("x-scroller-btn-over");
629 up.addClassOnClick("x-scroller-btn-click");
630 down.addClassOnClick("x-scroller-btn-click");
631 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
633 this.resizeEl = this.el;
634 this.el = wrap; this.up = up; this.down = down;
637 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
640 scrollUp : function(){
641 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
644 scrollDown : function(){
645 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
648 afterScroll : function(){
649 var el = this.resizeEl;
650 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
651 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
652 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
655 setSize : function(){
656 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
660 onWheel : function(e){
661 var d = e.getWheelDelta();
662 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
667 setContent : function(content, loadScripts){
668 this.resizeEl.update(content, loadScripts);
682 * @class Roo.TreePanel
683 * @extends Roo.ContentPanel
685 * Create a new TreePanel. - defaults to fit/scoll contents.
686 * @param {String/Object} config A string to set only the panel's title, or a config object
687 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
689 Roo.TreePanel = function(config){
691 var tree = config.tree;
693 delete config.el; // hopefull!
695 // wrapper for IE7 strict & safari scroll issue
697 var treeEl = el.createChild();
698 config.resizeEl = treeEl;
702 Roo.TreePanel.superclass.constructor.call(this, el, config);
705 this.tree = new Roo.tree.TreePanel(treeEl , tree);
707 this.on('activate', function()
709 if (this.tree.rendered) {
712 //console.log('render tree');
716 this.on('resize', function (cp, w, h) {
717 this.tree.innerCt.setWidth(w);
718 this.tree.innerCt.setHeight(h);
719 this.tree.innerCt.setStyle('overflow-y', 'auto');
726 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {