X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/source/widgets/Panel.js diff --git a/source/widgets/Panel.js b/source/widgets/Panel.js deleted file mode 100644 index f168fdd4..00000000 --- a/source/widgets/Panel.js +++ /dev/null @@ -1,1414 +0,0 @@ -/* - * Ext JS Library 2.2.1 - * Copyright(c) 2006-2009, Ext JS, LLC. - * licensing@extjs.com - * - * http://extjs.com/license - */ - -/** - * @class Ext.Panel - * @extends Ext.Container - * Panel is a container that has specific functionality and structural components that make it the perfect building - * block for application-oriented user interfaces. The Panel contains bottom and top toolbars, along with separate - * header, footer and body sections. It also provides built-in expandable and collapsible behavior, along with a - * variety of prebuilt tool buttons that can be wired up to provide other customized behavior. Panels can be easily - * dropped into any Container or layout, and the layout and rendering pipeline is completely managed by the framework. - * @constructor - * @param {Object} config The config object - */ -Ext.Panel = Ext.extend(Ext.Container, { - /** - * The Panel's header {@link Ext.Element Element}. Read-only. - *
This Element is used to house the {@link #title} and {@link #tools}
- * @type Ext.Element - * @property header - */ - /** - * The Panel's body {@link Ext.Element Element} which may be used to contain HTML content. - * The content may be specified in the {@link #html} config, or it may be loaded using the - * {@link autoLoad} config, or through the Panel's {@link #getUpdater Updater}. Read-only. - *If this is used to load visible HTML elements in either way, then - * the Panel may not be used as a Layout for hosting nested Panels.
- *If this Panel is intended to be used as the host of a Layout (See {@link #layout} - * then the body Element must not be loaded or changed - it is under the control - * of the Panel's Layout. - * @type Ext.Element - * @property body - */ - /** - * @cfg {Object} bodyCfg - *
A {@link Ext.DomHelper DomHelper} configuration object specifying the element structure - * of this Panel's {@link #body} Element.
- *This may be used to force the body Element to use a different form of markup than - * is created automatically. An example of this might be to create a child Panel containing - * custom content, such as a header, or forcing centering of all Panel - * content by having the body be a <center> element:
-new Ext.Panel({
- title: 'New Message',
- collapsible: true,
- renderTo: Ext.getBody(),
- width: 400,
- bodyCfg: {
- tag: 'center',
- cls: 'x-panel-body'
- },
- items: [{
- border: false,
- header: false,
- bodyCfg: {tag: 'h2', html: 'Message'}
- }, {
- xtype: 'textarea',
- style: {
- width: '95%',
- marginBottom: '10px'
- }
- },
- new Ext.Button({
- text: 'Send',
- minWidth: '100',
- style: {
- marginBottom: '10px'
- }
- })
- ]
-});
- */
- /**
- * The Panel's footer {@link Ext.Element Element}. Read-only.
- * This Element is used to house the Panel's {@link #buttons}.
- * @type Ext.Element - * @property footer - */ - /** - * @cfg {Mixed} applyTo - * The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in - * the document that specifies some panel-specific structural markup. When applyTo is used, constituent parts of - * the panel can be specified by CSS class name within the main element, and the panel will automatically create those - * components from that markup. Any required components not specified in the markup will be autogenerated if necessary. - * The following class names are supported (baseCls will be replaced by {@link #baseCls}): - *- * The URL will become the default URL for this panel's {@link #body} element, - * so it may be {@link Ext.Element#refresh refresh}ed at any time.
- */ - /** - * @cfg {Boolean} frame - * True to render the panel with custom rounded borders, false to render with plain 1px square borders (defaults to false). - */ - /** - * @cfg {Boolean} border - * True to display the borders of the panel's body element, false to hide them (defaults to true). By default, - * the border is a 2px wide inset border, but this can be further altered by setting {@link #bodyBorder} to false. - */ - /** - * @cfg {Boolean} bodyBorder - * True to display an interior border on the body element of the panel, false to hide it (defaults to true). - * This only applies when {@link #border} == true. If border == true and bodyBorder == false, the border will display - * as a 1px wide inset border, giving the entire body element an inset appearance. - */ - /** - * @cfg {String/Object/Function} bodyStyle - * Custom CSS styles to be applied to the body element in the format expected by {@link Ext.Element#applyStyles} - * (defaults to null). - */ - /** - * @cfg {String} iconCls - * A CSS class that will provide a background image to be used as the header icon (defaults to ''). An example - * custom icon class would be something like: .my-icon { background: url(../images/my-icon.gif) 0 6px no-repeat !important;} - */ - /** - * @cfg {Boolean} collapsible - * True to make the panel collapsible and have the expand/collapse toggle button automatically rendered into - * the header tool button area, false to keep the panel statically sized with no button (defaults to false). - */ - /** - * @cfg {Array} tools - * An array of tool button configs to be added to the header tool area. When rendered, each tool is - * stored as an {@link Ext.Element Element} referenced by a public property called tools.<tool-type> - *Each tool config may contain the following properties: - *
-tools:[{
- id:'refresh',
- qtip: 'Refresh form Data',
- // hidden:true,
- handler: function(event, toolEl, panel){
- // refresh logic
- }
-}]
-
- * Note that apart from the toggle tool which is provided when a panel is
- * collapsible, these tools only provide the visual button. Any required
- * functionality must be provided by adding handlers that implement the
- * necessary behavior.
- */
- /**
- * @cfg {Boolean} hideCollapseTool
- * True to hide the expand/collapse toggle button when {@link #collapsible} = true, false to display it (defaults to false).
- */
- /**
- * @cfg {Boolean} titleCollapse
- * True to allow expanding and collapsing the panel (when {@link #collapsible} = true) by clicking anywhere in the
- * header bar, false to allow it only by clicking to tool button (defaults to false).
- */
- /**
- * @cfg {Boolean} autoScroll
- * True to use overflow:'auto' on the panel's body element and show scroll bars automatically when necessary,
- * false to clip any overflowing content (defaults to false).
- */
- /**
- * @cfg {Boolean} floating
- * True to float the panel (absolute position it with automatic shimming and shadow), false to display it
- * inline where it is rendered (defaults to false). Note that by default, setting floating to true will cause the
- * panel to display at negative offsets so that it is hidden -- because the panel is absolute positioned, the
- * position must be set explicitly after render (e.g., myPanel.setPosition(100,100);). Also, when floating a
- * panel you should always assign a fixed width, otherwise it will be auto width and will expand to fill to the
- * right edge of the viewport.
- */
- /**
- * @cfg {Boolean/String} shadow
- * True (or a valid Ext.Shadow {@link Ext.Shadow#mode} value) to display a shadow behind the panel, false to
- * display no shadow (defaults to 'sides'). Note that this option only applies when floating = true.
- */
- /**
- * @cfg {Number} shadowOffset
- * The number of pixels to offset the shadow if displayed (defaults to 4). Note that this option only applies
- * when floating = true.
- */
- /**
- * @cfg {Boolean} shim
- * False to disable the iframe shim in browsers which need one (defaults to true). Note that this option
- * only applies when floating = true.
- */
- /**
- * @cfg {String/Object} html
- * An HTML fragment, or a {@link Ext.DomHelper DomHelper} specification to use
- * as the panel's body content (defaults to ''). The HTML content is added by the Panel's
- * afterRender method, and so the document will not contain this HTML at the time the render
- * event is fired. This content is inserted into the body before any configured
- * {@link #contentEl} is appended.
- */
- /**
- * @cfg {String} contentEl
- * The id of an existing HTML node to use as the panel's body content (defaults to ''). The
- * specified Element is appended to the Panel's body Element by the Panel's afterRender method
- * after any configured {@link #html HTML} has been inserted, and so the document will
- * not contain this HTML at the time the render event is fired.
- */
- /**
- * @cfg {Object/Array} keys
- * A KeyMap config object (in the format expected by {@link Ext.KeyMap#addBinding} used to assign custom key
- * handling to this panel (defaults to null).
- */
- /**
- * @cfg {Boolean} draggable
- * True to enable dragging of this Panel (defaults to false).
- *For custom drag/drop implementations, an Ext.Panel.DD - * config could also be passed in this config instead of true. Ext.Panel.DD is an internal, - * undocumented class which moves a proxy Element around in place of the Panel's element, but - * provides no other behaviour during dragging or on drop. It is a subclass of - * {@link Ext.dd.DragSource}, so behaviour may be added by implementing the interface methods - * of {@link Ext.dd.DragDrop} eg: - *
-new Ext.Panel({
- title: 'Drag me',
- x: 100,
- y: 100,
- renderTo: Ext.getBody(),
- floating: true,
- frame: true,
- width: 400,
- height: 200,
- draggable: {
-// Config option of Ext.Panel.DD class.
-// It's a floating Panel, so do not show a placeholder proxy in the original position.
- insertProxy: false,
-
-// Called for each mousemove event while dragging the DD object.
- onDrag : function(e){
-// Record the x,y position of the drag proxy so that we can
-// position the Panel at end of drag.
- var pel = this.proxy.getEl();
- this.x = pel.getLeft(true);
- this.y = pel.getTop(true);
-
-// Keep the Shadow aligned if there is one.
- var s = this.panel.getEl().shadow;
- if (s) {
- s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
- }
- },
-
-// Called on the mouseup event.
- endDrag : function(e){
- this.panel.setPosition(this.x, this.y);
- }
- }
-}).show();
-
- */
- /**
- * @cfg {String} tabTip
- * Adds a tooltip when mousing over the tab of a Ext.Panel which is an item of a Ext.TabPanel. Ext.QuickTips.init()
- * must be called in order for the tips to render.
- */
- /**
- * @cfg {Boolean} disabled
- * Render this panel disabled (default is false). An important note when using the disabled config on panels is
- * that IE will often fail to initialize the disabled mask element correectly if the panel's layout has not yet
- * completed by the time the Panel is disabled during the render process. If you experience this issue, you may
- * need to instead use the {@link afterlayout} event to initialize the disabled state:
- *
-new Ext.Panel({
- ...
- listeners: {
- 'afterlayout': {
- fn: function(p){
- p.disable();
- },
- single: true // important, as many layouts can occur
- }
- }
-});
-
- */
- /**
- * @cfg {Boolean} autoHeight
- * True to use height:'auto', false to use fixed height (defaults to false). Note: Setting autoHeight:true
- * means that the browser will manage the panel's height based on its contents, and that Ext will not manage it at
- * all. If the panel is within a layout that manages dimensions (fit, border, etc.) then setting autoHeight:true
- * can cause issues with scrolling and will not generally work as expected since the panel will take on the height
- * of its contents rather than the height required by the Ext layout.
- */
-
-
- /**
- * @cfg {String} baseCls
- * The base CSS class to apply to this panel's element (defaults to 'x-panel').
- */
- baseCls : 'x-panel',
- /**
- * @cfg {String} collapsedCls
- * A CSS class to add to the panel's element after it has been collapsed (defaults to 'x-panel-collapsed').
- */
- collapsedCls : 'x-panel-collapsed',
- /**
- * @cfg {Boolean} maskDisabled
- * True to mask the panel when it is disabled, false to not mask it (defaults to true). Either way, the panel
- * will always tell its contained elements to disable themselves when it is disabled, but masking the panel
- * can provide an additional visual cue that the panel is disabled.
- */
- maskDisabled: true,
- /**
- * @cfg {Boolean} animCollapse
- * True to animate the transition when the panel is collapsed, false to skip the animation (defaults to true
- * if the {@link Ext.Fx} class is available, otherwise false).
- */
- animCollapse: Ext.enableFx,
- /**
- * @cfg {Boolean} headerAsText
- * True to display the panel title in the header, false to hide it (defaults to true).
- */
- headerAsText: true,
- /**
- * @cfg {String} buttonAlign
- * The alignment of any buttons added to this panel. Valid values are 'right,' 'left' and 'center' (defaults to 'right').
- */
- buttonAlign: 'right',
- /**
- * @cfg {Boolean} collapsed
- * True to render the panel collapsed, false to render it expanded (defaults to false).
- */
- collapsed : false,
- /**
- * @cfg {Boolean} collapseFirst
- * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
- * in the panel's title bar, false to render it last (defaults to true).
- */
- collapseFirst: true,
- /**
- * @cfg {Number} minButtonWidth
- * Minimum width in pixels of all buttons in this panel (defaults to 75)
- */
- minButtonWidth:75,
- /**
- * @cfg {String} elements
- * A comma-delimited list of panel elements to initialize when the panel is rendered. Normally, this list will be
- * generated automatically based on the items added to the panel at config time, but sometimes it might be useful to
- * make sure a structural element is rendered even if not specified at config time (for example, you may want
- * to add a button or toolbar dynamically after the panel has been rendered). Adding those elements to this
- * list will allocate the required placeholders in the panel when it is rendered. Valid values areIf this Panel is configured {@link #draggable}, this property will contain - * an instance of {@link Ext.dd.DragSource} which handles dragging the Panel.
- * The developer must provide implementations of the abstract methods of {@link Ext.dd.DragSource} - * in order to supply behaviour for each stage of the drag/drop process. See {@link #draggable}. - * @type Ext.dd.DragSource. - * @property dd - */ - this.dd = new Ext.Panel.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable); - }, - - // private - beforeEffect : function(){ - if(this.floating){ - this.el.beforeAction(); - } - this.el.addClass('x-panel-animated'); - }, - - // private - afterEffect : function(){ - this.syncShadow(); - this.el.removeClass('x-panel-animated'); - }, - - // private - wraps up an animation param with internal callbacks - createEffect : function(a, cb, scope){ - var o = { - scope:scope, - block:true - }; - if(a === true){ - o.callback = cb; - return o; - }else if(!a.callback){ - o.callback = cb; - }else { // wrap it up - o.callback = function(){ - cb.call(scope); - Ext.callback(a.callback, a.scope); - }; - } - return Ext.applyIf(o, a); - }, - - /** - * Collapses the panel body so that it becomes hidden. Fires the {@link #beforecollapse} event which will - * cancel the collapse action if it returns false. - * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the - * {@link #animCollapse} panel config) - * @return {Ext.Panel} this - */ - collapse : function(animate){ - if(this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforecollapse', this, animate) === false){ - return; - } - var doAnim = animate === true || (animate !== false && this.animCollapse); - this.beforeEffect(); - this.onCollapse(doAnim, animate); - return this; - }, - - // private - onCollapse : function(doAnim, animArg){ - if(doAnim){ - this[this.collapseEl].slideOut(this.slideAnchor, - Ext.apply(this.createEffect(animArg||true, this.afterCollapse, this), - this.collapseDefaults)); - }else{ - this[this.collapseEl].hide(); - this.afterCollapse(); - } - }, - - // private - afterCollapse : function(){ - this.collapsed = true; - this.el.addClass(this.collapsedCls); - this.afterEffect(); - this.fireEvent('collapse', this); - }, - - /** - * Expands the panel body so that it becomes visible. Fires the {@link #beforeexpand} event which will - * cancel the expand action if it returns false. - * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the - * {@link #animCollapse} panel config) - * @return {Ext.Panel} this - */ - expand : function(animate){ - if(!this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforeexpand', this, animate) === false){ - return; - } - var doAnim = animate === true || (animate !== false && this.animCollapse); - this.el.removeClass(this.collapsedCls); - this.beforeEffect(); - this.onExpand(doAnim, animate); - return this; - }, - - // private - onExpand : function(doAnim, animArg){ - if(doAnim){ - this[this.collapseEl].slideIn(this.slideAnchor, - Ext.apply(this.createEffect(animArg||true, this.afterExpand, this), - this.expandDefaults)); - }else{ - this[this.collapseEl].show(); - this.afterExpand(); - } - }, - - // private - afterExpand : function(){ - this.collapsed = false; - this.afterEffect(); - this.fireEvent('expand', this); - }, - - /** - * Shortcut for performing an {@link #expand} or {@link #collapse} based on the current state of the panel. - * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the - * {@link #animCollapse} panel config) - * @return {Ext.Panel} this - */ - toggleCollapse : function(animate){ - this[this.collapsed ? 'expand' : 'collapse'](animate); - return this; - }, - - // private - onDisable : function(){ - if(this.rendered && this.maskDisabled){ - this.el.mask(); - } - Ext.Panel.superclass.onDisable.call(this); - }, - - // private - onEnable : function(){ - if(this.rendered && this.maskDisabled){ - this.el.unmask(); - } - Ext.Panel.superclass.onEnable.call(this); - }, - - // private - onResize : function(w, h){ - if(w !== undefined || h !== undefined){ - if(!this.collapsed){ - if(typeof w == 'number'){ - this.body.setWidth( - this.adjustBodyWidth(w - this.getFrameWidth())); - }else if(w == 'auto'){ - this.body.setWidth(w); - } - - if(typeof h == 'number'){ - this.body.setHeight( - this.adjustBodyHeight(h - this.getFrameHeight())); - }else if(h == 'auto'){ - this.body.setHeight(h); - } - - if(this.disabled && this.el._mask){ - this.el._mask.setSize(this.el.dom.clientWidth, this.el.getHeight()); - } - }else{ - this.queuedBodySize = {width: w, height: h}; - if(!this.queuedExpand && this.allowQueuedExpand !== false){ - this.queuedExpand = true; - this.on('expand', function(){ - delete this.queuedExpand; - this.onResize(this.queuedBodySize.width, this.queuedBodySize.height); - this.doLayout(); - }, this, {single:true}); - } - } - this.fireEvent('bodyresize', this, w, h); - } - this.syncShadow(); - }, - - // private - adjustBodyHeight : function(h){ - return h; - }, - - // private - adjustBodyWidth : function(w){ - return w; - }, - - // private - onPosition : function(){ - this.syncShadow(); - }, - - /** - * Returns the width in pixels of the framing elements of this panel (not including the body width). To - * retrieve the body width see {@link #getInnerWidth}. - * @return {Number} The frame width - */ - getFrameWidth : function(){ - var w = this.el.getFrameWidth('lr'); - - if(this.frame){ - var l = this.bwrap.dom.firstChild; - w += (Ext.fly(l).getFrameWidth('l') + Ext.fly(l.firstChild).getFrameWidth('r')); - var mc = this.bwrap.dom.firstChild.firstChild.firstChild; - w += Ext.fly(mc).getFrameWidth('lr'); - } - return w; - }, - - /** - * Returns the height in pixels of the framing elements of this panel (including any top and bottom bars and - * header and footer elements, but not including the body height). To retrieve the body height see {@link #getInnerHeight}. - * @return {Number} The frame height - */ - getFrameHeight : function(){ - var h = this.el.getFrameWidth('tb'); - h += (this.tbar ? this.tbar.getHeight() : 0) + - (this.bbar ? this.bbar.getHeight() : 0); - - if(this.frame){ - var hd = this.el.dom.firstChild; - var ft = this.bwrap.dom.lastChild; - h += (hd.offsetHeight + ft.offsetHeight); - var mc = this.bwrap.dom.firstChild.firstChild.firstChild; - h += Ext.fly(mc).getFrameWidth('tb'); - }else{ - h += (this.header ? this.header.getHeight() : 0) + - (this.footer ? this.footer.getHeight() : 0); - } - return h; - }, - - /** - * Returns the width in pixels of the body element (not including the width of any framing elements). - * For the frame width see {@link #getFrameWidth}. - * @return {Number} The body width - */ - getInnerWidth : function(){ - return this.getSize().width - this.getFrameWidth(); - }, - - /** - * Returns the height in pixels of the body element (not including the height of any framing elements). - * For the frame height see {@link #getFrameHeight}. - * @return {Number} The body height - */ - getInnerHeight : function(){ - return this.getSize().height - this.getFrameHeight(); - }, - - // private - syncShadow : function(){ - if(this.floating){ - this.el.sync(true); - } - }, - - // private - getLayoutTarget : function(){ - return this.body; - }, - - /** - *Sets the title text for the panel and optionally the icon class.
- *In order to be able to set the title, a header element must have been created - * for the Panel. This is triggered either by configuring the Panel with a non-blank title, - * or configuring it with {@link #header}: true.
- * @param {String} title The title text to set - * @param {String} iconCls (optional) iconCls A user-defined CSS class that provides the icon image for this panel - */ - setTitle : function(title, iconCls){ - this.title = title; - if(this.header && this.headerAsText){ - this.header.child('span').update(title); - } - if(iconCls){ - this.setIconClass(iconCls); - } - this.fireEvent('titlechange', this, title); - return this; - }, - - /** - * Get the {@link Ext.Updater} for this panel. Enables you to perform Ajax updates of this panel's body. - * @return {Ext.Updater} The Updater - */ - getUpdater : function(){ - return this.body.getUpdater(); - }, - - /** - * Loads this content panel immediately with content returned from an XHR call. - * @param {Object/String/Function} config A config object containing any of the following options: -
-panel.load({
- url: "your-url.php",
- params: {param1: "foo", param2: "bar"}, // or a URL encoded string
- callback: yourFunction,
- scope: yourObject, // optional scope for the callback
- discardUrl: false,
- nocache: false,
- text: "Loading...",
- timeout: 30,
- scripts: false
-});
-
- * The only required property is url. The optional properties nocache, text and scripts
- * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their
- * associated property on this panel Updater instance.
- * @return {Ext.Panel} this
- */
- load : function(){
- var um = this.body.getUpdater();
- um.update.apply(um, arguments);
- return this;
- },
-
- // private
- beforeDestroy : function(){
- if(this.header){
- this.header.removeAllListeners();
- if(this.headerAsText){
- Ext.Element.uncache(this.header.child('span'));
- }
- }
- Ext.Element.uncache(
- this.header,
- this.tbar,
- this.bbar,
- this.footer,
- this.body,
- this.bwrap
- );
- if(this.tools){
- for(var k in this.tools){
- Ext.destroy(this.tools[k]);
- }
- }
- if(this.buttons){
- for(var b in this.buttons){
- Ext.destroy(this.buttons[b]);
- }
- }
- Ext.destroy(
- this.topToolbar,
- this.bottomToolbar
- );
- Ext.Panel.superclass.beforeDestroy.call(this);
- },
-
- // private
- createClasses : function(){
- this.headerCls = this.baseCls + '-header';
- this.headerTextCls = this.baseCls + '-header-text';
- this.bwrapCls = this.baseCls + '-bwrap';
- this.tbarCls = this.baseCls + '-tbar';
- this.bodyCls = this.baseCls + '-body';
- this.bbarCls = this.baseCls + '-bbar';
- this.footerCls = this.baseCls + '-footer';
- },
-
- // private
- createGhost : function(cls, useShim, appendTo){
- var el = document.createElement('div');
- el.className = 'x-panel-ghost ' + (cls ? cls : '');
- if(this.header){
- el.appendChild(this.el.dom.firstChild.cloneNode(true));
- }
- Ext.fly(el.appendChild(document.createElement('ul'))).setHeight(this.bwrap.getHeight());
- el.style.width = this.el.dom.offsetWidth + 'px';;
- if(!appendTo){
- this.container.dom.appendChild(el);
- }else{
- Ext.getDom(appendTo).appendChild(el);
- }
- if(useShim !== false && this.el.useShim !== false){
- var layer = new Ext.Layer({shadow:false, useDisplay:true, constrain:false}, el);
- layer.show();
- return layer;
- }else{
- return new Ext.Element(el);
- }
- },
-
- // private
- doAutoLoad : function(){
- this.body.load(
- typeof this.autoLoad == 'object' ?
- this.autoLoad : {url: this.autoLoad});
- },
-
- /**
- * Retrieve a tool by id.
- * @param {String} id
- * @return {Object} tool
- */
- getTool: function(id) {
- return this.tools[id];
- }
-
-/**
- * @cfg {String} autoEl @hide
- */
-});
-Ext.reg('panel', Ext.Panel);