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} badges render the badges
31 * @cfg {String} cls extra classes to use
32 * @cfg {String} background (primary|secondary|success|info|warning|danger|light|dark)
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);
62 cls: "roo-layout-inactive-content",
66 elcfg.html = config.html;
70 this.el = Roo.DomHelper.append(document.body, elcfg , true);
73 this.closable = false;
78 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
80 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
82 this.wrapEl = this.el; //this.el.wrap();
84 if (config.toolbar.items) {
85 ti = config.toolbar.items ;
86 delete config.toolbar.items ;
90 this.toolbar.render(this.wrapEl, 'before');
91 for(var i =0;i < ti.length;i++) {
92 // Roo.log(['add child', items[i]]);
93 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
95 this.toolbar.items = nitems;
96 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
97 delete config.toolbar;
101 // xtype created footer. - not sure if will work as we normally have to render first..
102 if (this.footer && !this.footer.el && this.footer.xtype) {
104 this.wrapEl = this.el.wrap();
107 this.footer.container = this.wrapEl.createChild();
109 this.footer = Roo.factory(this.footer, Roo);
114 if(typeof config == "string"){
117 Roo.apply(this, config);
121 this.resizeEl = Roo.get(this.resizeEl, true);
123 this.resizeEl = this.el;
133 * Fires when this panel is activated.
134 * @param {Roo.ContentPanel} this
139 * Fires when this panel is activated.
140 * @param {Roo.ContentPanel} this
146 * Fires when this panel is resized if fitToFrame is true.
147 * @param {Roo.ContentPanel} this
148 * @param {Number} width The width after any component adjustments
149 * @param {Number} height The height after any component adjustments
155 * Fires when this tab is created
156 * @param {Roo.ContentPanel} this
168 this.resizeEl.setStyle("overflow", "auto");
170 // fix randome scrolling
171 //this.el.on('scroll', function() {
172 // Roo.log('fix random scolling');
173 // this.scrollTo('top',0);
176 content = content || this.content;
178 this.setContent(content);
180 if(config && config.url){
181 this.setUrl(this.url, this.params, this.loadOnce);
186 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
188 if (this.view && typeof(this.view.xtype) != 'undefined') {
189 this.view.el = this.el.appendChild(document.createElement("div"));
190 this.view = Roo.factory(this.view);
191 this.view.render && this.view.render(false, '');
195 this.fireEvent('render', this);
198 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
205 setRegion : function(region){
206 this.region = region;
207 this.setActiveClass(region && !this.background);
211 setActiveClass: function(state)
214 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
215 this.el.setStyle('position','relative');
217 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
218 this.el.setStyle('position', 'absolute');
223 * Returns the toolbar for this Panel if one was configured.
224 * @return {Roo.Toolbar}
226 getToolbar : function(){
230 setActiveState : function(active)
232 this.active = active;
233 this.setActiveClass(active);
235 if(this.fireEvent("deactivate", this) === false){
240 this.fireEvent("activate", this);
244 * Updates this panel's element
245 * @param {String} content The new content
246 * @param {Boolean} loadScripts (optional) true to look for and process scripts
248 setContent : function(content, loadScripts){
249 this.el.update(content, loadScripts);
252 ignoreResize : function(w, h){
253 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
256 this.lastSize = {width: w, height: h};
261 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
262 * @return {Roo.UpdateManager} The UpdateManager
264 getUpdateManager : function(){
265 return this.el.getUpdateManager();
268 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
269 * @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:
273 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
274 callback: yourFunction,
275 scope: yourObject, //(optional scope)
283 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
284 * 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.
285 * @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}
286 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
287 * @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.
288 * @return {Roo.ContentPanel} this
291 var um = this.el.getUpdateManager();
292 um.update.apply(um, arguments);
298 * 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.
299 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
300 * @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)
301 * @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)
302 * @return {Roo.UpdateManager} The UpdateManager
304 setUrl : function(url, params, loadOnce){
305 if(this.refreshDelegate){
306 this.removeListener("activate", this.refreshDelegate);
308 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
309 this.on("activate", this.refreshDelegate);
310 return this.el.getUpdateManager();
313 _handleRefresh : function(url, params, loadOnce){
314 if(!loadOnce || !this.loaded){
315 var updater = this.el.getUpdateManager();
316 updater.update(url, params, this._setLoaded.createDelegate(this));
320 _setLoaded : function(){
325 * Returns this panel's id
333 * Returns this panel's element - used by regiosn to add.
334 * @return {Roo.Element}
337 return this.wrapEl || this.el;
342 adjustForComponents : function(width, height)
344 //Roo.log('adjustForComponents ');
345 if(this.resizeEl != this.el){
346 width -= this.el.getFrameWidth('lr');
347 height -= this.el.getFrameWidth('tb');
350 var te = this.toolbar.getEl();
352 height -= te.getHeight();
355 var te = this.footer.getEl();
357 height -= te.getHeight();
361 if(this.adjustments){
362 width += this.adjustments[0];
363 height += this.adjustments[1];
365 return {"width": width, "height": height};
368 setSize : function(width, height){
369 if(this.fitToFrame && !this.ignoreResize(width, height)){
370 if(this.fitContainer && this.resizeEl != this.el){
371 this.el.setSize(width, height);
373 var size = this.adjustForComponents(width, height);
374 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
375 this.fireEvent('resize', this, size.width, size.height);
380 * Returns this panel's title
383 getTitle : function(){
385 if (typeof(this.title) != 'object') {
390 for (var k in this.title) {
391 if (!this.title.hasOwnProperty(k)) {
395 if (k.indexOf('-') >= 0) {
396 var s = k.split('-');
397 for (var i = 0; i<s.length; i++) {
398 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
401 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
408 * Set this panel's title
409 * @param {String} title
411 setTitle : function(title){
414 this.region.updatePanelTitle(this, title);
419 * Returns true is this panel was configured to be closable
422 isClosable : function(){
423 return this.closable;
426 beforeSlide : function(){
428 this.resizeEl.clip();
431 afterSlide : function(){
433 this.resizeEl.unclip();
437 * Force a content refresh from the URL specified in the {@link #setUrl} method.
438 * Will fail silently if the {@link #setUrl} method has not been called.
439 * This does not activate the panel, just updates its content.
441 refresh : function(){
442 if(this.refreshDelegate){
444 this.refreshDelegate();
449 * Destroys this panel
451 destroy : function(){
452 this.el.removeAllListeners();
453 var tempEl = document.createElement("span");
454 tempEl.appendChild(this.el.dom);
455 tempEl.innerHTML = "";
461 * form - if the content panel contains a form - this is a reference to it.
462 * @type {Roo.form.Form}
466 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
467 * This contains a reference to it.
473 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
483 * @param {Object} cfg Xtype definition of item to add.
487 getChildContainer: function () {
493 var ret = new Roo.factory(cfg);
498 if (cfg.xtype.match(/^Form$/)) {
502 // el = this.footer.container.insertSibling(false, 'before');
504 el = this.el.createChild();
507 this.form = new Roo.form.Form(cfg);
510 if ( this.form.allItems.length) {
511 this.form.render(el.dom);
515 // should only have one of theses..
516 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
517 // views.. should not be just added - used named prop 'view''
519 cfg.el = this.el.appendChild(document.createElement("div"));
522 var ret = new Roo.factory(cfg);
524 ret.render && ret.render(false, ''); // render blank..