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
15 * @children Roo.boootstrap.Component
16 * A basic ContentPanel element.
17 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
18 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
19 * @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
20 * @cfg {Boolean} closable True if the panel can be closed/removed
21 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
22 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
23 * @cfg {Toolbar} toolbar A toolbar for this panel
24 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
25 * @cfg {String} title The title for this panel
26 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
27 * @cfg {String} url Calls {@link #setUrl} with this value
28 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
29 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
30 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
31 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
32 * @cfg {Boolean} iframe contents are an iframe - makes showing remote sources/CSS feasible..
33 * @cfg {Boolean} badges render the badges
34 * @cfg {String} cls extra classes to use
35 * @cfg {String} background (primary|secondary|success|info|warning|danger|light|dark)
38 * Create a new ContentPanel.
39 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
40 * @param {String/Object} config A string to set only the title or a config object
41 * @param {String} content (optional) Set the HTML content for this panel
42 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
44 Roo.bootstrap.panel.Content = function( config){
46 this.tpl = config.tpl || false;
49 var content = config.content;
51 if(config.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);
65 cls: (config.cls || '') +
66 (config.background ? ' bg-' + config.background : '') +
67 " roo-layout-inactive-content",
74 style : 'border: 0px',
81 elcfg.html = config.html;
85 this.el = Roo.DomHelper.append(document.body, elcfg , true);
87 this.iframeEl = this.el.select('iframe',true).first();
92 this.closable = false;
97 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
99 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
101 this.wrapEl = this.el; //this.el.wrap();
103 if (config.toolbar.items) {
104 ti = config.toolbar.items ;
105 delete config.toolbar.items ;
109 this.toolbar.render(this.wrapEl, 'before');
110 for(var i =0;i < ti.length;i++) {
111 // Roo.log(['add child', items[i]]);
112 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
114 this.toolbar.items = nitems;
115 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
116 delete config.toolbar;
120 // xtype created footer. - not sure if will work as we normally have to render first..
121 if (this.footer && !this.footer.el && this.footer.xtype) {
123 this.wrapEl = this.el.wrap();
126 this.footer.container = this.wrapEl.createChild();
128 this.footer = Roo.factory(this.footer, Roo);
133 if(typeof config == "string"){
136 Roo.apply(this, config);
140 this.resizeEl = Roo.get(this.resizeEl, true);
142 this.resizeEl = this.el;
152 * Fires when this panel is activated.
153 * @param {Roo.ContentPanel} this
158 * Fires when this panel is activated.
159 * @param {Roo.ContentPanel} this
165 * Fires when this panel is resized if fitToFrame is true.
166 * @param {Roo.ContentPanel} this
167 * @param {Number} width The width after any component adjustments
168 * @param {Number} height The height after any component adjustments
174 * Fires when this tab is created
175 * @param {Roo.ContentPanel} this
181 * Fires when this content is scrolled
182 * @param {Roo.ContentPanel} this
183 * @param {Event} scrollEvent
194 if(this.autoScroll && !this.iframe){
195 this.resizeEl.setStyle("overflow", "auto");
196 this.resizeEl.on('scroll', this.onScroll, this);
198 // fix randome scrolling
199 //this.el.on('scroll', function() {
200 // Roo.log('fix random scolling');
201 // this.scrollTo('top',0);
204 content = content || this.content;
206 this.setContent(content);
208 if(config && config.url){
209 this.setUrl(this.url, this.params, this.loadOnce);
214 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
216 if (this.view && typeof(this.view.xtype) != 'undefined') {
217 this.view.el = this.el.appendChild(document.createElement("div"));
218 this.view = Roo.factory(this.view);
219 this.view.render && this.view.render(false, '');
223 this.fireEvent('render', this);
226 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
236 /* Resize Element - use this to work out scroll etc. */
239 setRegion : function(region){
240 this.region = region;
241 this.setActiveClass(region && !this.background);
245 setActiveClass: function(state)
248 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
249 this.el.setStyle('position','relative');
251 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
252 this.el.setStyle('position', 'absolute');
257 * Returns the toolbar for this Panel if one was configured.
258 * @return {Roo.Toolbar}
260 getToolbar : function(){
264 setActiveState : function(active)
266 this.active = active;
267 this.setActiveClass(active);
269 if(this.fireEvent("deactivate", this) === false){
274 this.fireEvent("activate", this);
278 * Updates this panel's element (not for iframe)
279 * @param {String} content The new content
280 * @param {Boolean} loadScripts (optional) true to look for and process scripts
282 setContent : function(content, loadScripts){
287 this.el.update(content, loadScripts);
290 ignoreResize : function(w, h){
291 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
294 this.lastSize = {width: w, height: h};
299 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
300 * @return {Roo.UpdateManager} The UpdateManager
302 getUpdateManager : function(){
306 return this.el.getUpdateManager();
309 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
310 * Does not work with IFRAME contents
311 * @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:
315 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
316 callback: yourFunction,
317 scope: yourObject, //(optional scope)
326 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
327 * 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.
328 * @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}
329 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
330 * @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.
331 * @return {Roo.ContentPanel} this
339 var um = this.el.getUpdateManager();
340 um.update.apply(um, arguments);
346 * 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.
347 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
348 * @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)
349 * @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)
350 * @return {Roo.UpdateManager|Boolean} The UpdateManager or false if IFRAME
352 setUrl : function(url, params, loadOnce){
354 this.iframeEl.dom.src = url;
358 if(this.refreshDelegate){
359 this.removeListener("activate", this.refreshDelegate);
361 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
362 this.on("activate", this.refreshDelegate);
363 return this.el.getUpdateManager();
366 _handleRefresh : function(url, params, loadOnce){
367 if(!loadOnce || !this.loaded){
368 var updater = this.el.getUpdateManager();
369 updater.update(url, params, this._setLoaded.createDelegate(this));
373 _setLoaded : function(){
378 * Returns this panel's id
386 * Returns this panel's element - used by regiosn to add.
387 * @return {Roo.Element}
390 return this.wrapEl || this.el;
395 adjustForComponents : function(width, height)
397 //Roo.log('adjustForComponents ');
398 if(this.resizeEl != this.el){
399 width -= this.el.getFrameWidth('lr');
400 height -= this.el.getFrameWidth('tb');
403 var te = this.toolbar.getEl();
405 height -= te.getHeight();
408 var te = this.footer.getEl();
410 height -= te.getHeight();
414 if(this.adjustments){
415 width += this.adjustments[0];
416 height += this.adjustments[1];
418 return {"width": width, "height": height};
421 setSize : function(width, height){
422 if(this.fitToFrame && !this.ignoreResize(width, height)){
423 if(this.fitContainer && this.resizeEl != this.el){
424 this.el.setSize(width, height);
426 var size = this.adjustForComponents(width, height);
428 this.iframeEl.setSize(width,height);
431 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
432 this.fireEvent('resize', this, size.width, size.height);
439 * Returns this panel's title
442 getTitle : function(){
444 if (typeof(this.title) != 'object') {
449 for (var k in this.title) {
450 if (!this.title.hasOwnProperty(k)) {
454 if (k.indexOf('-') >= 0) {
455 var s = k.split('-');
456 for (var i = 0; i<s.length; i++) {
457 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
460 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
467 * Set this panel's title
468 * @param {String} title
470 setTitle : function(title){
473 this.region.updatePanelTitle(this, title);
478 * Returns true is this panel was configured to be closable
481 isClosable : function(){
482 return this.closable;
485 beforeSlide : function(){
487 this.resizeEl.clip();
490 afterSlide : function(){
492 this.resizeEl.unclip();
496 * Force a content refresh from the URL specified in the {@link #setUrl} method.
497 * Will fail silently if the {@link #setUrl} method has not been called.
498 * This does not activate the panel, just updates its content.
500 refresh : function(){
501 if(this.refreshDelegate){
503 this.refreshDelegate();
508 * Destroys this panel
510 destroy : function(){
511 this.el.removeAllListeners();
512 var tempEl = document.createElement("span");
513 tempEl.appendChild(this.el.dom);
514 tempEl.innerHTML = "";
520 * form - if the content panel contains a form - this is a reference to it.
521 * @type {Roo.form.Form}
525 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
526 * This contains a reference to it.
532 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
542 * @param {Object} cfg Xtype definition of item to add.
546 getChildContainer: function () {
551 onScroll : function(e)
553 this.fireEvent('scroll', this, e);
558 var ret = new Roo.factory(cfg);
563 if (cfg.xtype.match(/^Form$/)) {
567 // el = this.footer.container.insertSibling(false, 'before');
569 el = this.el.createChild();
572 this.form = new Roo.form.Form(cfg);
575 if ( this.form.allItems.length) {
576 this.form.render(el.dom);
580 // should only have one of theses..
581 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
582 // views.. should not be just added - used named prop 'view''
584 cfg.el = this.el.appendChild(document.createElement("div"));
587 var ret = new Roo.factory(cfg);
589 ret.render && ret.render(false, ''); // render blank..