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|Object} title The title for this panel or object { 'xs-sm-md' : 'small title' , 'lg' : medim title ....}
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} badges render the badges
35 * Create a new ContentPanel.
36 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
37 * @param {String/Object} config A string to set only the title or a config object
38 * @param {String} content (optional) Set the HTML content for this panel
39 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
41 Roo.bootstrap.panel.Content = function( config){
43 this.tpl = config.tpl || false;
46 var content = config.content;
48 if(config.autoCreate){ // xtype is available if this is called from factory
51 this.el = Roo.get(el);
52 if(!this.el && config && config.autoCreate){
53 if(typeof config.autoCreate == "object"){
54 if(!config.autoCreate.id){
55 config.autoCreate.id = config.id||el;
57 this.el = Roo.DomHelper.append(document.body,
58 config.autoCreate, true);
60 var elcfg = { tag: "div",
61 cls: "roo-layout-inactive-content",
65 elcfg.html = config.html;
69 this.el = Roo.DomHelper.append(document.body, elcfg , true);
72 this.closable = false;
77 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
79 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
81 this.wrapEl = this.el; //this.el.wrap();
83 if (config.toolbar.items) {
84 ti = config.toolbar.items ;
85 delete config.toolbar.items ;
89 this.toolbar.render(this.wrapEl, 'before');
90 for(var i =0;i < ti.length;i++) {
91 // Roo.log(['add child', items[i]]);
92 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
94 this.toolbar.items = nitems;
95 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
96 delete config.toolbar;
100 // xtype created footer. - not sure if will work as we normally have to render first..
101 if (this.footer && !this.footer.el && this.footer.xtype) {
103 this.wrapEl = this.el.wrap();
106 this.footer.container = this.wrapEl.createChild();
108 this.footer = Roo.factory(this.footer, Roo);
113 if(typeof config == "string"){
116 Roo.apply(this, config);
119 // convert 'title' object into a string
121 // { 'xs-sm' : 'atitle', "md-lg": "xxxx"}
123 // <spam class="visible-xs .visible-sm">+hhhh+</span><span class="visible-md .visible-lg">{1}<span>
124 // show a roo.log messages if a size is not found ....
128 this.resizeEl = Roo.get(this.resizeEl, true);
130 this.resizeEl = this.el;
140 * Fires when this panel is activated.
141 * @param {Roo.ContentPanel} this
146 * Fires when this panel is activated.
147 * @param {Roo.ContentPanel} this
153 * Fires when this panel is resized if fitToFrame is true.
154 * @param {Roo.ContentPanel} this
155 * @param {Number} width The width after any component adjustments
156 * @param {Number} height The height after any component adjustments
162 * Fires when this tab is created
163 * @param {Roo.ContentPanel} this
175 this.resizeEl.setStyle("overflow", "auto");
177 // fix randome scrolling
178 //this.el.on('scroll', function() {
179 // Roo.log('fix random scolling');
180 // this.scrollTo('top',0);
183 content = content || this.content;
185 this.setContent(content);
187 if(config && config.url){
188 this.setUrl(this.url, this.params, this.loadOnce);
193 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
195 if (this.view && typeof(this.view.xtype) != 'undefined') {
196 this.view.el = this.el.appendChild(document.createElement("div"));
197 this.view = Roo.factory(this.view);
198 this.view.render && this.view.render(false, '');
202 this.fireEvent('render', this);
205 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
209 setRegion : function(region){
210 this.region = region;
211 this.setActiveClass(region && !this.background);
215 setActiveClass: function(state)
218 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
219 this.el.setStyle('position','relative');
221 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
222 this.el.setStyle('position', 'absolute');
227 * Returns the toolbar for this Panel if one was configured.
228 * @return {Roo.Toolbar}
230 getToolbar : function(){
234 setActiveState : function(active)
236 this.active = active;
237 this.setActiveClass(active);
239 this.fireEvent("deactivate", this);
241 this.fireEvent("activate", this);
245 * Updates this panel's element
246 * @param {String} content The new content
247 * @param {Boolean} loadScripts (optional) true to look for and process scripts
249 setContent : function(content, loadScripts){
250 this.el.update(content, loadScripts);
253 ignoreResize : function(w, h){
254 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
257 this.lastSize = {width: w, height: h};
262 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
263 * @return {Roo.UpdateManager} The UpdateManager
265 getUpdateManager : function(){
266 return this.el.getUpdateManager();
269 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
270 * @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:
274 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
275 callback: yourFunction,
276 scope: yourObject, //(optional scope)
284 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
285 * 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.
286 * @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}
287 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
288 * @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.
289 * @return {Roo.ContentPanel} this
292 var um = this.el.getUpdateManager();
293 um.update.apply(um, arguments);
299 * 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.
300 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
301 * @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)
302 * @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)
303 * @return {Roo.UpdateManager} The UpdateManager
305 setUrl : function(url, params, loadOnce){
306 if(this.refreshDelegate){
307 this.removeListener("activate", this.refreshDelegate);
309 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
310 this.on("activate", this.refreshDelegate);
311 return this.el.getUpdateManager();
314 _handleRefresh : function(url, params, loadOnce){
315 if(!loadOnce || !this.loaded){
316 var updater = this.el.getUpdateManager();
317 updater.update(url, params, this._setLoaded.createDelegate(this));
321 _setLoaded : function(){
326 * Returns this panel's id
334 * Returns this panel's element - used by regiosn to add.
335 * @return {Roo.Element}
338 return this.wrapEl || this.el;
343 adjustForComponents : function(width, height)
345 //Roo.log('adjustForComponents ');
346 if(this.resizeEl != this.el){
347 width -= this.el.getFrameWidth('lr');
348 height -= this.el.getFrameWidth('tb');
351 var te = this.toolbar.getEl();
352 height -= te.getHeight();
356 var te = this.footer.getEl();
357 Roo.log("footer:" + te.getHeight());
359 height -= te.getHeight();
364 if(this.adjustments){
365 width += this.adjustments[0];
366 height += this.adjustments[1];
368 return {"width": width, "height": height};
371 setSize : function(width, height){
372 if(this.fitToFrame && !this.ignoreResize(width, height)){
373 if(this.fitContainer && this.resizeEl != this.el){
374 this.el.setSize(width, height);
376 var size = this.adjustForComponents(width, height);
377 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
378 this.fireEvent('resize', this, size.width, size.height);
383 * Returns this panel's title
386 getTitle : function(){
391 * Set this panel's title
392 * @param {String} title
394 setTitle : function(title){
395 this.title = title+'testing';
397 this.region.updatePanelTitle(this, title);
402 * Returns true is this panel was configured to be closable
405 isClosable : function(){
406 return this.closable;
409 beforeSlide : function(){
411 this.resizeEl.clip();
414 afterSlide : function(){
416 this.resizeEl.unclip();
420 * Force a content refresh from the URL specified in the {@link #setUrl} method.
421 * Will fail silently if the {@link #setUrl} method has not been called.
422 * This does not activate the panel, just updates its content.
424 refresh : function(){
425 if(this.refreshDelegate){
427 this.refreshDelegate();
432 * Destroys this panel
434 destroy : function(){
435 this.el.removeAllListeners();
436 var tempEl = document.createElement("span");
437 tempEl.appendChild(this.el.dom);
438 tempEl.innerHTML = "";
444 * form - if the content panel contains a form - this is a reference to it.
445 * @type {Roo.form.Form}
449 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
450 * This contains a reference to it.
456 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
466 * @param {Object} cfg Xtype definition of item to add.
470 getChildContainer: function () {
476 var ret = new Roo.factory(cfg);
481 if (cfg.xtype.match(/^Form$/)) {
485 // el = this.footer.container.insertSibling(false, 'before');
487 el = this.el.createChild();
490 this.form = new Roo.form.Form(cfg);
493 if ( this.form.allItems.length) {
494 this.form.render(el.dom);
498 // should only have one of theses..
499 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
500 // views.. should not be just added - used named prop 'view''
502 cfg.el = this.el.appendChild(document.createElement("div"));
505 var ret = new Roo.factory(cfg);
507 ret.render && ret.render(false, ''); // render blank..