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 // fix randome scrolling
114 this.el.on('scroll', function() {
115 Roo.log('fix random scolling');
116 this.scrollTo('top',0);
119 content = content || this.content;
121 this.setContent(content);
123 if(config && config.url){
124 this.setUrl(this.url, this.params, this.loadOnce);
129 Roo.ContentPanel.superclass.constructor.call(this);
132 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
134 setRegion : function(region){
135 this.region = region;
137 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
139 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
144 * Returns the toolbar for this Panel if one was configured.
145 * @return {Roo.Toolbar}
147 getToolbar : function(){
151 setActiveState : function(active){
152 this.active = active;
154 this.fireEvent("deactivate", this);
156 this.fireEvent("activate", this);
160 * Updates this panel's element
161 * @param {String} content The new content
162 * @param {Boolean} loadScripts (optional) true to look for and process scripts
164 setContent : function(content, loadScripts){
165 this.el.update(content, loadScripts);
168 ignoreResize : function(w, h){
169 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
172 this.lastSize = {width: w, height: h};
177 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
178 * @return {Roo.UpdateManager} The UpdateManager
180 getUpdateManager : function(){
181 return this.el.getUpdateManager();
184 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
185 * @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:
189 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
190 callback: yourFunction,
191 scope: yourObject, //(optional scope)
199 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
200 * 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.
201 * @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}
202 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
203 * @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.
204 * @return {Roo.ContentPanel} this
207 var um = this.el.getUpdateManager();
208 um.update.apply(um, arguments);
214 * 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.
215 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
216 * @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)
217 * @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)
218 * @return {Roo.UpdateManager} The UpdateManager
220 setUrl : function(url, params, loadOnce){
221 if(this.refreshDelegate){
222 this.removeListener("activate", this.refreshDelegate);
224 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
225 this.on("activate", this.refreshDelegate);
226 return this.el.getUpdateManager();
229 _handleRefresh : function(url, params, loadOnce){
230 if(!loadOnce || !this.loaded){
231 var updater = this.el.getUpdateManager();
232 updater.update(url, params, this._setLoaded.createDelegate(this));
236 _setLoaded : function(){
241 * Returns this panel's id
249 * Returns this panel's element - used by regiosn to add.
250 * @return {Roo.Element}
253 return this.wrapEl || this.el;
256 adjustForComponents : function(width, height){
257 if(this.resizeEl != this.el){
258 width -= this.el.getFrameWidth('lr');
259 height -= this.el.getFrameWidth('tb');
262 var te = this.toolbar.getEl();
263 height -= te.getHeight();
266 if(this.adjustments){
267 width += this.adjustments[0];
268 height += this.adjustments[1];
270 return {"width": width, "height": height};
273 setSize : function(width, height){
274 if(this.fitToFrame && !this.ignoreResize(width, height)){
275 if(this.fitContainer && this.resizeEl != this.el){
276 this.el.setSize(width, height);
278 var size = this.adjustForComponents(width, height);
279 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
280 this.fireEvent('resize', this, size.width, size.height);
285 * Returns this panel's title
288 getTitle : function(){
293 * Set this panel's title
294 * @param {String} title
296 setTitle : function(title){
299 this.region.updatePanelTitle(this, title);
304 * Returns true is this panel was configured to be closable
307 isClosable : function(){
308 return this.closable;
311 beforeSlide : function(){
313 this.resizeEl.clip();
316 afterSlide : function(){
318 this.resizeEl.unclip();
322 * Force a content refresh from the URL specified in the {@link #setUrl} method.
323 * Will fail silently if the {@link #setUrl} method has not been called.
324 * This does not activate the panel, just updates its content.
326 refresh : function(){
327 if(this.refreshDelegate){
329 this.refreshDelegate();
334 * Destroys this panel
336 destroy : function(){
337 this.el.removeAllListeners();
338 var tempEl = document.createElement("span");
339 tempEl.appendChild(this.el.dom);
340 tempEl.innerHTML = "";
346 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
356 * @param {Object} cfg Xtype definition of item to add.
359 addxtype : function(cfg) {
361 if (cfg.xtype.match(/^Form$/)) {
362 var el = this.el.createChild();
364 this.form = new Roo.form.Form(cfg);
367 if ( this.form.allItems.length) this.form.render(el.dom);
370 if (['View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
372 cfg.el = this.el.appendChild(document.createElement("div"));
374 var ret = new Roo[cfg.xtype](cfg);
375 ret.render(false, ''); // render blank..
385 * @class Roo.GridPanel
386 * @extends Roo.ContentPanel
388 * Create a new GridPanel.
389 * @param {Roo.grid.Grid} grid The grid for this panel
390 * @param {String/Object} config A string to set only the panel's title, or a config object
392 Roo.GridPanel = function(grid, config){
395 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
396 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
398 this.wrapper.dom.appendChild(grid.getGridEl().dom);
400 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
403 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
405 // xtype created footer. - not sure if will work as we normally have to render first..
406 if (this.footer && !this.footer.el && this.footer.xtype) {
408 this.footer.container = this.grid.getView().getFooterPanel(true);
409 this.footer.dataSource = this.grid.dataSource;
410 this.footer = Roo.factory(this.footer, Roo);
414 grid.monitorWindowResize = false; // turn off autosizing
415 grid.autoHeight = false;
416 grid.autoWidth = false;
418 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
421 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
427 * Returns the grid for this panel
428 * @return {Roo.grid.Grid}
430 getGrid : function(){
434 setSize : function(width, height){
435 if(!this.ignoreResize(width, height)){
436 var grid = this.grid;
437 var size = this.adjustForComponents(width, height);
438 grid.getGridEl().setSize(size.width, size.height);
443 beforeSlide : function(){
444 this.grid.getView().scroller.clip();
447 afterSlide : function(){
448 this.grid.getView().scroller.unclip();
451 destroy : function(){
454 Roo.GridPanel.superclass.destroy.call(this);
460 * @class Roo.NestedLayoutPanel
461 * @extends Roo.ContentPanel
463 * Create a new NestedLayoutPanel.
466 * @param {Roo.BorderLayout} layout The layout for this panel
467 * @param {String/Object} config A string to set only the title or a config object
469 Roo.NestedLayoutPanel = function(layout, config)
471 // construct with only one argument..
472 /* FIXME - implement nicer consturctors
475 layout = config.layout;
476 delete config.layout;
478 if (layout.xtype && !layout.getEl) {
479 // then layout needs constructing..
480 layout = Roo.factory(layout, Roo);
485 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
487 layout.monitorWindowResize = false; // turn off autosizing
488 this.layout = layout;
489 this.layout.getEl().addClass("x-layout-nested-layout");
496 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
498 setSize : function(width, height){
499 if(!this.ignoreResize(width, height)){
500 var size = this.adjustForComponents(width, height);
501 var el = this.layout.getEl();
502 el.setSize(size.width, size.height);
503 var touch = el.dom.offsetWidth;
504 this.layout.layout();
505 // ie requires a double layout on the first pass
506 if(Roo.isIE && !this.initialized){
507 this.initialized = true;
508 this.layout.layout();
513 // activate all subpanels if not currently active..
515 setActiveState : function(active){
516 this.active = active;
518 this.fireEvent("deactivate", this);
522 this.fireEvent("activate", this);
523 // not sure if this should happen before or after..
525 return; // should not happen..
528 for (var r in this.layout.regions) {
529 reg = this.layout.getRegion(r);
530 if (reg.getActivePanel()) {
531 //reg.showPanel(reg.getActivePanel()); // force it to activate..
532 reg.setActivePanel(reg.getActivePanel());
535 if (!reg.panels.length) {
538 reg.showPanel(reg.getPanel(0));
547 * Returns the nested BorderLayout for this panel
548 * @return {Roo.BorderLayout}
550 getLayout : function(){
555 * Adds a xtype elements to the layout of the nested panel
559 xtype : 'ContentPanel',
566 xtype : 'NestedLayoutPanel',
572 items : [ ... list of content panels or nested layout panels.. ]
576 * @param {Object} cfg Xtype definition of item to add.
578 addxtype : function(cfg) {
579 return this.layout.addxtype(cfg);
584 Roo.ScrollPanel = function(el, config, content){
585 config = config || {};
586 config.fitToFrame = true;
587 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
589 this.el.dom.style.overflow = "hidden";
590 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
591 this.el.removeClass("x-layout-inactive-content");
592 this.el.on("mousewheel", this.onWheel, this);
594 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
595 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
596 up.unselectable(); down.unselectable();
597 up.on("click", this.scrollUp, this);
598 down.on("click", this.scrollDown, this);
599 up.addClassOnOver("x-scroller-btn-over");
600 down.addClassOnOver("x-scroller-btn-over");
601 up.addClassOnClick("x-scroller-btn-click");
602 down.addClassOnClick("x-scroller-btn-click");
603 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
605 this.resizeEl = this.el;
606 this.el = wrap; this.up = up; this.down = down;
609 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
612 scrollUp : function(){
613 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
616 scrollDown : function(){
617 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
620 afterScroll : function(){
621 var el = this.resizeEl;
622 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
623 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
624 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
627 setSize : function(){
628 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
632 onWheel : function(e){
633 var d = e.getWheelDelta();
634 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
639 setContent : function(content, loadScripts){
640 this.resizeEl.update(content, loadScripts);
654 * @class Roo.TreePanel
655 * @extends Roo.ContentPanel
657 * Create a new TreePanel. - defaults to fit/scoll contents.
658 * @param {String/Object} config A string to set only the panel's title, or a config object
659 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
661 Roo.TreePanel = function(config){
663 var tree = config.tree;
665 delete config.el; // hopefull!
667 // wrapper for IE7 strict & safari scroll issue
669 var treeEl = el.createChild();
670 config.resizeEl = treeEl;
674 Roo.TreePanel.superclass.constructor.call(this, el, config);
677 this.tree = new Roo.tree.TreePanel(treeEl , tree);
679 this.on('activate', function()
681 if (this.tree.rendered) {
684 //console.log('render tree');
688 this.on('resize', function (cp, w, h) {
689 this.tree.innerCt.setWidth(w);
690 this.tree.innerCt.setHeight(h);
691 this.tree.innerCt.setStyle('overflow-y', 'auto');
698 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {