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 = new Roo.Toolbar(this.el.insertSibling(false, 'before'), [] , this.toolbar);
85 this.resizeEl = Roo.get(this.resizeEl, true);
87 this.resizeEl = this.el;
92 * Fires when this panel is activated.
93 * @param {Roo.ContentPanel} this
98 * Fires when this panel is activated.
99 * @param {Roo.ContentPanel} this
105 * Fires when this panel is resized if fitToFrame is true.
106 * @param {Roo.ContentPanel} this
107 * @param {Number} width The width after any component adjustments
108 * @param {Number} height The height after any component adjustments
114 * Fires when this tab is created
115 * @param {Roo.ContentPanel} this
123 this.resizeEl.setStyle("overflow", "auto");
125 // fix randome scrolling
126 this.el.on('scroll', function() {
127 Roo.log('fix random scolling');
128 this.scrollTo('top',0);
131 content = content || this.content;
133 this.setContent(content);
135 if(config && config.url){
136 this.setUrl(this.url, this.params, this.loadOnce);
141 Roo.ContentPanel.superclass.constructor.call(this);
144 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
146 setRegion : function(region){
147 this.region = region;
149 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
151 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
156 * Returns the toolbar for this Panel if one was configured.
157 * @return {Roo.Toolbar}
159 getToolbar : function(){
163 setActiveState : function(active){
164 this.active = active;
166 this.fireEvent("deactivate", this);
168 this.fireEvent("activate", this);
172 * Updates this panel's element
173 * @param {String} content The new content
174 * @param {Boolean} loadScripts (optional) true to look for and process scripts
176 setContent : function(content, loadScripts){
177 this.el.update(content, loadScripts);
180 ignoreResize : function(w, h){
181 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
184 this.lastSize = {width: w, height: h};
189 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
190 * @return {Roo.UpdateManager} The UpdateManager
192 getUpdateManager : function(){
193 return this.el.getUpdateManager();
196 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
197 * @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:
201 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
202 callback: yourFunction,
203 scope: yourObject, //(optional scope)
211 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
212 * 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.
213 * @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}
214 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
215 * @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.
216 * @return {Roo.ContentPanel} this
219 var um = this.el.getUpdateManager();
220 um.update.apply(um, arguments);
226 * 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.
227 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
228 * @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)
229 * @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)
230 * @return {Roo.UpdateManager} The UpdateManager
232 setUrl : function(url, params, loadOnce){
233 if(this.refreshDelegate){
234 this.removeListener("activate", this.refreshDelegate);
236 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
237 this.on("activate", this.refreshDelegate);
238 return this.el.getUpdateManager();
241 _handleRefresh : function(url, params, loadOnce){
242 if(!loadOnce || !this.loaded){
243 var updater = this.el.getUpdateManager();
244 updater.update(url, params, this._setLoaded.createDelegate(this));
248 _setLoaded : function(){
253 * Returns this panel's id
261 * Returns this panel's element - used by regiosn to add.
262 * @return {Roo.Element}
265 return this.wrapEl || this.el;
268 adjustForComponents : function(width, height){
269 if(this.resizeEl != this.el){
270 width -= this.el.getFrameWidth('lr');
271 height -= this.el.getFrameWidth('tb');
274 var te = this.toolbar.getEl();
275 height -= te.getHeight();
278 if(this.adjustments){
279 width += this.adjustments[0];
280 height += this.adjustments[1];
282 return {"width": width, "height": height};
285 setSize : function(width, height){
286 if(this.fitToFrame && !this.ignoreResize(width, height)){
287 if(this.fitContainer && this.resizeEl != this.el){
288 this.el.setSize(width, height);
290 var size = this.adjustForComponents(width, height);
291 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
292 this.fireEvent('resize', this, size.width, size.height);
297 * Returns this panel's title
300 getTitle : function(){
305 * Set this panel's title
306 * @param {String} title
308 setTitle : function(title){
311 this.region.updatePanelTitle(this, title);
316 * Returns true is this panel was configured to be closable
319 isClosable : function(){
320 return this.closable;
323 beforeSlide : function(){
325 this.resizeEl.clip();
328 afterSlide : function(){
330 this.resizeEl.unclip();
334 * Force a content refresh from the URL specified in the {@link #setUrl} method.
335 * Will fail silently if the {@link #setUrl} method has not been called.
336 * This does not activate the panel, just updates its content.
338 refresh : function(){
339 if(this.refreshDelegate){
341 this.refreshDelegate();
346 * Destroys this panel
348 destroy : function(){
349 this.el.removeAllListeners();
350 var tempEl = document.createElement("span");
351 tempEl.appendChild(this.el.dom);
352 tempEl.innerHTML = "";
358 * form - if the content panel contains a form - this is a reference to it.
359 * @type {Roo.form.Form}
363 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
364 * This contains a reference to it.
370 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
380 * @param {Object} cfg Xtype definition of item to add.
383 addxtype : function(cfg) {
385 if (cfg.xtype.match(/^Form$/)) {
386 var el = this.el.createChild();
388 this.form = new Roo.form.Form(cfg);
391 if ( this.form.allItems.length) this.form.render(el.dom);
394 // should only have one of theses..
395 if (['View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
397 cfg.el = this.el.appendChild(document.createElement("div"));
400 var ret = new Roo.factory(cfg);
401 ret.render && ret.render(false, ''); // render blank..
410 * @class Roo.GridPanel
411 * @extends Roo.ContentPanel
413 * Create a new GridPanel.
414 * @param {Roo.grid.Grid} grid The grid for this panel
415 * @param {String/Object} config A string to set only the panel's title, or a config object
417 Roo.GridPanel = function(grid, config){
420 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
421 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
423 this.wrapper.dom.appendChild(grid.getGridEl().dom);
425 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
428 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
430 // xtype created footer. - not sure if will work as we normally have to render first..
431 if (this.footer && !this.footer.el && this.footer.xtype) {
433 this.footer.container = this.grid.getView().getFooterPanel(true);
434 this.footer.dataSource = this.grid.dataSource;
435 this.footer = Roo.factory(this.footer, Roo);
439 grid.monitorWindowResize = false; // turn off autosizing
440 grid.autoHeight = false;
441 grid.autoWidth = false;
443 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
446 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
452 * Returns the grid for this panel
453 * @return {Roo.grid.Grid}
455 getGrid : function(){
459 setSize : function(width, height){
460 if(!this.ignoreResize(width, height)){
461 var grid = this.grid;
462 var size = this.adjustForComponents(width, height);
463 grid.getGridEl().setSize(size.width, size.height);
468 beforeSlide : function(){
469 this.grid.getView().scroller.clip();
472 afterSlide : function(){
473 this.grid.getView().scroller.unclip();
476 destroy : function(){
479 Roo.GridPanel.superclass.destroy.call(this);
485 * @class Roo.NestedLayoutPanel
486 * @extends Roo.ContentPanel
488 * Create a new NestedLayoutPanel.
491 * @param {Roo.BorderLayout} layout The layout for this panel
492 * @param {String/Object} config A string to set only the title or a config object
494 Roo.NestedLayoutPanel = function(layout, config)
496 // construct with only one argument..
497 /* FIXME - implement nicer consturctors
500 layout = config.layout;
501 delete config.layout;
503 if (layout.xtype && !layout.getEl) {
504 // then layout needs constructing..
505 layout = Roo.factory(layout, Roo);
510 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
512 layout.monitorWindowResize = false; // turn off autosizing
513 this.layout = layout;
514 this.layout.getEl().addClass("x-layout-nested-layout");
521 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
523 setSize : function(width, height){
524 if(!this.ignoreResize(width, height)){
525 var size = this.adjustForComponents(width, height);
526 var el = this.layout.getEl();
527 el.setSize(size.width, size.height);
528 var touch = el.dom.offsetWidth;
529 this.layout.layout();
530 // ie requires a double layout on the first pass
531 if(Roo.isIE && !this.initialized){
532 this.initialized = true;
533 this.layout.layout();
538 // activate all subpanels if not currently active..
540 setActiveState : function(active){
541 this.active = active;
543 this.fireEvent("deactivate", this);
547 this.fireEvent("activate", this);
548 // not sure if this should happen before or after..
550 return; // should not happen..
553 for (var r in this.layout.regions) {
554 reg = this.layout.getRegion(r);
555 if (reg.getActivePanel()) {
556 //reg.showPanel(reg.getActivePanel()); // force it to activate..
557 reg.setActivePanel(reg.getActivePanel());
560 if (!reg.panels.length) {
563 reg.showPanel(reg.getPanel(0));
572 * Returns the nested BorderLayout for this panel
573 * @return {Roo.BorderLayout}
575 getLayout : function(){
580 * Adds a xtype elements to the layout of the nested panel
584 xtype : 'ContentPanel',
591 xtype : 'NestedLayoutPanel',
597 items : [ ... list of content panels or nested layout panels.. ]
601 * @param {Object} cfg Xtype definition of item to add.
603 addxtype : function(cfg) {
604 return this.layout.addxtype(cfg);
609 Roo.ScrollPanel = function(el, config, content){
610 config = config || {};
611 config.fitToFrame = true;
612 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
614 this.el.dom.style.overflow = "hidden";
615 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
616 this.el.removeClass("x-layout-inactive-content");
617 this.el.on("mousewheel", this.onWheel, this);
619 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
620 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
621 up.unselectable(); down.unselectable();
622 up.on("click", this.scrollUp, this);
623 down.on("click", this.scrollDown, this);
624 up.addClassOnOver("x-scroller-btn-over");
625 down.addClassOnOver("x-scroller-btn-over");
626 up.addClassOnClick("x-scroller-btn-click");
627 down.addClassOnClick("x-scroller-btn-click");
628 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
630 this.resizeEl = this.el;
631 this.el = wrap; this.up = up; this.down = down;
634 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
637 scrollUp : function(){
638 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
641 scrollDown : function(){
642 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
645 afterScroll : function(){
646 var el = this.resizeEl;
647 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
648 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
649 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
652 setSize : function(){
653 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
657 onWheel : function(e){
658 var d = e.getWheelDelta();
659 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
664 setContent : function(content, loadScripts){
665 this.resizeEl.update(content, loadScripts);
679 * @class Roo.TreePanel
680 * @extends Roo.ContentPanel
682 * Create a new TreePanel. - defaults to fit/scoll contents.
683 * @param {String/Object} config A string to set only the panel's title, or a config object
684 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
686 Roo.TreePanel = function(config){
688 var tree = config.tree;
690 delete config.el; // hopefull!
692 // wrapper for IE7 strict & safari scroll issue
694 var treeEl = el.createChild();
695 config.resizeEl = treeEl;
699 Roo.TreePanel.superclass.constructor.call(this, el, config);
702 this.tree = new Roo.tree.TreePanel(treeEl , tree);
704 this.on('activate', function()
706 if (this.tree.rendered) {
709 //console.log('render tree');
713 this.on('resize', function (cp, w, h) {
714 this.tree.innerCt.setWidth(w);
715 this.tree.innerCt.setHeight(h);
716 this.tree.innerCt.setStyle('overflow-y', 'auto');
723 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {