3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.layout.ToolbarLayout
\r
9 * @extends Ext.layout.ContainerLayout
\r
10 * Layout manager implicitly used by Ext.Toolbar.
\r
12 Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
\r
13 monitorResize : true,
\r
15 lastOverflow : false,
\r
17 noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
\r
19 onLayout : function(ct, target){
\r
21 target.addClass('x-toolbar-layout-ct');
\r
22 target.insertHtml('beforeEnd',
\r
23 '<table cellspacing="0" class="x-toolbar-ct"><tbody><tr><td class="x-toolbar-left" align="left"><table cellspacing="0"><tbody><tr class="x-toolbar-left-row"></tr></tbody></table></td><td class="x-toolbar-right" align="right"><table cellspacing="0" class="x-toolbar-right-ct"><tbody><tr><td><table cellspacing="0"><tbody><tr class="x-toolbar-right-row"></tr></tbody></table></td><td><table cellspacing="0"><tbody><tr class="x-toolbar-extras-row"></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>');
\r
24 this.leftTr = target.child('tr.x-toolbar-left-row', true);
\r
25 this.rightTr = target.child('tr.x-toolbar-right-row', true);
\r
26 this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
\r
28 var side = this.leftTr;
\r
31 var items = ct.items.items;
\r
32 for(var i = 0, len = items.length, c; i < len; i++, pos++) {
\r
35 side = this.rightTr;
\r
37 }else if(!c.rendered){
\r
38 c.render(this.insertCell(c, side, pos));
\r
40 if(!c.xtbHidden && !this.isValidParent(c, side.childNodes[pos])){
\r
41 var td = this.insertCell(c, side, pos);
\r
42 td.appendChild(c.getDomPositionEl().dom);
\r
43 c.container = Ext.get(td);
\r
47 //strip extra empty cells
\r
48 this.cleanup(this.leftTr);
\r
49 this.cleanup(this.rightTr);
\r
50 this.cleanup(this.extrasTr);
\r
51 this.fitToSize(target);
\r
54 cleanup : function(row){
\r
55 var cn = row.childNodes;
\r
56 for(var i = cn.length-1, c; i >= 0 && (c = cn[i]); i--){
\r
63 insertCell : function(c, side, pos){
\r
64 var td = document.createElement('td');
\r
65 td.className='x-toolbar-cell';
\r
66 side.insertBefore(td, side.childNodes[pos]||null);
\r
70 hideItem : function(item){
\r
71 var h = (this.hiddens = this.hiddens || []);
\r
73 item.xtbHidden = true;
\r
74 item.xtbWidth = item.getDomPositionEl().dom.parentNode.offsetWidth;
\r
78 unhideItem : function(item){
\r
80 item.xtbHidden = false;
\r
81 this.hiddens.remove(item);
\r
82 if(this.hiddens.length < 1){
\r
83 delete this.hiddens;
\r
87 getItemWidth : function(c){
\r
88 return c.hidden ? (c.xtbWidth || 0) : c.getDomPositionEl().dom.parentNode.offsetWidth;
\r
91 fitToSize : function(t){
\r
92 if(this.container.enableOverflow === false){
\r
95 var w = t.dom.clientWidth;
\r
96 var lw = this.lastWidth || 0;
\r
98 var iw = t.dom.firstChild.offsetWidth;
\r
100 var clipWidth = w - this.triggerWidth;
\r
101 var hideIndex = -1;
\r
103 if(iw > w || (this.hiddens && w >= lw)){
\r
104 var i, items = this.container.items.items, len = items.length, c;
\r
106 for(i = 0; i < len; i++) {
\r
109 loopWidth += this.getItemWidth(c);
\r
110 if(loopWidth > clipWidth){
\r
116 this.unhideItem(c);
\r
124 if(!this.lastOverflow){
\r
125 this.container.fireEvent('overflowchange', this.container, true);
\r
126 this.lastOverflow = true;
\r
128 }else if(this.more){
\r
130 this.more.destroy();
\r
132 if(this.lastOverflow){
\r
133 this.container.fireEvent('overflowchange', this.container, false);
\r
134 this.lastOverflow = false;
\r
139 createMenuConfig : function(c, hideOnClick){
\r
140 var cfg = Ext.apply({}, c.initialConfig),
\r
141 group = c.toggleGroup;
\r
144 text: c.overflowText || c.text,
\r
145 iconCls: c.iconCls,
\r
148 disabled: c.disabled,
\r
149 handler: c.handler,
\r
152 hideOnClick: hideOnClick
\r
154 if(group || c.enableToggle){
\r
157 checked: c.pressed,
\r
159 checkchange: function(item, checked){
\r
171 addComponentToMenu : function(m, c){
\r
172 if(c instanceof Ext.Toolbar.Separator){
\r
174 }else if(Ext.isFunction(c.isXType)){
\r
175 if(c.isXType('splitbutton')){
\r
176 m.add(this.createMenuConfig(c, true));
\r
177 }else if(c.isXType('button')){
\r
178 m.add(this.createMenuConfig(c, !c.menu));
\r
179 }else if(c.isXType('buttongroup')){
\r
180 c.items.each(function(item){
\r
181 this.addComponentToMenu(m, item);
\r
187 clearMenu : function(){
\r
188 var m = this.moreMenu;
\r
190 this.moreMenu.items.each(function(item){
\r
197 beforeMoreShow : function(m){
\r
198 var h = this.container.items.items,
\r
202 needsSep = function(group, item){
\r
203 return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
\r
208 for(var i = 0; i < len; i++){
\r
211 if(prev && (needsSep(c, prev) || needsSep(prev, c))){
\r
214 this.addComponentToMenu(m, c);
\r
218 // put something so the menu isn't empty
\r
219 // if no compatible items found
\r
220 if(m.items.length < 1){
\r
221 m.add(this.noItemsMenuText);
\r
225 initMore : function(){
\r
227 this.moreMenu = new Ext.menu.Menu({
\r
229 beforeshow: this.beforeMoreShow,
\r
233 this.more = new Ext.Button({
\r
234 iconCls: 'x-toolbar-more-icon',
\r
235 cls: 'x-toolbar-more',
\r
236 menu: this.moreMenu
\r
238 var td = this.insertCell(this.more, this.extrasTr, 100);
\r
239 this.more.render(td);
\r
243 destroy : function(){
\r
244 Ext.destroy(this.more, this.moreMenu);
\r
245 Ext.layout.ToolbarLayout.superclass.destroy.call(this);
\r
248 * @property activeItem
\r
253 Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
\r
256 * @class Ext.Toolbar
\r
257 * @extends Ext.Container
\r
258 * <p>Basic Toolbar class. Although the <tt>{@link Ext.Container#defaultType defaultType}</tt> for Toolbar
\r
259 * is <tt>{@link Ext.Button button}</tt>, Toolbar elements (child items for the Toolbar container) may
\r
260 * be virtually any type of Component. Toolbar elements can be created explicitly via their constructors,
\r
261 * or implicitly via their xtypes, and can be <tt>{@link #add}</tt>ed dynamically.</p>
\r
262 * <p>Some items have shortcut strings for creation:</p>
\r
264 <u>Shortcut</u> <u>xtype</u> <u>Class</u> <u>Description</u>
\r
265 '->' 'tbfill' {@link Ext.Toolbar.Fill} begin using the right-justified button container
\r
266 '-' 'tbseparator' {@link Ext.Toolbar.Separator} add a vertical separator bar between toolbar items
\r
267 ' ' 'tbspacer' {@link Ext.Toolbar.Spacer} add horiztonal space between elements
\r
270 * Example usage of various elements:
\r
272 var tb = new Ext.Toolbar({
\r
273 renderTo: document.body,
\r
278 // xtype: 'button', // default for Toolbars, same as 'tbbutton'
\r
282 xtype: 'splitbutton', // same as 'tbsplitbutton'
\r
283 text: 'Split Button'
\r
285 // begin using the right-justified button container
\r
286 '->', // same as {xtype: 'tbfill'}, // Ext.Toolbar.Fill
\r
288 xtype: 'textfield',
\r
290 emptyText: 'enter search term'
\r
292 // add a vertical separator bar between toolbar items
\r
293 '-', // same as {xtype: 'tbseparator'} to create Ext.Toolbar.Separator
\r
294 'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.Toolbar.TextItem
\r
295 {xtype: 'tbspacer'},// same as ' ' to create Ext.Toolbar.Spacer
\r
297 {xtype: 'tbspacer', width: 50}, // add a 50px space
\r
302 * Example adding a ComboBox within a menu of a button:
\r
304 // ComboBox creation
\r
305 var combo = new Ext.form.ComboBox({
\r
306 store: new Ext.data.ArrayStore({
\r
308 fields: ['initials', 'fullname'],
\r
310 ['FF', 'Fred Flintstone'],
\r
311 ['BR', 'Barney Rubble']
\r
314 displayField: 'fullname',
\r
317 forceSelection: true,
\r
318 triggerAction: 'all',
\r
319 emptyText: 'Select a name...',
\r
320 selectOnFocus: true,
\r
322 getListParent: function() {
\r
323 return this.el.up('.x-menu');
\r
325 iconCls: 'no-icon' //use iconCls if placing within menu to shift to right side of menu
\r
328 // put ComboBox in a Menu
\r
329 var menu = new Ext.menu.Menu({
\r
332 combo // A Field in a Menu
\r
336 // add a Button with the menu
\r
338 text:'Button w/ Menu',
\r
339 menu: menu // assign menu by instance
\r
344 * Creates a new Toolbar
\r
345 * @param {Object/Array} config A config object or an array of buttons to <tt>{@link #add}</tt>
\r
348 Ext.Toolbar = function(config){
\r
349 if(Ext.isArray(config)){
\r
350 config = {items: config, layout: 'toolbar'};
\r
352 config = Ext.apply({
\r
355 if(config.buttons) {
\r
356 config.items = config.buttons;
\r
359 Ext.Toolbar.superclass.constructor.call(this, config);
\r
364 var T = Ext.Toolbar;
\r
366 Ext.extend(T, Ext.Container, {
\r
368 defaultType: 'button',
\r
371 internalDefaults: {removeMode: 'container', hideParent: true},
\r
372 toolbarCls: 'x-toolbar',
\r
374 initComponent : function(){
\r
375 T.superclass.initComponent.call(this);
\r
378 * @event overflowchange
\r
379 * Fires after the overflow state has changed.
\r
380 * @param {Object} c The Container
\r
381 * @param {Boolean} lastOverflow overflow state
\r
383 this.addEvents('overflowchange');
\r
387 onRender : function(ct, position){
\r
389 if(!this.autoCreate){
\r
390 this.autoCreate = {
\r
391 cls: this.toolbarCls + ' x-small-editor'
\r
394 this.el = ct.createChild(Ext.apply({ id: this.id },this.autoCreate), position);
\r
399 * Adds element(s) to the toolbar -- this function takes a variable number of
\r
400 * arguments of mixed type and adds them to the toolbar.
\r
401 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
\r
403 * <li>{@link Ext.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
\r
404 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
\r
405 * <li>Field: Any form field (equivalent to {@link #addField})</li>
\r
406 * <li>Item: Any subclass of {@link Ext.Toolbar.Item} (equivalent to {@link #addItem})</li>
\r
407 * <li>String: Any generic string (gets wrapped in a {@link Ext.Toolbar.TextItem}, equivalent to {@link #addText}).
\r
408 * Note that there are a few special strings that are treated differently as explained next.</li>
\r
409 * <li>'-': Creates a separator element (equivalent to {@link #addSeparator})</li>
\r
410 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
\r
411 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
\r
413 * @param {Mixed} arg2
\r
414 * @param {Mixed} etc.
\r
419 lookupComponent : function(c){
\r
420 if(Ext.isString(c)){
\r
422 c = new T.Separator();
\r
423 }else if(c == ' '){
\r
424 c = new T.Spacer();
\r
425 }else if(c == '->'){
\r
428 c = new T.TextItem(c);
\r
430 this.applyDefaults(c);
\r
432 if(c.isFormField || c.render){ // some kind of form field, some kind of Toolbar.Item
\r
433 c = this.constructItem(c);
\r
434 }else if(c.tag){ // DomHelper spec
\r
435 c = new T.Item({autoEl: c});
\r
436 }else if(c.tagName){ // element
\r
437 c = new T.Item({el:c});
\r
438 }else if(Ext.isObject(c)){ // must be button config?
\r
439 c = c.xtype ? this.constructItem(c) : this.constructButton(c);
\r
446 applyDefaults : function(c){
\r
447 if(!Ext.isString(c)){
\r
448 c = Ext.Toolbar.superclass.applyDefaults.call(this, c);
\r
449 var d = this.internalDefaults;
\r
451 Ext.applyIf(c.initialConfig, d);
\r
461 constructItem : function(item, type){
\r
462 return Ext.create(item, type || this.defaultType);
\r
467 * @return {Ext.Toolbar.Item} The separator {@link Ext.Toolbar.Item item}
\r
469 addSeparator : function(){
\r
470 return this.add(new T.Separator());
\r
474 * Adds a spacer element
\r
475 * @return {Ext.Toolbar.Spacer} The spacer item
\r
477 addSpacer : function(){
\r
478 return this.add(new T.Spacer());
\r
482 * Forces subsequent additions into the float:right toolbar
\r
484 addFill : function(){
\r
485 this.add(new T.Fill());
\r
489 * Adds any standard HTML element to the toolbar
\r
490 * @param {Mixed} el The element or id of the element to add
\r
491 * @return {Ext.Toolbar.Item} The element's item
\r
493 addElement : function(el){
\r
494 return this.addItem(new T.Item({el:el}));
\r
498 * Adds any Toolbar.Item or subclass
\r
499 * @param {Ext.Toolbar.Item} item
\r
500 * @return {Ext.Toolbar.Item} The item
\r
502 addItem : function(item){
\r
503 return Ext.Toolbar.superclass.add.apply(this, arguments);
\r
507 * Adds a button (or buttons). See {@link Ext.Button} for more info on the config.
\r
508 * @param {Object/Array} config A button config or array of configs
\r
509 * @return {Ext.Button/Array}
\r
511 addButton : function(config){
\r
512 if(Ext.isArray(config)){
\r
514 for(var i = 0, len = config.length; i < len; i++) {
\r
515 buttons.push(this.addButton(config[i]));
\r
519 return this.add(this.constructButton(config));
\r
523 * Adds text to the toolbar
\r
524 * @param {String} text The text to add
\r
525 * @return {Ext.Toolbar.Item} The element's item
\r
527 addText : function(text){
\r
528 return this.addItem(new T.TextItem(text));
\r
532 * Adds a new element to the toolbar from the passed {@link Ext.DomHelper} config
\r
533 * @param {Object} config
\r
534 * @return {Ext.Toolbar.Item} The element's item
\r
536 addDom : function(config){
\r
537 return this.add(new T.Item({autoEl: config}));
\r
541 * Adds a dynamically rendered Ext.form field (TextField, ComboBox, etc). Note: the field should not have
\r
542 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
\r
543 * @param {Ext.form.Field} field
\r
544 * @return {Ext.Toolbar.Item}
\r
546 addField : function(field){
\r
547 return this.add(field);
\r
551 * Inserts any {@link Ext.Toolbar.Item}/{@link Ext.Button} at the specified index.
\r
552 * @param {Number} index The index where the item is to be inserted
\r
553 * @param {Object/Ext.Toolbar.Item/Ext.Button/Array} item The button, or button config object to be
\r
554 * inserted, or an array of buttons/configs.
\r
555 * @return {Ext.Button/Item}
\r
557 insertButton : function(index, item){
\r
558 if(Ext.isArray(item)){
\r
560 for(var i = 0, len = item.length; i < len; i++) {
\r
561 buttons.push(this.insertButton(index + i, item[i]));
\r
565 return Ext.Toolbar.superclass.insert.call(this, index, item);
\r
569 initMenuTracking : function(item){
\r
570 if(this.trackMenus && item.menu){
\r
572 'menutriggerover' : this.onButtonTriggerOver,
\r
573 'menushow' : this.onButtonMenuShow,
\r
574 'menuhide' : this.onButtonMenuHide,
\r
581 constructButton : function(item){
\r
582 var b = item.events ? item : this.constructItem(item, item.split ? 'splitbutton' : this.defaultType);
\r
583 this.initMenuTracking(b);
\r
588 onDisable : function(){
\r
589 this.items.each(function(item){
\r
597 onEnable : function(){
\r
598 this.items.each(function(item){
\r
606 onButtonTriggerOver : function(btn){
\r
607 if(this.activeMenuBtn && this.activeMenuBtn != btn){
\r
608 this.activeMenuBtn.hideMenu();
\r
610 this.activeMenuBtn = btn;
\r
615 onButtonMenuShow : function(btn){
\r
616 this.activeMenuBtn = btn;
\r
620 onButtonMenuHide : function(btn){
\r
621 delete this.activeMenuBtn;
\r
624 Ext.reg('toolbar', Ext.Toolbar);
\r
627 * @class Ext.Toolbar.Item
\r
628 * @extends Ext.BoxComponent
\r
629 * The base class that other non-interacting Toolbar Item classes should extend in order to
\r
630 * get some basic common toolbar item functionality.
\r
632 * Creates a new Item
\r
633 * @param {HTMLElement} el
\r
636 T.Item = Ext.extend(Ext.BoxComponent, {
\r
637 hideParent: true, // Hiding a Toolbar.Item hides its containing TD
\r
638 enable:Ext.emptyFn,
\r
639 disable:Ext.emptyFn,
\r
642 * @cfg {String} overflowText Text to be used for the menu if the item is overflowed.
\r
645 Ext.reg('tbitem', T.Item);
\r
648 * @class Ext.Toolbar.Separator
\r
649 * @extends Ext.Toolbar.Item
\r
650 * A simple class that adds a vertical separator bar between toolbar items
\r
651 * (css class:<tt>'xtb-sep'</tt>). Example usage:
\r
656 {xtype: 'tbseparator'}, // or '-'
\r
662 * Creates a new Separator
\r
663 * @xtype tbseparator
\r
665 T.Separator = Ext.extend(T.Item, {
\r
666 onRender : function(ct, position){
\r
667 this.el = ct.createChild({tag:'span', cls:'xtb-sep'}, position);
\r
670 Ext.reg('tbseparator', T.Separator);
\r
673 * @class Ext.Toolbar.Spacer
\r
674 * @extends Ext.Toolbar.Item
\r
675 * A simple element that adds extra horizontal space between items in a toolbar.
\r
676 * By default a 2px wide space is added via css specification:<pre><code>
\r
677 .x-toolbar .xtb-spacer {
\r
681 * <p>Example usage:</p>
\r
686 {xtype: 'tbspacer'}, // or ' '
\r
688 // space width is also configurable via javascript
\r
689 {xtype: 'tbspacer', width: 50}, // add a 50px space
\r
695 * Creates a new Spacer
\r
698 T.Spacer = Ext.extend(T.Item, {
\r
700 * @cfg {Number} width
\r
701 * The width of the spacer in pixels (defaults to 2px via css style <tt>.x-toolbar .xtb-spacer</tt>).
\r
704 onRender : function(ct, position){
\r
705 this.el = ct.createChild({tag:'div', cls:'xtb-spacer', style: this.width?'width:'+this.width+'px':''}, position);
\r
708 Ext.reg('tbspacer', T.Spacer);
\r
711 * @class Ext.Toolbar.Fill
\r
712 * @extends Ext.Toolbar.Spacer
\r
713 * A non-rendering placeholder item which instructs the Toolbar's Layout to begin using
\r
714 * the right-justified button container.
\r
719 {xtype: 'tbfill'}, // or '->'
\r
725 * Creates a new Fill
\r
728 T.Fill = Ext.extend(T.Item, {
\r
730 render : Ext.emptyFn,
\r
733 Ext.reg('tbfill', T.Fill);
\r
736 * @class Ext.Toolbar.TextItem
\r
737 * @extends Ext.Toolbar.Item
\r
738 * A simple class that renders text directly into a toolbar
\r
739 * (with css class:<tt>'xtb-text'</tt>). Example usage:
\r
743 {xtype: 'tbtext', text: 'Item 1'} // or simply 'Item 1'
\r
748 * Creates a new TextItem
\r
749 * @param {String/Object} text A text string, or a config object containing a <tt>text</tt> property
\r
752 T.TextItem = Ext.extend(T.Item, {
\r
753 constructor: function(config){
\r
754 if (Ext.isString(config)) {
\r
755 config = { autoEl: {cls: 'xtb-text', html: config }};
\r
757 config.autoEl = {cls: 'xtb-text', html: config.text || ''};
\r
759 T.TextItem.superclass.constructor.call(this, config);
\r
762 * Updates this item's text, setting the text to be used as innerHTML.
\r
763 * @param {String} t The text to display (html accepted).
\r
765 setText : function(t) {
\r
766 if (this.rendered) {
\r
767 this.el.dom.innerHTML = t;
\r
769 this.autoEl.html = t;
\r
773 Ext.reg('tbtext', T.TextItem);
\r
775 // backwards compat
\r
776 T.Button = Ext.extend(Ext.Button, {});
\r
777 T.SplitButton = Ext.extend(Ext.SplitButton, {});
\r
778 Ext.reg('tbbutton', T.Button);
\r
779 Ext.reg('tbsplit', T.SplitButton);
\r
783 * @class Ext.ButtonGroup
\r
784 * @extends Ext.Panel
\r
785 * Container for a group of buttons. Example usage:
\r
787 var p = new Ext.Panel({
\r
788 title: 'Panel with Button Group',
\r
791 renderTo: document.body,
\r
794 xtype: 'buttongroup',
\r
795 {@link #columns}: 3,
\r
796 title: 'Clipboard',
\r
800 rowspan: 3, iconCls: 'add',
\r
802 cls: 'x-btn-as-arrow'
\r
804 xtype:'splitbutton',
\r
805 text: 'Menu Button',
\r
810 arrowAlign:'bottom',
\r
811 menu: [{text: 'Menu Item 1'}]
\r
813 xtype:'splitbutton', text: 'Cut', iconCls: 'add16', menu: [{text: 'Cut Menu Item'}]
\r
815 text: 'Copy', iconCls: 'add16'
\r
817 text: 'Format', iconCls: 'add16'
\r
822 * @xtype buttongroup
\r
824 Ext.ButtonGroup = Ext.extend(Ext.Panel, {
\r
826 * @cfg {Number} columns The <tt>columns</tt> configuration property passed to the
\r
827 * {@link #layout configured layout manager}. See {@link Ext.layout.TableLayout#columns}.
\r
830 * @cfg {String} baseCls Defaults to <tt>'x-btn-group'</tt>. See {@link Ext.Panel#baseCls}.
\r
832 baseCls: 'x-btn-group',
\r
834 * @cfg {String} layout Defaults to <tt>'table'</tt>. See {@link Ext.Container#layout}.
\r
837 defaultType: 'button',
\r
839 * @cfg {Boolean} frame Defaults to <tt>true</tt>. See {@link Ext.Panel#frame}.
\r
842 internalDefaults: {removeMode: 'container', hideParent: true},
\r
844 initComponent : function(){
\r
845 this.layoutConfig = this.layoutConfig || {};
\r
846 Ext.applyIf(this.layoutConfig, {
\r
847 columns : this.columns
\r
850 this.addClass('x-btn-group-notitle');
\r
852 this.on('afterlayout', this.onAfterLayout, this);
\r
853 Ext.ButtonGroup.superclass.initComponent.call(this);
\r
856 applyDefaults : function(c){
\r
857 c = Ext.ButtonGroup.superclass.applyDefaults.call(this, c);
\r
858 var d = this.internalDefaults;
\r
860 Ext.applyIf(c.initialConfig, d);
\r
868 onAfterLayout : function(){
\r
869 var bodyWidth = this.body.getFrameWidth('lr') + this.body.dom.firstChild.offsetWidth;
\r
870 this.body.setWidth(bodyWidth);
\r
871 this.el.setWidth(bodyWidth + this.getFrameWidth());
\r
874 * @cfg {Array} tools @hide
\r
878 Ext.reg('buttongroup', Ext.ButtonGroup);
\r
880 * @class Ext.PagingToolbar
881 * @extends Ext.Toolbar
882 * <p>As the amount of records increases, the time required for the browser to render
883 * them increases. Paging is used to reduce the amount of data exchanged with the client.
884 * Note: if there are more records/rows than can be viewed in the available screen area, vertical
885 * scrollbars will be added.</p>
886 * <p>Paging is typically handled on the server side (see exception below). The client sends
887 * parameters to the server side, which the server needs to interpret and then respond with the
888 * approprate data.</p>
889 * <p><b>Ext.PagingToolbar</b> is a specialized toolbar that is bound to a {@link Ext.data.Store}
890 * and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
891 * of data into the <tt>{@link #store}</tt> by passing {@link Ext.data.Store#paramNames paramNames} used for
892 * paging criteria.</p>
893 * <p>PagingToolbar is typically used as one of the Grid's toolbars:</p>
895 Ext.QuickTips.init(); // to display button quicktips
897 var myStore = new Ext.data.Store({
901 var myPageSize = 25; // server script should only send back 25 items
903 var grid = new Ext.grid.GridPanel({
906 bbar: new Ext.PagingToolbar({
907 {@link #store}: myStore, // grid and PagingToolbar using same store
908 {@link #displayInfo}: true,
909 {@link #pageSize}: myPageSize,
910 {@link #prependButtons}: true,
918 * <p>To use paging, pass the paging requirements to the server when the store is first loaded.</p>
922 start: 0, // specify params for the first page load if using paging
928 * <p><u>Paging with Local Data</u></p>
929 * <p>Paging can also be accomplished with local data using extensions:</p>
930 * <div class="mdetail-params"><ul>
931 * <li><a href="http://extjs.com/forum/showthread.php?t=57386">Ext.ux.data.PagingStore</a></li>
932 * <li>Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)</li>
935 * Create a new PagingToolbar
936 * @param {Object} config The config object
943 Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
945 * @cfg {Ext.data.Store} store
946 * The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
949 * @cfg {Boolean} displayInfo
950 * <tt>true</tt> to display the displayMsg (defaults to <tt>false</tt>)
953 * @cfg {Number} pageSize
954 * The number of records to display per page (defaults to <tt>20</tt>)
958 * @cfg {Boolean} prependButtons
959 * <tt>true</tt> to insert any configured <tt>items</tt> <i>before</i> the paging buttons.
960 * Defaults to <tt>false</tt>.
963 * @cfg {String} displayMsg
964 * The paging status message to display (defaults to <tt>'Displaying {0} - {1} of {2}'</tt>).
965 * Note that this string is formatted using the braced numbers <tt>{0}-{2}</tt> as tokens
966 * that are replaced by the values for start, end and total respectively. These tokens should
967 * be preserved when overriding this string if showing those values is desired.
969 displayMsg : 'Displaying {0} - {1} of {2}',
971 * @cfg {String} emptyMsg
972 * The message to display when no records are found (defaults to 'No data to display')
974 emptyMsg : 'No data to display',
976 * @cfg {String} beforePageText
977 * The text displayed before the input item (defaults to <tt>'Page'</tt>).
979 beforePageText : 'Page',
981 * @cfg {String} afterPageText
982 * Customizable piece of the default paging text (defaults to <tt>'of {0}'</tt>). Note that
983 * this string is formatted using <tt>{0}</tt> as a token that is replaced by the number of
984 * total pages. This token should be preserved when overriding this string if showing the
985 * total page count is desired.
987 afterPageText : 'of {0}',
989 * @cfg {String} firstText
990 * The quicktip text displayed for the first page button (defaults to <tt>'First Page'</tt>).
991 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
993 firstText : 'First Page',
995 * @cfg {String} prevText
996 * The quicktip text displayed for the previous page button (defaults to <tt>'Previous Page'</tt>).
997 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
999 prevText : 'Previous Page',
1001 * @cfg {String} nextText
1002 * The quicktip text displayed for the next page button (defaults to <tt>'Next Page'</tt>).
1003 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1005 nextText : 'Next Page',
1007 * @cfg {String} lastText
1008 * The quicktip text displayed for the last page button (defaults to <tt>'Last Page'</tt>).
1009 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1011 lastText : 'Last Page',
1013 * @cfg {String} refreshText
1014 * The quicktip text displayed for the Refresh button (defaults to <tt>'Refresh'</tt>).
1015 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1017 refreshText : 'Refresh',
1021 * <b>The defaults for these should be set in the data store.</b>
1022 * Object mapping of parameter names used for load calls, initially set to:
1023 * <pre>{start: 'start', limit: 'limit'}</pre>
1027 * The number of records to display per page. See also <tt>{@link #cursor}</tt>.
1029 * @property pageSize
1033 * Indicator for the record position. This property might be used to get the active page
1034 * number for example:<pre><code>
1035 * // t is reference to the paging toolbar instance
1036 * var activePage = Math.ceil((t.cursor + t.pageSize) / t.pageSize);
1042 initComponent : function(){
1043 var pagingItems = [this.first = new T.Button({
1044 tooltip: this.firstText,
1045 overflowText: this.firstText,
1046 iconCls: 'x-tbar-page-first',
1048 handler: this.moveFirst,
1050 }), this.prev = new T.Button({
1051 tooltip: this.prevText,
1052 overflowText: this.prevText,
1053 iconCls: 'x-tbar-page-prev',
1055 handler: this.movePrevious,
1057 }), '-', this.beforePageText,
1058 this.inputItem = new Ext.form.NumberField({
1059 cls: 'x-tbar-page-number',
1060 allowDecimals: false,
1061 allowNegative: false,
1062 enableKeyEvents: true,
1063 selectOnFocus: true,
1066 keydown: this.onPagingKeyDown,
1067 blur: this.onPagingBlur
1069 }), this.afterTextItem = new T.TextItem({
1070 text: String.format(this.afterPageText, 1)
1071 }), '-', this.next = new T.Button({
1072 tooltip: this.nextText,
1073 overflowText: this.nextText,
1074 iconCls: 'x-tbar-page-next',
1076 handler: this.moveNext,
1078 }), this.last = new T.Button({
1079 tooltip: this.lastText,
1080 overflowText: this.lastText,
1081 iconCls: 'x-tbar-page-last',
1083 handler: this.moveLast,
1085 }), '-', this.refresh = new T.Button({
1086 tooltip: this.refreshText,
1087 overflowText: this.refreshText,
1088 iconCls: 'x-tbar-loading',
1089 handler: this.refresh,
1094 var userItems = this.items || this.buttons || [];
1095 if (this.prependButtons) {
1096 this.items = userItems.concat(pagingItems);
1098 this.items = pagingItems.concat(userItems);
1100 delete this.buttons;
1101 if(this.displayInfo){
1102 this.items.push('->');
1103 this.items.push(this.displayItem = new T.TextItem({}));
1105 Ext.PagingToolbar.superclass.initComponent.call(this);
1109 * Fires after the active page has been changed.
1110 * @param {Ext.PagingToolbar} this
1111 * @param {Object} pageData An object that has these properties:<ul>
1112 * <li><code>total</code> : Number <div class="sub-desc">The total number of records in the dataset as
1113 * returned by the server</div></li>
1114 * <li><code>activePage</code> : Number <div class="sub-desc">The current page number</div></li>
1115 * <li><code>pages</code> : Number <div class="sub-desc">The total number of pages (calculated from
1116 * the total number of records in the dataset as returned by the server and the current {@link #pageSize})</div></li>
1121 * @event beforechange
1122 * Fires just before the active page is changed.
1123 * Return false to prevent the active page from being changed.
1124 * @param {Ext.PagingToolbar} this
1125 * @param {Object} params An object hash of the parameters which the PagingToolbar will send when
1126 * loading the required page. This will contain:<ul>
1127 * <li><code>start</code> : Number <div class="sub-desc">The starting row number for the next page of records to
1128 * be retrieved from the server</div></li>
1129 * <li><code>limit</code> : Number <div class="sub-desc">The number of records to be retrieved from the server</div></li>
1131 * <p>(note: the names of the <b>start</b> and <b>limit</b> properties are determined
1132 * by the store's {@link Ext.data.Store#paramNames paramNames} property.)</p>
1133 * <p>Parameters may be added as required in the event handler.</p>
1137 this.on('afterlayout', this.onFirstLayout, this, {single: true});
1139 this.bindStore(this.store);
1143 onFirstLayout : function(){
1145 this.onLoad.apply(this, this.dsLoaded);
1150 updateInfo : function(){
1151 if(this.displayItem){
1152 var count = this.store.getCount();
1153 var msg = count == 0 ?
1157 this.cursor+1, this.cursor+count, this.store.getTotalCount()
1159 this.displayItem.setText(msg);
1164 onLoad : function(store, r, o){
1166 this.dsLoaded = [store, r, o];
1169 var p = this.getParams();
1170 this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
1171 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
1173 this.afterTextItem.setText(String.format(this.afterPageText, d.pages));
1174 this.inputItem.setValue(ap);
1175 this.first.setDisabled(ap == 1);
1176 this.prev.setDisabled(ap == 1);
1177 this.next.setDisabled(ap == ps);
1178 this.last.setDisabled(ap == ps);
1179 this.refresh.enable();
1181 this.fireEvent('change', this, d);
1185 getPageData : function(){
1186 var total = this.store.getTotalCount();
1189 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
1190 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
1195 * Change the active page
1196 * @param {Integer} page The page to display
1198 changePage : function(page){
1199 this.doLoad(((page-1) * this.pageSize).constrain(0, this.store.getTotalCount()));
1203 onLoadError : function(){
1207 this.refresh.enable();
1211 readPage : function(d){
1212 var v = this.inputItem.getValue(), pageNum;
1213 if (!v || isNaN(pageNum = parseInt(v, 10))) {
1214 this.inputItem.setValue(d.activePage);
1220 onPagingFocus : function(){
1221 this.inputItem.select();
1225 onPagingBlur : function(e){
1226 this.inputItem.setValue(this.getPageData().activePage);
1230 onPagingKeyDown : function(field, e){
1231 var k = e.getKey(), d = this.getPageData(), pageNum;
1232 if (k == e.RETURN) {
1234 pageNum = this.readPage(d);
1235 if(pageNum !== false){
1236 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
1237 this.doLoad(pageNum * this.pageSize);
1239 }else if (k == e.HOME || k == e.END){
1241 pageNum = k == e.HOME ? 1 : d.pages;
1242 field.setValue(pageNum);
1243 }else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
1245 if((pageNum = this.readPage(d))){
1246 var increment = e.shiftKey ? 10 : 1;
1247 if(k == e.DOWN || k == e.PAGEDOWN){
1250 pageNum += increment;
1251 if(pageNum >= 1 & pageNum <= d.pages){
1252 field.setValue(pageNum);
1259 getParams : function(){
1260 //retain backwards compat, allow params on the toolbar itself, if they exist.
1261 return this.paramNames || this.store.paramNames;
1265 beforeLoad : function(){
1266 if(this.rendered && this.refresh){
1267 this.refresh.disable();
1272 doLoad : function(start){
1273 var o = {}, pn = this.getParams();
1274 o[pn.start] = start;
1275 o[pn.limit] = this.pageSize;
1276 if(this.fireEvent('beforechange', this, o) !== false){
1277 this.store.load({params:o});
1282 * Move to the first page, has the same effect as clicking the 'first' button.
1284 moveFirst : function(){
1289 * Move to the previous page, has the same effect as clicking the 'previous' button.
1291 movePrevious : function(){
1292 this.doLoad(Math.max(0, this.cursor-this.pageSize));
1296 * Move to the next page, has the same effect as clicking the 'next' button.
1298 moveNext : function(){
1299 this.doLoad(this.cursor+this.pageSize);
1303 * Move to the last page, has the same effect as clicking the 'last' button.
1305 moveLast : function(){
1306 var total = this.store.getTotalCount(),
1307 extra = total % this.pageSize;
1309 this.doLoad(extra ? (total - extra) : total - this.pageSize);
1313 * Refresh the current page, has the same effect as clicking the 'refresh' button.
1315 refresh : function(){
1316 this.doLoad(this.cursor);
1320 * Binds the paging toolbar to the specified {@link Ext.data.Store}
1321 * @param {Store} store The store to bind to this toolbar
1322 * @param {Boolean} initial (Optional) true to not remove listeners
1324 bindStore : function(store, initial){
1326 if(!initial && this.store){
1327 this.store.un('beforeload', this.beforeLoad, this);
1328 this.store.un('load', this.onLoad, this);
1329 this.store.un('exception', this.onLoadError, this);
1330 if(store !== this.store && this.store.autoDestroy){
1331 this.store.destroy();
1335 store = Ext.StoreMgr.lookup(store);
1338 beforeload: this.beforeLoad,
1340 exception: this.onLoadError
1342 doLoad = store.getCount() > 0;
1346 this.onLoad(store, null, {});
1351 * Unbinds the paging toolbar from the specified {@link Ext.data.Store} <b>(deprecated)</b>
1352 * @param {Ext.data.Store} store The data store to unbind
1354 unbind : function(store){
1355 this.bindStore(null);
1359 * Binds the paging toolbar to the specified {@link Ext.data.Store} <b>(deprecated)</b>
1360 * @param {Ext.data.Store} store The data store to bind
1362 bind : function(store){
1363 this.bindStore(store);
1367 onDestroy : function(){
1368 this.bindStore(null);
1369 Ext.PagingToolbar.superclass.onDestroy.call(this);
1374 Ext.reg('paging', Ext.PagingToolbar);