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 {Boolean} iframe contents are an iframe - makes showing remote sources/CSS feasible..
31 * @cfg {Boolean} badges render the badges
32 * @cfg {String} cls extra classes to use
33 * @cfg {String} background (primary|secondary|success|info|warning|danger|light|dark)
36 * Create a new ContentPanel.
37 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
38 * @param {String/Object} config A string to set only the title or a config object
39 * @param {String} content (optional) Set the HTML content for this panel
40 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
42 Roo.bootstrap.panel.Content = function( config){
44 this.tpl = config.tpl || false;
47 var content = config.content;
49 if(config.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);
63 cls: (config.cls || '') +
64 (config.background ? ' bg-' + config.background : '') +
65 " roo-layout-inactive-content",
79 elcfg.html = config.html;
83 this.el = Roo.DomHelper.append(document.body, elcfg , true);
86 this.closable = false;
91 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
93 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
95 this.wrapEl = this.el; //this.el.wrap();
97 if (config.toolbar.items) {
98 ti = config.toolbar.items ;
99 delete config.toolbar.items ;
103 this.toolbar.render(this.wrapEl, 'before');
104 for(var i =0;i < ti.length;i++) {
105 // Roo.log(['add child', items[i]]);
106 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
108 this.toolbar.items = nitems;
109 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
110 delete config.toolbar;
114 // xtype created footer. - not sure if will work as we normally have to render first..
115 if (this.footer && !this.footer.el && this.footer.xtype) {
117 this.wrapEl = this.el.wrap();
120 this.footer.container = this.wrapEl.createChild();
122 this.footer = Roo.factory(this.footer, Roo);
127 if(typeof config == "string"){
130 Roo.apply(this, config);
134 this.resizeEl = Roo.get(this.resizeEl, true);
136 this.resizeEl = this.el;
146 * Fires when this panel is activated.
147 * @param {Roo.ContentPanel} this
152 * Fires when this panel is activated.
153 * @param {Roo.ContentPanel} this
159 * Fires when this panel is resized if fitToFrame is true.
160 * @param {Roo.ContentPanel} this
161 * @param {Number} width The width after any component adjustments
162 * @param {Number} height The height after any component adjustments
168 * Fires when this tab is created
169 * @param {Roo.ContentPanel} this
181 this.resizeEl.setStyle("overflow", "auto");
183 // fix randome scrolling
184 //this.el.on('scroll', function() {
185 // Roo.log('fix random scolling');
186 // this.scrollTo('top',0);
189 content = content || this.content;
191 this.setContent(content);
193 if(config && config.url){
194 this.setUrl(this.url, this.params, this.loadOnce);
199 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
201 if (this.view && typeof(this.view.xtype) != 'undefined') {
202 this.view.el = this.el.appendChild(document.createElement("div"));
203 this.view = Roo.factory(this.view);
204 this.view.render && this.view.render(false, '');
208 this.fireEvent('render', this);
211 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
220 setRegion : function(region){
221 this.region = region;
222 this.setActiveClass(region && !this.background);
226 setActiveClass: function(state)
229 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
230 this.el.setStyle('position','relative');
232 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
233 this.el.setStyle('position', 'absolute');
238 * Returns the toolbar for this Panel if one was configured.
239 * @return {Roo.Toolbar}
241 getToolbar : function(){
245 setActiveState : function(active)
247 this.active = active;
248 this.setActiveClass(active);
250 if(this.fireEvent("deactivate", this) === false){
255 this.fireEvent("activate", this);
259 * Updates this panel's element
260 * @param {String} content The new content
261 * @param {Boolean} loadScripts (optional) true to look for and process scripts
263 setContent : function(content, loadScripts){
264 this.el.update(content, loadScripts);
267 ignoreResize : function(w, h){
268 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
271 this.lastSize = {width: w, height: h};
276 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
277 * @return {Roo.UpdateManager} The UpdateManager
279 getUpdateManager : function(){
280 return this.el.getUpdateManager();
283 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
284 * @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:
288 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
289 callback: yourFunction,
290 scope: yourObject, //(optional scope)
298 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
299 * 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.
300 * @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}
301 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
302 * @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.
303 * @return {Roo.ContentPanel} this
306 var um = this.el.getUpdateManager();
307 um.update.apply(um, arguments);
313 * 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.
314 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
315 * @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)
316 * @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)
317 * @return {Roo.UpdateManager} The UpdateManager
319 setUrl : function(url, params, loadOnce){
320 if(this.refreshDelegate){
321 this.removeListener("activate", this.refreshDelegate);
323 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
324 this.on("activate", this.refreshDelegate);
325 return this.el.getUpdateManager();
328 _handleRefresh : function(url, params, loadOnce){
329 if(!loadOnce || !this.loaded){
330 var updater = this.el.getUpdateManager();
331 updater.update(url, params, this._setLoaded.createDelegate(this));
335 _setLoaded : function(){
340 * Returns this panel's id
348 * Returns this panel's element - used by regiosn to add.
349 * @return {Roo.Element}
352 return this.wrapEl || this.el;
357 adjustForComponents : function(width, height)
359 //Roo.log('adjustForComponents ');
360 if(this.resizeEl != this.el){
361 width -= this.el.getFrameWidth('lr');
362 height -= this.el.getFrameWidth('tb');
365 var te = this.toolbar.getEl();
367 height -= te.getHeight();
370 var te = this.footer.getEl();
372 height -= te.getHeight();
376 if(this.adjustments){
377 width += this.adjustments[0];
378 height += this.adjustments[1];
380 return {"width": width, "height": height};
383 setSize : function(width, height){
384 if(this.fitToFrame && !this.ignoreResize(width, height)){
385 if(this.fitContainer && this.resizeEl != this.el){
386 this.el.setSize(width, height);
388 var size = this.adjustForComponents(width, height);
389 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
390 this.fireEvent('resize', this, size.width, size.height);
395 * Returns this panel's title
398 getTitle : function(){
400 if (typeof(this.title) != 'object') {
405 for (var k in this.title) {
406 if (!this.title.hasOwnProperty(k)) {
410 if (k.indexOf('-') >= 0) {
411 var s = k.split('-');
412 for (var i = 0; i<s.length; i++) {
413 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
416 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
423 * Set this panel's title
424 * @param {String} title
426 setTitle : function(title){
429 this.region.updatePanelTitle(this, title);
434 * Returns true is this panel was configured to be closable
437 isClosable : function(){
438 return this.closable;
441 beforeSlide : function(){
443 this.resizeEl.clip();
446 afterSlide : function(){
448 this.resizeEl.unclip();
452 * Force a content refresh from the URL specified in the {@link #setUrl} method.
453 * Will fail silently if the {@link #setUrl} method has not been called.
454 * This does not activate the panel, just updates its content.
456 refresh : function(){
457 if(this.refreshDelegate){
459 this.refreshDelegate();
464 * Destroys this panel
466 destroy : function(){
467 this.el.removeAllListeners();
468 var tempEl = document.createElement("span");
469 tempEl.appendChild(this.el.dom);
470 tempEl.innerHTML = "";
476 * form - if the content panel contains a form - this is a reference to it.
477 * @type {Roo.form.Form}
481 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
482 * This contains a reference to it.
488 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
498 * @param {Object} cfg Xtype definition of item to add.
502 getChildContainer: function () {
508 var ret = new Roo.factory(cfg);
513 if (cfg.xtype.match(/^Form$/)) {
517 // el = this.footer.container.insertSibling(false, 'before');
519 el = this.el.createChild();
522 this.form = new Roo.form.Form(cfg);
525 if ( this.form.allItems.length) {
526 this.form.render(el.dom);
530 // should only have one of theses..
531 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
532 // views.. should not be just added - used named prop 'view''
534 cfg.el = this.el.appendChild(document.createElement("div"));
537 var ret = new Roo.factory(cfg);
539 ret.render && ret.render(false, ''); // render blank..