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.)
30 * @cfg {String} style Extra style to add to the content panel
33 * Create a new ContentPanel.
34 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
35 * @param {String/Object} config A string to set only the title or a config object
36 * @param {String} content (optional) Set the HTML content for this panel
37 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
39 Roo.ContentPanel = function(el, config, content){
43 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
47 if (config && config.parentLayout) {
48 el = config.parentLayout.el.createChild();
51 if(el.autoCreate){ // xtype is available if this is called from factory
55 this.el = Roo.get(el);
56 if(!this.el && config && config.autoCreate){
57 if(typeof config.autoCreate == "object"){
58 if(!config.autoCreate.id){
59 config.autoCreate.id = config.id||el;
61 this.el = Roo.DomHelper.append(document.body,
62 config.autoCreate, true);
64 this.el = Roo.DomHelper.append(document.body,
65 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
70 this.closable = false;
73 if(typeof config == "string"){
76 Roo.apply(this, config);
79 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
80 this.wrapEl = this.el.wrap();
81 this.toolbar.container = this.el.insertSibling(false, 'before');
82 this.toolbar = new Roo.Toolbar(this.toolbar);
85 // xtype created footer. - not sure if will work as we normally have to render first..
86 if (this.footer && !this.footer.el && this.footer.xtype) {
88 this.wrapEl = this.el.wrap();
91 this.footer.container = this.wrapEl.createChild();
93 this.footer = Roo.factory(this.footer, Roo);
98 this.resizeEl = Roo.get(this.resizeEl, true);
100 this.resizeEl = this.el;
110 * Fires when this panel is activated.
111 * @param {Roo.ContentPanel} this
116 * Fires when this panel is activated.
117 * @param {Roo.ContentPanel} this
123 * Fires when this panel is resized if fitToFrame is true.
124 * @param {Roo.ContentPanel} this
125 * @param {Number} width The width after any component adjustments
126 * @param {Number} height The height after any component adjustments
132 * Fires when this tab is created
133 * @param {Roo.ContentPanel} this
144 this.resizeEl.setStyle("overflow", "auto");
146 // fix randome scrolling
147 this.el.on('scroll', function() {
148 Roo.log('fix random scolling');
149 this.scrollTo('top',0);
152 content = content || this.content;
154 this.setContent(content);
156 if(config && config.url){
157 this.setUrl(this.url, this.params, this.loadOnce);
162 Roo.ContentPanel.superclass.constructor.call(this);
164 if (this.view && typeof(this.view.xtype) != 'undefined') {
165 this.view.el = this.el.appendChild(document.createElement("div"));
166 this.view = Roo.factory(this.view);
167 this.view.render && this.view.render(false, '');
171 this.fireEvent('render', this);
174 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
176 setRegion : function(region){
177 this.region = region;
179 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
181 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
186 * Returns the toolbar for this Panel if one was configured.
187 * @return {Roo.Toolbar}
189 getToolbar : function(){
193 setActiveState : function(active){
194 this.active = active;
196 this.fireEvent("deactivate", this);
198 this.fireEvent("activate", this);
202 * Updates this panel's element
203 * @param {String} content The new content
204 * @param {Boolean} loadScripts (optional) true to look for and process scripts
206 setContent : function(content, loadScripts){
207 this.el.update(content, loadScripts);
210 ignoreResize : function(w, h){
211 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
214 this.lastSize = {width: w, height: h};
219 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
220 * @return {Roo.UpdateManager} The UpdateManager
222 getUpdateManager : function(){
223 return this.el.getUpdateManager();
226 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
227 * @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:
231 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
232 callback: yourFunction,
233 scope: yourObject, //(optional scope)
241 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
242 * 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.
243 * @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}
244 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
245 * @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.
246 * @return {Roo.ContentPanel} this
249 var um = this.el.getUpdateManager();
250 um.update.apply(um, arguments);
256 * 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.
257 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
258 * @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)
259 * @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)
260 * @return {Roo.UpdateManager} The UpdateManager
262 setUrl : function(url, params, loadOnce){
263 if(this.refreshDelegate){
264 this.removeListener("activate", this.refreshDelegate);
266 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
267 this.on("activate", this.refreshDelegate);
268 return this.el.getUpdateManager();
271 _handleRefresh : function(url, params, loadOnce){
272 if(!loadOnce || !this.loaded){
273 var updater = this.el.getUpdateManager();
274 updater.update(url, params, this._setLoaded.createDelegate(this));
278 _setLoaded : function(){
283 * Returns this panel's id
291 * Returns this panel's element - used by regiosn to add.
292 * @return {Roo.Element}
295 return this.wrapEl || this.el;
298 adjustForComponents : function(width, height)
300 //Roo.log('adjustForComponents ');
301 if(this.resizeEl != this.el){
302 width -= this.el.getFrameWidth('lr');
303 height -= this.el.getFrameWidth('tb');
306 var te = this.toolbar.getEl();
307 height -= te.getHeight();
311 var te = this.footer.getEl();
312 //Roo.log("footer:" + te.getHeight());
314 height -= te.getHeight();
319 if(this.adjustments){
320 width += this.adjustments[0];
321 height += this.adjustments[1];
323 return {"width": width, "height": height};
326 setSize : function(width, height){
327 if(this.fitToFrame && !this.ignoreResize(width, height)){
328 if(this.fitContainer && this.resizeEl != this.el){
329 this.el.setSize(width, height);
331 var size = this.adjustForComponents(width, height);
332 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
333 this.fireEvent('resize', this, size.width, size.height);
338 * Returns this panel's title
341 getTitle : function(){
346 * Set this panel's title
347 * @param {String} title
349 setTitle : function(title){
352 this.region.updatePanelTitle(this, title);
357 * Returns true is this panel was configured to be closable
360 isClosable : function(){
361 return this.closable;
364 beforeSlide : function(){
366 this.resizeEl.clip();
369 afterSlide : function(){
371 this.resizeEl.unclip();
375 * Force a content refresh from the URL specified in the {@link #setUrl} method.
376 * Will fail silently if the {@link #setUrl} method has not been called.
377 * This does not activate the panel, just updates its content.
379 refresh : function(){
380 if(this.refreshDelegate){
382 this.refreshDelegate();
387 * Destroys this panel
389 destroy : function(){
390 this.el.removeAllListeners();
391 var tempEl = document.createElement("span");
392 tempEl.appendChild(this.el.dom);
393 tempEl.innerHTML = "";
399 * form - if the content panel contains a form - this is a reference to it.
400 * @type {Roo.form.Form}
404 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
405 * This contains a reference to it.
411 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
421 * @param {Object} cfg Xtype definition of item to add.
424 addxtype : function(cfg) {
426 if (cfg.xtype.match(/^Form$/)) {
430 // el = this.footer.container.insertSibling(false, 'before');
432 el = this.el.createChild();
435 this.form = new Roo.form.Form(cfg);
438 if ( this.form.allItems.length) {
439 this.form.render(el.dom);
443 // should only have one of theses..
444 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
445 // views.. should not be just added - used named prop 'view''
447 cfg.el = this.el.appendChild(document.createElement("div"));
450 var ret = new Roo.factory(cfg);
452 ret.render && ret.render(false, ''); // render blank..
461 * @class Roo.GridPanel
462 * @extends Roo.ContentPanel
464 * Create a new GridPanel.
465 * @param {Roo.grid.Grid} grid The grid for this panel
466 * @param {String/Object} config A string to set only the panel's title, or a config object
468 Roo.GridPanel = function(grid, config){
471 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
472 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
474 this.wrapper.dom.appendChild(grid.getGridEl().dom);
476 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
479 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
481 // xtype created footer. - not sure if will work as we normally have to render first..
482 if (this.footer && !this.footer.el && this.footer.xtype) {
484 this.footer.container = this.grid.getView().getFooterPanel(true);
485 this.footer.dataSource = this.grid.dataSource;
486 this.footer = Roo.factory(this.footer, Roo);
490 grid.monitorWindowResize = false; // turn off autosizing
491 grid.autoHeight = false;
492 grid.autoWidth = false;
494 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
497 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
503 * Returns the grid for this panel
504 * @return {Roo.grid.Grid}
506 getGrid : function(){
510 setSize : function(width, height){
511 if(!this.ignoreResize(width, height)){
512 var grid = this.grid;
513 var size = this.adjustForComponents(width, height);
514 grid.getGridEl().setSize(size.width, size.height);
519 beforeSlide : function(){
520 this.grid.getView().scroller.clip();
523 afterSlide : function(){
524 this.grid.getView().scroller.unclip();
527 destroy : function(){
530 Roo.GridPanel.superclass.destroy.call(this);
536 * @class Roo.NestedLayoutPanel
537 * @extends Roo.ContentPanel
539 * Create a new NestedLayoutPanel.
542 * @param {Roo.BorderLayout} layout The layout for this panel
543 * @param {String/Object} config A string to set only the title or a config object
545 Roo.NestedLayoutPanel = function(layout, config)
547 // construct with only one argument..
548 /* FIXME - implement nicer consturctors
551 layout = config.layout;
552 delete config.layout;
554 if (layout.xtype && !layout.getEl) {
555 // then layout needs constructing..
556 layout = Roo.factory(layout, Roo);
561 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
563 layout.monitorWindowResize = false; // turn off autosizing
564 this.layout = layout;
565 this.layout.getEl().addClass("x-layout-nested-layout");
572 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
574 setSize : function(width, height){
575 if(!this.ignoreResize(width, height)){
576 var size = this.adjustForComponents(width, height);
577 var el = this.layout.getEl();
578 el.setSize(size.width, size.height);
579 var touch = el.dom.offsetWidth;
580 this.layout.layout();
581 // ie requires a double layout on the first pass
582 if(Roo.isIE && !this.initialized){
583 this.initialized = true;
584 this.layout.layout();
589 // activate all subpanels if not currently active..
591 setActiveState : function(active){
592 this.active = active;
594 this.fireEvent("deactivate", this);
598 this.fireEvent("activate", this);
599 // not sure if this should happen before or after..
601 return; // should not happen..
604 for (var r in this.layout.regions) {
605 reg = this.layout.getRegion(r);
606 if (reg.getActivePanel()) {
607 //reg.showPanel(reg.getActivePanel()); // force it to activate..
608 reg.setActivePanel(reg.getActivePanel());
611 if (!reg.panels.length) {
614 reg.showPanel(reg.getPanel(0));
623 * Returns the nested BorderLayout for this panel
624 * @return {Roo.BorderLayout}
626 getLayout : function(){
631 * Adds a xtype elements to the layout of the nested panel
635 xtype : 'ContentPanel',
642 xtype : 'NestedLayoutPanel',
648 items : [ ... list of content panels or nested layout panels.. ]
652 * @param {Object} cfg Xtype definition of item to add.
654 addxtype : function(cfg) {
655 return this.layout.addxtype(cfg);
660 Roo.ScrollPanel = function(el, config, content){
661 config = config || {};
662 config.fitToFrame = true;
663 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
665 this.el.dom.style.overflow = "hidden";
666 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
667 this.el.removeClass("x-layout-inactive-content");
668 this.el.on("mousewheel", this.onWheel, this);
670 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
671 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
672 up.unselectable(); down.unselectable();
673 up.on("click", this.scrollUp, this);
674 down.on("click", this.scrollDown, this);
675 up.addClassOnOver("x-scroller-btn-over");
676 down.addClassOnOver("x-scroller-btn-over");
677 up.addClassOnClick("x-scroller-btn-click");
678 down.addClassOnClick("x-scroller-btn-click");
679 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
681 this.resizeEl = this.el;
682 this.el = wrap; this.up = up; this.down = down;
685 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
688 scrollUp : function(){
689 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
692 scrollDown : function(){
693 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
696 afterScroll : function(){
697 var el = this.resizeEl;
698 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
699 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
700 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
703 setSize : function(){
704 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
708 onWheel : function(e){
709 var d = e.getWheelDelta();
710 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
715 setContent : function(content, loadScripts){
716 this.resizeEl.update(content, loadScripts);
730 * @class Roo.TreePanel
731 * @extends Roo.ContentPanel
733 * Create a new TreePanel. - defaults to fit/scoll contents.
734 * @param {String/Object} config A string to set only the panel's title, or a config object
735 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
737 Roo.TreePanel = function(config){
739 var tree = config.tree;
741 delete config.el; // hopefull!
743 // wrapper for IE7 strict & safari scroll issue
745 var treeEl = el.createChild();
746 config.resizeEl = treeEl;
750 Roo.TreePanel.superclass.constructor.call(this, el, config);
753 this.tree = new Roo.tree.TreePanel(treeEl , tree);
755 this.on('activate', function()
757 if (this.tree.rendered) {
760 //console.log('render tree');
763 // this should not be needed.. - it's actually the 'el' that resizes?
764 // actuall it breaks the containerScroll - dragging nodes auto scroll at top
766 //this.on('resize', function (cp, w, h) {
767 // this.tree.innerCt.setWidth(w);
768 // this.tree.innerCt.setHeight(h);
769 // //this.tree.innerCt.setStyle('overflow-y', 'auto');
776 Roo.extend(Roo.TreePanel, Roo.ContentPanel, {