Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / pkgs / pkg-toolbars-debug.js
1 /*!
2  * Ext JS Library 3.0.3
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.layout.ToolbarLayout\r
9  * @extends Ext.layout.ContainerLayout\r
10  * Layout manager implicitly used by Ext.Toolbar.\r
11  */\r
12 Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {\r
13     monitorResize : true,\r
14     triggerWidth : 18,\r
15     lastOverflow : false,\r
16 \r
17     noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',\r
18     // private\r
19     onLayout : function(ct, target){\r
20         if(!this.leftTr){\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
27         }\r
28         var side = this.leftTr;\r
29         var pos = 0;\r
30 \r
31         var items = ct.items.items;\r
32         for(var i = 0, len = items.length, c; i < len; i++, pos++) {\r
33             c = items[i];\r
34             if(c.isFill){\r
35                 side = this.rightTr;\r
36                 pos = -1;\r
37             }else if(!c.rendered){\r
38                 c.render(this.insertCell(c, side, pos));\r
39             }else{\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
44                 }\r
45             }\r
46         }\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
52     },\r
53 \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
57             if(!c.firstChild){\r
58                 row.removeChild(c);\r
59             }\r
60         }\r
61     },\r
62 \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
67         return td;\r
68     },\r
69 \r
70     hideItem : function(item){\r
71         var h = (this.hiddens = this.hiddens || []);\r
72         h.push(item);\r
73         item.xtbHidden = true;\r
74         item.xtbWidth = item.getDomPositionEl().dom.parentNode.offsetWidth;\r
75         item.hide();\r
76     },\r
77 \r
78     unhideItem : function(item){\r
79         item.show();\r
80         item.xtbHidden = false;\r
81         this.hiddens.remove(item);\r
82         if(this.hiddens.length < 1){\r
83             delete this.hiddens;\r
84         }\r
85     },\r
86 \r
87     getItemWidth : function(c){\r
88         return c.hidden ? (c.xtbWidth || 0) : c.getDomPositionEl().dom.parentNode.offsetWidth;\r
89     },\r
90 \r
91     fitToSize : function(t){\r
92         if(this.container.enableOverflow === false){\r
93             return;\r
94         }\r
95         var w = t.dom.clientWidth;\r
96         var lw = this.lastWidth || 0;\r
97         this.lastWidth = w;\r
98         var iw = t.dom.firstChild.offsetWidth;\r
99 \r
100         var clipWidth = w - this.triggerWidth;\r
101         var hideIndex = -1;\r
102 \r
103         if(iw > w || (this.hiddens && w >= lw)){\r
104             var i, items = this.container.items.items, len = items.length, c;\r
105             var loopWidth = 0;\r
106             for(i = 0; i < len; i++) {\r
107                 c = items[i];\r
108                 if(!c.isFill){\r
109                     loopWidth += this.getItemWidth(c);\r
110                     if(loopWidth > clipWidth){\r
111                         if(!c.xtbHidden){\r
112                             this.hideItem(c);\r
113                         }\r
114                     }else{\r
115                         if(c.xtbHidden){\r
116                             this.unhideItem(c);\r
117                         }\r
118                     }\r
119                 }\r
120             }\r
121         }\r
122         if(this.hiddens){\r
123             this.initMore();\r
124             if(!this.lastOverflow){\r
125                 this.container.fireEvent('overflowchange', this.container, true);\r
126                 this.lastOverflow = true;\r
127             }\r
128         }else if(this.more){\r
129             this.clearMenu();\r
130             this.more.destroy();\r
131             delete this.more;\r
132             if(this.lastOverflow){\r
133                 this.container.fireEvent('overflowchange', this.container, false);\r
134                 this.lastOverflow = false;\r
135             }\r
136         }\r
137     },\r
138 \r
139     createMenuConfig : function(c, hideOnClick){\r
140         var cfg = Ext.apply({}, c.initialConfig),\r
141             group = c.toggleGroup;\r
142 \r
143         Ext.apply(cfg, {\r
144             text: c.overflowText || c.text,\r
145             iconCls: c.iconCls,\r
146             icon: c.icon,\r
147             itemId: c.itemId,\r
148             disabled: c.disabled,\r
149             handler: c.handler,\r
150             scope: c.scope,\r
151             menu: c.menu,\r
152             hideOnClick: hideOnClick\r
153         });\r
154         if(group || c.enableToggle){\r
155             Ext.apply(cfg, {\r
156                 group: group,\r
157                 checked: c.pressed,\r
158                 listeners: {\r
159                     checkchange: function(item, checked){\r
160                         c.toggle(checked);\r
161                     }\r
162                 }\r
163             });\r
164         }\r
165         delete cfg.xtype;\r
166         delete cfg.id;\r
167         return cfg;\r
168     },\r
169 \r
170     // private\r
171     addComponentToMenu : function(m, c){\r
172         if(c instanceof Ext.Toolbar.Separator){\r
173             m.add('-');\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
182                 }, this);\r
183             }\r
184         }\r
185     },\r
186 \r
187     clearMenu : function(){\r
188         var m = this.moreMenu;\r
189         if(m && m.items){\r
190             m.items.each(function(item){\r
191                 delete item.menu;\r
192             });\r
193         }\r
194     },\r
195 \r
196     // private\r
197     beforeMoreShow : function(m){\r
198         var h = this.container.items.items,\r
199             len = h.length,\r
200             c,\r
201             prev,\r
202             needsSep = function(group, item){\r
203                 return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);\r
204             };\r
205 \r
206         this.clearMenu();\r
207         m.removeAll();\r
208         for(var i = 0; i < len; i++){\r
209             c = h[i];\r
210             if(c.xtbHidden){\r
211                 if(prev && (needsSep(c, prev) || needsSep(prev, c))){\r
212                     m.add('-');\r
213                 }\r
214                 this.addComponentToMenu(m, c);\r
215                 prev = c;\r
216             }\r
217         }\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
222         }\r
223     },\r
224 \r
225     initMore : function(){\r
226         if(!this.more){\r
227             this.moreMenu = new Ext.menu.Menu({\r
228                 listeners: {\r
229                     beforeshow: this.beforeMoreShow,\r
230                     scope: this\r
231                 }\r
232             });\r
233             this.moreMenu.ownerCt = this.container;\r
234             this.more = new Ext.Button({\r
235                 iconCls: 'x-toolbar-more-icon',\r
236                 cls: 'x-toolbar-more',\r
237                 menu: this.moreMenu\r
238             });\r
239             var td = this.insertCell(this.more, this.extrasTr, 100);\r
240             this.more.render(td);\r
241         }\r
242     },\r
243 \r
244     destroy : function(){\r
245         Ext.destroy(this.more, this.moreMenu);\r
246         Ext.layout.ToolbarLayout.superclass.destroy.call(this);\r
247     }\r
248     /**\r
249      * @property activeItem\r
250      * @hide\r
251      */\r
252 });\r
253 \r
254 Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;\r
255 \r
256 /**\r
257  * @class Ext.Toolbar\r
258  * @extends Ext.Container\r
259  * <p>Basic Toolbar class. Although the <tt>{@link Ext.Container#defaultType defaultType}</tt> for Toolbar\r
260  * is <tt>{@link Ext.Button button}</tt>, Toolbar elements (child items for the Toolbar container) may\r
261  * be virtually any type of Component. Toolbar elements can be created explicitly via their constructors,\r
262  * or implicitly via their xtypes, and can be <tt>{@link #add}</tt>ed dynamically.</p>\r
263  * <p>Some items have shortcut strings for creation:</p>\r
264  * <pre>\r
265 <u>Shortcut</u>  <u>xtype</u>          <u>Class</u>                  <u>Description</u>\r
266 '->'      'tbfill'       {@link Ext.Toolbar.Fill}       begin using the right-justified button container\r
267 '-'       'tbseparator'  {@link Ext.Toolbar.Separator}  add a vertical separator bar between toolbar items\r
268 ' '       'tbspacer'     {@link Ext.Toolbar.Spacer}     add horiztonal space between elements\r
269  * </pre>\r
270  *\r
271  * Example usage of various elements:\r
272  * <pre><code>\r
273 var tb = new Ext.Toolbar({\r
274     renderTo: document.body,\r
275     width: 600,\r
276     height: 100,\r
277     items: [\r
278         {\r
279             // xtype: 'button', // default for Toolbars, same as 'tbbutton'\r
280             text: 'Button'\r
281         },\r
282         {\r
283             xtype: 'splitbutton', // same as 'tbsplitbutton'\r
284             text: 'Split Button'\r
285         },\r
286         // begin using the right-justified button container\r
287         '->', // same as {xtype: 'tbfill'}, // Ext.Toolbar.Fill\r
288         {\r
289             xtype: 'textfield',\r
290             name: 'field1',\r
291             emptyText: 'enter search term'\r
292         },\r
293         // add a vertical separator bar between toolbar items\r
294         '-', // same as {xtype: 'tbseparator'} to create Ext.Toolbar.Separator\r
295         'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.Toolbar.TextItem\r
296         {xtype: 'tbspacer'},// same as ' ' to create Ext.Toolbar.Spacer\r
297         'text 2',\r
298         {xtype: 'tbspacer', width: 50}, // add a 50px space\r
299         'text 3'\r
300     ]\r
301 });\r
302  * </code></pre>\r
303  * Example adding a ComboBox within a menu of a button:\r
304  * <pre><code>\r
305 // ComboBox creation\r
306 var combo = new Ext.form.ComboBox({\r
307     store: new Ext.data.ArrayStore({\r
308         autoDestroy: true,\r
309         fields: ['initials', 'fullname'],\r
310         data : [\r
311             ['FF', 'Fred Flintstone'],\r
312             ['BR', 'Barney Rubble']\r
313         ]\r
314     }),\r
315     displayField: 'fullname',\r
316     typeAhead: true,\r
317     mode: 'local',\r
318     forceSelection: true,\r
319     triggerAction: 'all',\r
320     emptyText: 'Select a name...',\r
321     selectOnFocus: true,\r
322     width: 135,\r
323     getListParent: function() {\r
324         return this.el.up('.x-menu');\r
325     },\r
326     iconCls: 'no-icon' //use iconCls if placing within menu to shift to right side of menu\r
327 });\r
328 \r
329 // put ComboBox in a Menu\r
330 var menu = new Ext.menu.Menu({\r
331     id: 'mainMenu',\r
332     items: [\r
333         combo // A Field in a Menu\r
334     ]\r
335 });\r
336 \r
337 // add a Button with the menu\r
338 tb.add({\r
339         text:'Button w/ Menu',\r
340         menu: menu  // assign menu by instance\r
341     });\r
342 tb.doLayout();\r
343  * </code></pre>\r
344  * @constructor\r
345  * Creates a new Toolbar\r
346  * @param {Object/Array} config A config object or an array of buttons to <tt>{@link #add}</tt>\r
347  * @xtype toolbar\r
348  */\r
349 Ext.Toolbar = function(config){\r
350     if(Ext.isArray(config)){\r
351         config = {items: config, layout: 'toolbar'};\r
352     } else {\r
353         config = Ext.apply({\r
354             layout: 'toolbar'\r
355         }, config);\r
356         if(config.buttons) {\r
357             config.items = config.buttons;\r
358         }\r
359     }\r
360     Ext.Toolbar.superclass.constructor.call(this, config);\r
361 };\r
362 \r
363 (function(){\r
364 \r
365 var T = Ext.Toolbar;\r
366 \r
367 Ext.extend(T, Ext.Container, {\r
368 \r
369     defaultType: 'button',\r
370 \r
371     /**\r
372      * @cfg {String/Object} layout\r
373      * This class assigns a default layout (<code>layout:'<b>toolbar</b>'</code>).\r
374      * Developers <i>may</i> override this configuration option if another layout\r
375      * is required (the constructor must be passed a configuration object in this\r
376      * case instead of an array).\r
377      * See {@link Ext.Container#layout} for additional information.\r
378      */\r
379 \r
380     trackMenus : true,\r
381     internalDefaults: {removeMode: 'container', hideParent: true},\r
382     toolbarCls: 'x-toolbar',\r
383 \r
384     initComponent : function(){\r
385         T.superclass.initComponent.call(this);\r
386 \r
387         /**\r
388          * @event overflowchange\r
389          * Fires after the overflow state has changed.\r
390          * @param {Object} c The Container\r
391          * @param {Boolean} lastOverflow overflow state\r
392          */\r
393         this.addEvents('overflowchange');\r
394     },\r
395 \r
396     // private\r
397     onRender : function(ct, position){\r
398         if(!this.el){\r
399             if(!this.autoCreate){\r
400                 this.autoCreate = {\r
401                     cls: this.toolbarCls + ' x-small-editor'\r
402                 };\r
403             }\r
404             this.el = ct.createChild(Ext.apply({ id: this.id },this.autoCreate), position);\r
405             Ext.Toolbar.superclass.onRender.apply(this, arguments);\r
406         }\r
407     },\r
408 \r
409     /**\r
410      * <p>Adds element(s) to the toolbar -- this function takes a variable number of\r
411      * arguments of mixed type and adds them to the toolbar.</p>\r
412      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
413      * @param {Mixed} arg1 The following types of arguments are all valid:<br />\r
414      * <ul>\r
415      * <li>{@link Ext.Button} config: A valid button config object (equivalent to {@link #addButton})</li>\r
416      * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>\r
417      * <li>Field: Any form field (equivalent to {@link #addField})</li>\r
418      * <li>Item: Any subclass of {@link Ext.Toolbar.Item} (equivalent to {@link #addItem})</li>\r
419      * <li>String: Any generic string (gets wrapped in a {@link Ext.Toolbar.TextItem}, equivalent to {@link #addText}).\r
420      * Note that there are a few special strings that are treated differently as explained next.</li>\r
421      * <li>'-': Creates a separator element (equivalent to {@link #addSeparator})</li>\r
422      * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>\r
423      * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>\r
424      * </ul>\r
425      * @param {Mixed} arg2\r
426      * @param {Mixed} etc.\r
427      * @method add\r
428      */\r
429 \r
430     // private\r
431     lookupComponent : function(c){\r
432         if(Ext.isString(c)){\r
433             if(c == '-'){\r
434                 c = new T.Separator();\r
435             }else if(c == ' '){\r
436                 c = new T.Spacer();\r
437             }else if(c == '->'){\r
438                 c = new T.Fill();\r
439             }else{\r
440                 c = new T.TextItem(c);\r
441             }\r
442             this.applyDefaults(c);\r
443         }else{\r
444             if(c.isFormField || c.render){ // some kind of form field, some kind of Toolbar.Item\r
445                 c = this.constructItem(c);\r
446             }else if(c.tag){ // DomHelper spec\r
447                 c = new T.Item({autoEl: c});\r
448             }else if(c.tagName){ // element\r
449                 c = new T.Item({el:c});\r
450             }else if(Ext.isObject(c)){ // must be button config?\r
451                 c = c.xtype ? this.constructItem(c) : this.constructButton(c);\r
452             }\r
453         }\r
454         return c;\r
455     },\r
456 \r
457     // private\r
458     applyDefaults : function(c){\r
459         if(!Ext.isString(c)){\r
460             c = Ext.Toolbar.superclass.applyDefaults.call(this, c);\r
461             var d = this.internalDefaults;\r
462             if(c.events){\r
463                 Ext.applyIf(c.initialConfig, d);\r
464                 Ext.apply(c, d);\r
465             }else{\r
466                 Ext.applyIf(c, d);\r
467             }\r
468         }\r
469         return c;\r
470     },\r
471 \r
472     // private\r
473     constructItem : function(item, type){\r
474         return Ext.create(item, type || this.defaultType);\r
475     },\r
476 \r
477     /**\r
478      * Adds a separator\r
479      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
480      * @return {Ext.Toolbar.Item} The separator {@link Ext.Toolbar.Item item}\r
481      */\r
482     addSeparator : function(){\r
483         return this.add(new T.Separator());\r
484     },\r
485 \r
486     /**\r
487      * Adds a spacer element\r
488      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
489      * @return {Ext.Toolbar.Spacer} The spacer item\r
490      */\r
491     addSpacer : function(){\r
492         return this.add(new T.Spacer());\r
493     },\r
494 \r
495     /**\r
496      * Forces subsequent additions into the float:right toolbar\r
497      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
498      */\r
499     addFill : function(){\r
500         this.add(new T.Fill());\r
501     },\r
502 \r
503     /**\r
504      * Adds any standard HTML element to the toolbar\r
505      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
506      * @param {Mixed} el The element or id of the element to add\r
507      * @return {Ext.Toolbar.Item} The element's item\r
508      */\r
509     addElement : function(el){\r
510         return this.addItem(new T.Item({el:el}));\r
511     },\r
512 \r
513     /**\r
514      * Adds any Toolbar.Item or subclass\r
515      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
516      * @param {Ext.Toolbar.Item} item\r
517      * @return {Ext.Toolbar.Item} The item\r
518      */\r
519     addItem : function(item){\r
520         return this.add.apply(this, arguments);\r
521     },\r
522 \r
523     /**\r
524      * Adds a button (or buttons). See {@link Ext.Button} for more info on the config.\r
525      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
526      * @param {Object/Array} config A button config or array of configs\r
527      * @return {Ext.Button/Array}\r
528      */\r
529     addButton : function(config){\r
530         if(Ext.isArray(config)){\r
531             var buttons = [];\r
532             for(var i = 0, len = config.length; i < len; i++) {\r
533                 buttons.push(this.addButton(config[i]));\r
534             }\r
535             return buttons;\r
536         }\r
537         return this.add(this.constructButton(config));\r
538     },\r
539 \r
540     /**\r
541      * Adds text to the toolbar\r
542      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
543      * @param {String} text The text to add\r
544      * @return {Ext.Toolbar.Item} The element's item\r
545      */\r
546     addText : function(text){\r
547         return this.addItem(new T.TextItem(text));\r
548     },\r
549 \r
550     /**\r
551      * Adds a new element to the toolbar from the passed {@link Ext.DomHelper} config\r
552      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
553      * @param {Object} config\r
554      * @return {Ext.Toolbar.Item} The element's item\r
555      */\r
556     addDom : function(config){\r
557         return this.add(new T.Item({autoEl: config}));\r
558     },\r
559 \r
560     /**\r
561      * Adds a dynamically rendered Ext.form field (TextField, ComboBox, etc). Note: the field should not have\r
562      * been rendered yet. For a field that has already been rendered, use {@link #addElement}.\r
563      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
564      * @param {Ext.form.Field} field\r
565      * @return {Ext.Toolbar.Item}\r
566      */\r
567     addField : function(field){\r
568         return this.add(field);\r
569     },\r
570 \r
571     /**\r
572      * Inserts any {@link Ext.Toolbar.Item}/{@link Ext.Button} at the specified index.\r
573      * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>\r
574      * @param {Number} index The index where the item is to be inserted\r
575      * @param {Object/Ext.Toolbar.Item/Ext.Button/Array} item The button, or button config object to be\r
576      * inserted, or an array of buttons/configs.\r
577      * @return {Ext.Button/Item}\r
578      */\r
579     insertButton : function(index, item){\r
580         if(Ext.isArray(item)){\r
581             var buttons = [];\r
582             for(var i = 0, len = item.length; i < len; i++) {\r
583                buttons.push(this.insertButton(index + i, item[i]));\r
584             }\r
585             return buttons;\r
586         }\r
587         return Ext.Toolbar.superclass.insert.call(this, index, item);\r
588     },\r
589 \r
590     // private\r
591     initMenuTracking : function(item){\r
592         if(this.trackMenus && item.menu){\r
593             this.mon(item, {\r
594                 'menutriggerover' : this.onButtonTriggerOver,\r
595                 'menushow' : this.onButtonMenuShow,\r
596                 'menuhide' : this.onButtonMenuHide,\r
597                 scope: this\r
598             });\r
599         }\r
600     },\r
601 \r
602     // private\r
603     constructButton : function(item){\r
604         var b = item.events ? item : this.constructItem(item, item.split ? 'splitbutton' : this.defaultType);\r
605         this.initMenuTracking(b);\r
606         return b;\r
607     },\r
608 \r
609     // private\r
610     onDisable : function(){\r
611         this.items.each(function(item){\r
612              if(item.disable){\r
613                  item.disable();\r
614              }\r
615         });\r
616     },\r
617 \r
618     // private\r
619     onEnable : function(){\r
620         this.items.each(function(item){\r
621              if(item.enable){\r
622                  item.enable();\r
623              }\r
624         });\r
625     },\r
626 \r
627     // private\r
628     onButtonTriggerOver : function(btn){\r
629         if(this.activeMenuBtn && this.activeMenuBtn != btn){\r
630             this.activeMenuBtn.hideMenu();\r
631             btn.showMenu();\r
632             this.activeMenuBtn = btn;\r
633         }\r
634     },\r
635 \r
636     // private\r
637     onButtonMenuShow : function(btn){\r
638         this.activeMenuBtn = btn;\r
639     },\r
640 \r
641     // private\r
642     onButtonMenuHide : function(btn){\r
643         delete this.activeMenuBtn;\r
644     }\r
645 });\r
646 Ext.reg('toolbar', Ext.Toolbar);\r
647 \r
648 /**\r
649  * @class Ext.Toolbar.Item\r
650  * @extends Ext.BoxComponent\r
651  * The base class that other non-interacting Toolbar Item classes should extend in order to\r
652  * get some basic common toolbar item functionality.\r
653  * @constructor\r
654  * Creates a new Item\r
655  * @param {HTMLElement} el\r
656  * @xtype tbitem\r
657  */\r
658 T.Item = Ext.extend(Ext.BoxComponent, {\r
659     hideParent: true, //  Hiding a Toolbar.Item hides its containing TD\r
660     enable:Ext.emptyFn,\r
661     disable:Ext.emptyFn,\r
662     focus:Ext.emptyFn\r
663     /**\r
664      * @cfg {String} overflowText Text to be used for the menu if the item is overflowed.\r
665      */\r
666 });\r
667 Ext.reg('tbitem', T.Item);\r
668 \r
669 /**\r
670  * @class Ext.Toolbar.Separator\r
671  * @extends Ext.Toolbar.Item\r
672  * A simple class that adds a vertical separator bar between toolbar items\r
673  * (css class:<tt>'xtb-sep'</tt>). Example usage:\r
674  * <pre><code>\r
675 new Ext.Panel({\r
676     tbar : [\r
677         'Item 1',\r
678         {xtype: 'tbseparator'}, // or '-'\r
679         'Item 2'\r
680     ]\r
681 });\r
682 </code></pre>\r
683  * @constructor\r
684  * Creates a new Separator\r
685  * @xtype tbseparator\r
686  */\r
687 T.Separator = Ext.extend(T.Item, {\r
688     onRender : function(ct, position){\r
689         this.el = ct.createChild({tag:'span', cls:'xtb-sep'}, position);\r
690     }\r
691 });\r
692 Ext.reg('tbseparator', T.Separator);\r
693 \r
694 /**\r
695  * @class Ext.Toolbar.Spacer\r
696  * @extends Ext.Toolbar.Item\r
697  * A simple element that adds extra horizontal space between items in a toolbar.\r
698  * By default a 2px wide space is added via css specification:<pre><code>\r
699 .x-toolbar .xtb-spacer {\r
700     width:2px;\r
701 }\r
702  * </code></pre>\r
703  * <p>Example usage:</p>\r
704  * <pre><code>\r
705 new Ext.Panel({\r
706     tbar : [\r
707         'Item 1',\r
708         {xtype: 'tbspacer'}, // or ' '\r
709         'Item 2',\r
710         // space width is also configurable via javascript\r
711         {xtype: 'tbspacer', width: 50}, // add a 50px space\r
712         'Item 3'\r
713     ]\r
714 });\r
715 </code></pre>\r
716  * @constructor\r
717  * Creates a new Spacer\r
718  * @xtype tbspacer\r
719  */\r
720 T.Spacer = Ext.extend(T.Item, {\r
721     /**\r
722      * @cfg {Number} width\r
723      * The width of the spacer in pixels (defaults to 2px via css style <tt>.x-toolbar .xtb-spacer</tt>).\r
724      */\r
725 \r
726     onRender : function(ct, position){\r
727         this.el = ct.createChild({tag:'div', cls:'xtb-spacer', style: this.width?'width:'+this.width+'px':''}, position);\r
728     }\r
729 });\r
730 Ext.reg('tbspacer', T.Spacer);\r
731 \r
732 /**\r
733  * @class Ext.Toolbar.Fill\r
734  * @extends Ext.Toolbar.Spacer\r
735  * A non-rendering placeholder item which instructs the Toolbar's Layout to begin using\r
736  * the right-justified button container.\r
737  * <pre><code>\r
738 new Ext.Panel({\r
739     tbar : [\r
740         'Item 1',\r
741         {xtype: 'tbfill'}, // or '->'\r
742         'Item 2'\r
743     ]\r
744 });\r
745 </code></pre>\r
746  * @constructor\r
747  * Creates a new Fill\r
748  * @xtype tbfill\r
749  */\r
750 T.Fill = Ext.extend(T.Item, {\r
751     // private\r
752     render : Ext.emptyFn,\r
753     isFill : true\r
754 });\r
755 Ext.reg('tbfill', T.Fill);\r
756 \r
757 /**\r
758  * @class Ext.Toolbar.TextItem\r
759  * @extends Ext.Toolbar.Item\r
760  * A simple class that renders text directly into a toolbar\r
761  * (with css class:<tt>'xtb-text'</tt>). Example usage:\r
762  * <pre><code>\r
763 new Ext.Panel({\r
764     tbar : [\r
765         {xtype: 'tbtext', text: 'Item 1'} // or simply 'Item 1'\r
766     ]\r
767 });\r
768 </code></pre>\r
769  * @constructor\r
770  * Creates a new TextItem\r
771  * @param {String/Object} text A text string, or a config object containing a <tt>text</tt> property\r
772  * @xtype tbtext\r
773  */\r
774 T.TextItem = Ext.extend(T.Item, {\r
775     /**\r
776      * @cfg {String} text The text to be used as innerHTML (html tags are accepted)\r
777      */ \r
778 \r
779     constructor: function(config){\r
780         T.TextItem.superclass.constructor.call(this, Ext.isString(config) ? {text: config} : config);\r
781     },\r
782     \r
783     // private\r
784     onRender : function(ct, position) {\r
785         this.autoEl = {cls: 'xtb-text', html: this.text || ''};\r
786         T.TextItem.superclass.onRender.call(this, ct, position);\r
787     },\r
788     \r
789     /**\r
790      * Updates this item's text, setting the text to be used as innerHTML.\r
791      * @param {String} t The text to display (html accepted).\r
792      */\r
793     setText : function(t) {\r
794         if(this.rendered){\r
795             this.el.update(t);\r
796         }else{\r
797             this.text = t;\r
798         }\r
799     }\r
800 });\r
801 Ext.reg('tbtext', T.TextItem);\r
802 \r
803 // backwards compat\r
804 T.Button = Ext.extend(Ext.Button, {});\r
805 T.SplitButton = Ext.extend(Ext.SplitButton, {});\r
806 Ext.reg('tbbutton', T.Button);\r
807 Ext.reg('tbsplit', T.SplitButton);\r
808 \r
809 })();\r
810 /**\r
811  * @class Ext.ButtonGroup\r
812  * @extends Ext.Panel\r
813  * Container for a group of buttons. Example usage:\r
814  * <pre><code>\r
815 var p = new Ext.Panel({\r
816     title: 'Panel with Button Group',\r
817     width: 300,\r
818     height:200,\r
819     renderTo: document.body,\r
820     html: 'whatever',\r
821     tbar: [{\r
822         xtype: 'buttongroup',\r
823         {@link #columns}: 3,\r
824         title: 'Clipboard',\r
825         items: [{\r
826             text: 'Paste',\r
827             scale: 'large',\r
828             rowspan: 3, iconCls: 'add',\r
829             iconAlign: 'top',\r
830             cls: 'x-btn-as-arrow'\r
831         },{\r
832             xtype:'splitbutton',\r
833             text: 'Menu Button',\r
834             scale: 'large',\r
835             rowspan: 3,\r
836             iconCls: 'add',\r
837             iconAlign: 'top',\r
838             arrowAlign:'bottom',\r
839             menu: [{text: 'Menu Item 1'}]\r
840         },{\r
841             xtype:'splitbutton', text: 'Cut', iconCls: 'add16', menu: [{text: 'Cut Menu Item'}]\r
842         },{\r
843             text: 'Copy', iconCls: 'add16'\r
844         },{\r
845             text: 'Format', iconCls: 'add16'\r
846         }]\r
847     }]\r
848 });\r
849  * </code></pre>\r
850  * @xtype buttongroup\r
851  */\r
852 Ext.ButtonGroup = Ext.extend(Ext.Panel, {\r
853     /**\r
854      * @cfg {Number} columns The <tt>columns</tt> configuration property passed to the\r
855      * {@link #layout configured layout manager}. See {@link Ext.layout.TableLayout#columns}.\r
856      */\r
857     /**\r
858      * @cfg {String} baseCls  Defaults to <tt>'x-btn-group'</tt>.  See {@link Ext.Panel#baseCls}.\r
859      */\r
860     baseCls: 'x-btn-group',\r
861     /**\r
862      * @cfg {String} layout  Defaults to <tt>'table'</tt>.  See {@link Ext.Container#layout}.\r
863      */\r
864     layout:'table',\r
865     defaultType: 'button',\r
866     /**\r
867      * @cfg {Boolean} frame  Defaults to <tt>true</tt>.  See {@link Ext.Panel#frame}.\r
868      */\r
869     frame: true,\r
870     internalDefaults: {removeMode: 'container', hideParent: true},\r
871 \r
872     initComponent : function(){\r
873         this.layoutConfig = this.layoutConfig || {};\r
874         Ext.applyIf(this.layoutConfig, {\r
875             columns : this.columns\r
876         });\r
877         if(!this.title){\r
878             this.addClass('x-btn-group-notitle');\r
879         }\r
880         this.on('afterlayout', this.onAfterLayout, this);\r
881         Ext.ButtonGroup.superclass.initComponent.call(this);\r
882     },\r
883 \r
884     applyDefaults : function(c){\r
885         c = Ext.ButtonGroup.superclass.applyDefaults.call(this, c);\r
886         var d = this.internalDefaults;\r
887         if(c.events){\r
888             Ext.applyIf(c.initialConfig, d);\r
889             Ext.apply(c, d);\r
890         }else{\r
891             Ext.applyIf(c, d);\r
892         }\r
893         return c;\r
894     },\r
895 \r
896     onAfterLayout : function(){\r
897         var bodyWidth = this.body.getFrameWidth('lr') + this.body.dom.firstChild.offsetWidth;\r
898         this.body.setWidth(bodyWidth);\r
899         this.el.setWidth(bodyWidth + this.getFrameWidth());\r
900     }\r
901     /**\r
902      * @cfg {Array} tools  @hide\r
903      */\r
904 });\r
905 \r
906 Ext.reg('buttongroup', Ext.ButtonGroup);\r
907 /**
908  * @class Ext.PagingToolbar
909  * @extends Ext.Toolbar
910  * <p>As the amount of records increases, the time required for the browser to render
911  * them increases. Paging is used to reduce the amount of data exchanged with the client.
912  * Note: if there are more records/rows than can be viewed in the available screen area, vertical
913  * scrollbars will be added.</p>
914  * <p>Paging is typically handled on the server side (see exception below). The client sends
915  * parameters to the server side, which the server needs to interpret and then respond with the
916  * approprate data.</p>
917  * <p><b>Ext.PagingToolbar</b> is a specialized toolbar that is bound to a {@link Ext.data.Store}
918  * and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
919  * of data into the <tt>{@link #store}</tt> by passing {@link Ext.data.Store#paramNames paramNames} used for
920  * paging criteria.</p>
921  * <p>PagingToolbar is typically used as one of the Grid's toolbars:</p>
922  * <pre><code>
923 Ext.QuickTips.init(); // to display button quicktips
924
925 var myStore = new Ext.data.Store({
926     reader: new Ext.data.JsonReader({
927         {@link Ext.data.JsonReader#totalProperty totalProperty}: 'results', 
928         ...
929     }),
930     ...
931 });
932
933 var myPageSize = 25;  // server script should only send back 25 items at a time
934
935 var grid = new Ext.grid.GridPanel({
936     ...
937     store: myStore,
938     bbar: new Ext.PagingToolbar({
939         {@link #store}: myStore,       // grid and PagingToolbar using same store
940         {@link #displayInfo}: true,
941         {@link #pageSize}: myPageSize,
942         {@link #prependButtons}: true,
943         items: [
944             'text 1'
945         ]
946     })
947 });
948  * </code></pre>
949  *
950  * <p>To use paging, pass the paging requirements to the server when the store is first loaded.</p>
951  * <pre><code>
952 store.load({
953     params: {
954         // specify params for the first page load if using paging
955         start: 0,          
956         limit: myPageSize,
957         // other params
958         foo:   'bar'
959     }
960 });
961  * </code></pre>
962  * 
963  * <p>If using {@link Ext.data.Store#autoLoad store's autoLoad} configuration:</p>
964  * <pre><code>
965 var myStore = new Ext.data.Store({
966     {@link Ext.data.Store#autoLoad autoLoad}: {params:{start: 0, limit: 25}},
967     ...
968 });
969  * </code></pre>
970  * 
971  * <p>The packet sent back from the server would have this form:</p>
972  * <pre><code>
973 {
974     "success": true,
975     "results": 2000, 
976     "rows": [ // <b>*Note:</b> this must be an Array 
977         { "id":  1, "name": "Bill", "occupation": "Gardener" },
978         { "id":  2, "name":  "Ben", "occupation": "Horticulturalist" },
979         ...
980         { "id": 25, "name":  "Sue", "occupation": "Botanist" }
981     ]
982 }
983  * </code></pre>
984  * <p><u>Paging with Local Data</u></p>
985  * <p>Paging can also be accomplished with local data using extensions:</p>
986  * <div class="mdetail-params"><ul>
987  * <li><a href="http://extjs.com/forum/showthread.php?t=71532">Ext.ux.data.PagingStore</a></li>
988  * <li>Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)</li>
989  * </ul></div>
990  * @constructor Create a new PagingToolbar
991  * @param {Object} config The config object
992  * @xtype paging
993  */
994 (function() {
995
996 var T = Ext.Toolbar;
997
998 Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
999     /**
1000      * @cfg {Ext.data.Store} store
1001      * The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
1002      */
1003     /**
1004      * @cfg {Boolean} displayInfo
1005      * <tt>true</tt> to display the displayMsg (defaults to <tt>false</tt>)
1006      */
1007     /**
1008      * @cfg {Number} pageSize
1009      * The number of records to display per page (defaults to <tt>20</tt>)
1010      */
1011     pageSize : 20,
1012     /**
1013      * @cfg {Boolean} prependButtons
1014      * <tt>true</tt> to insert any configured <tt>items</tt> <i>before</i> the paging buttons.
1015      * Defaults to <tt>false</tt>.
1016      */
1017     /**
1018      * @cfg {String} displayMsg
1019      * The paging status message to display (defaults to <tt>'Displaying {0} - {1} of {2}'</tt>).
1020      * Note that this string is formatted using the braced numbers <tt>{0}-{2}</tt> as tokens
1021      * that are replaced by the values for start, end and total respectively. These tokens should
1022      * be preserved when overriding this string if showing those values is desired.
1023      */
1024     displayMsg : 'Displaying {0} - {1} of {2}',
1025     /**
1026      * @cfg {String} emptyMsg
1027      * The message to display when no records are found (defaults to 'No data to display')
1028      */
1029     emptyMsg : 'No data to display',
1030     /**
1031      * @cfg {String} beforePageText
1032      * The text displayed before the input item (defaults to <tt>'Page'</tt>).
1033      */
1034     beforePageText : 'Page',
1035     /**
1036      * @cfg {String} afterPageText
1037      * Customizable piece of the default paging text (defaults to <tt>'of {0}'</tt>). Note that
1038      * this string is formatted using <tt>{0}</tt> as a token that is replaced by the number of
1039      * total pages. This token should be preserved when overriding this string if showing the
1040      * total page count is desired.
1041      */
1042     afterPageText : 'of {0}',
1043     /**
1044      * @cfg {String} firstText
1045      * The quicktip text displayed for the first page button (defaults to <tt>'First Page'</tt>).
1046      * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1047      */
1048     firstText : 'First Page',
1049     /**
1050      * @cfg {String} prevText
1051      * The quicktip text displayed for the previous page button (defaults to <tt>'Previous Page'</tt>).
1052      * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1053      */
1054     prevText : 'Previous Page',
1055     /**
1056      * @cfg {String} nextText
1057      * The quicktip text displayed for the next page button (defaults to <tt>'Next Page'</tt>).
1058      * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1059      */
1060     nextText : 'Next Page',
1061     /**
1062      * @cfg {String} lastText
1063      * The quicktip text displayed for the last page button (defaults to <tt>'Last Page'</tt>).
1064      * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1065      */
1066     lastText : 'Last Page',
1067     /**
1068      * @cfg {String} refreshText
1069      * The quicktip text displayed for the Refresh button (defaults to <tt>'Refresh'</tt>).
1070      * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1071      */
1072     refreshText : 'Refresh',
1073
1074     /**
1075      * <p><b>Deprecated</b>. <code>paramNames</code> should be set in the <b>data store</b>
1076      * (see {@link Ext.data.Store#paramNames}).</p>
1077      * <br><p>Object mapping of parameter names used for load calls, initially set to:</p>
1078      * <pre>{start: 'start', limit: 'limit'}</pre>
1079      * @type Object
1080      * @property paramNames
1081      * @deprecated
1082      */
1083
1084     /**
1085      * The number of records to display per page.  See also <tt>{@link #cursor}</tt>.
1086      * @type Number
1087      * @property pageSize
1088      */
1089
1090     /**
1091      * Indicator for the record position.  This property might be used to get the active page
1092      * number for example:<pre><code>
1093      * // t is reference to the paging toolbar instance
1094      * var activePage = Math.ceil((t.cursor + t.pageSize) / t.pageSize);
1095      * </code></pre>
1096      * @type Number
1097      * @property cursor
1098      */
1099
1100     initComponent : function(){
1101         var pagingItems = [this.first = new T.Button({
1102             tooltip: this.firstText,
1103             overflowText: this.firstText,
1104             iconCls: 'x-tbar-page-first',
1105             disabled: true,
1106             handler: this.moveFirst,
1107             scope: this
1108         }), this.prev = new T.Button({
1109             tooltip: this.prevText,
1110             overflowText: this.prevText,
1111             iconCls: 'x-tbar-page-prev',
1112             disabled: true,
1113             handler: this.movePrevious,
1114             scope: this
1115         }), '-', this.beforePageText,
1116         this.inputItem = new Ext.form.NumberField({
1117             cls: 'x-tbar-page-number',
1118             allowDecimals: false,
1119             allowNegative: false,
1120             enableKeyEvents: true,
1121             selectOnFocus: true,
1122             listeners: {
1123                 scope: this,
1124                 keydown: this.onPagingKeyDown,
1125                 blur: this.onPagingBlur
1126             }
1127         }), this.afterTextItem = new T.TextItem({
1128             text: String.format(this.afterPageText, 1)
1129         }), '-', this.next = new T.Button({
1130             tooltip: this.nextText,
1131             overflowText: this.nextText,
1132             iconCls: 'x-tbar-page-next',
1133             disabled: true,
1134             handler: this.moveNext,
1135             scope: this
1136         }), this.last = new T.Button({
1137             tooltip: this.lastText,
1138             overflowText: this.lastText,
1139             iconCls: 'x-tbar-page-last',
1140             disabled: true,
1141             handler: this.moveLast,
1142             scope: this
1143         }), '-', this.refresh = new T.Button({
1144             tooltip: this.refreshText,
1145             overflowText: this.refreshText,
1146             iconCls: 'x-tbar-loading',
1147             handler: this.doRefresh,
1148             scope: this
1149         })];
1150
1151
1152         var userItems = this.items || this.buttons || [];
1153         if (this.prependButtons) {
1154             this.items = userItems.concat(pagingItems);
1155         }else{
1156             this.items = pagingItems.concat(userItems);
1157         }
1158         delete this.buttons;
1159         if(this.displayInfo){
1160             this.items.push('->');
1161             this.items.push(this.displayItem = new T.TextItem({}));
1162         }
1163         Ext.PagingToolbar.superclass.initComponent.call(this);
1164         this.addEvents(
1165             /**
1166              * @event change
1167              * Fires after the active page has been changed.
1168              * @param {Ext.PagingToolbar} this
1169              * @param {Object} pageData An object that has these properties:<ul>
1170              * <li><code>total</code> : Number <div class="sub-desc">The total number of records in the dataset as
1171              * returned by the server</div></li>
1172              * <li><code>activePage</code> : Number <div class="sub-desc">The current page number</div></li>
1173              * <li><code>pages</code> : Number <div class="sub-desc">The total number of pages (calculated from
1174              * the total number of records in the dataset as returned by the server and the current {@link #pageSize})</div></li>
1175              * </ul>
1176              */
1177             'change',
1178             /**
1179              * @event beforechange
1180              * Fires just before the active page is changed.
1181              * Return false to prevent the active page from being changed.
1182              * @param {Ext.PagingToolbar} this
1183              * @param {Object} params An object hash of the parameters which the PagingToolbar will send when
1184              * loading the required page. This will contain:<ul>
1185              * <li><code>start</code> : Number <div class="sub-desc">The starting row number for the next page of records to
1186              * be retrieved from the server</div></li>
1187              * <li><code>limit</code> : Number <div class="sub-desc">The number of records to be retrieved from the server</div></li>
1188              * </ul>
1189              * <p>(note: the names of the <b>start</b> and <b>limit</b> properties are determined
1190              * by the store's {@link Ext.data.Store#paramNames paramNames} property.)</p>
1191              * <p>Parameters may be added as required in the event handler.</p>
1192              */
1193             'beforechange'
1194         );
1195         this.on('afterlayout', this.onFirstLayout, this, {single: true});
1196         this.cursor = 0;
1197         this.bindStore(this.store, true);
1198     },
1199
1200     // private
1201     onFirstLayout : function(){
1202         if(this.dsLoaded){
1203             this.onLoad.apply(this, this.dsLoaded);
1204         }
1205     },
1206
1207     // private
1208     updateInfo : function(){
1209         if(this.displayItem){
1210             var count = this.store.getCount();
1211             var msg = count == 0 ?
1212                 this.emptyMsg :
1213                 String.format(
1214                     this.displayMsg,
1215                     this.cursor+1, this.cursor+count, this.store.getTotalCount()
1216                 );
1217             this.displayItem.setText(msg);
1218         }
1219     },
1220
1221     // private
1222     onLoad : function(store, r, o){
1223         if(!this.rendered){
1224             this.dsLoaded = [store, r, o];
1225             return;
1226         }
1227         var p = this.getParams();
1228         this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
1229         var d = this.getPageData(), ap = d.activePage, ps = d.pages;
1230
1231         this.afterTextItem.setText(String.format(this.afterPageText, d.pages));
1232         this.inputItem.setValue(ap);
1233         this.first.setDisabled(ap == 1);
1234         this.prev.setDisabled(ap == 1);
1235         this.next.setDisabled(ap == ps);
1236         this.last.setDisabled(ap == ps);
1237         this.refresh.enable();
1238         this.updateInfo();
1239         this.fireEvent('change', this, d);
1240     },
1241
1242     // private
1243     getPageData : function(){
1244         var total = this.store.getTotalCount();
1245         return {
1246             total : total,
1247             activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
1248             pages :  total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
1249         };
1250     },
1251
1252     /**
1253      * Change the active page
1254      * @param {Integer} page The page to display
1255      */
1256     changePage : function(page){
1257         this.doLoad(((page-1) * this.pageSize).constrain(0, this.store.getTotalCount()));
1258     },
1259
1260     // private
1261     onLoadError : function(){
1262         if(!this.rendered){
1263             return;
1264         }
1265         this.refresh.enable();
1266     },
1267
1268     // private
1269     readPage : function(d){
1270         var v = this.inputItem.getValue(), pageNum;
1271         if (!v || isNaN(pageNum = parseInt(v, 10))) {
1272             this.inputItem.setValue(d.activePage);
1273             return false;
1274         }
1275         return pageNum;
1276     },
1277
1278     onPagingFocus : function(){
1279         this.inputItem.select();
1280     },
1281
1282     //private
1283     onPagingBlur : function(e){
1284         this.inputItem.setValue(this.getPageData().activePage);
1285     },
1286
1287     // private
1288     onPagingKeyDown : function(field, e){
1289         var k = e.getKey(), d = this.getPageData(), pageNum;
1290         if (k == e.RETURN) {
1291             e.stopEvent();
1292             pageNum = this.readPage(d);
1293             if(pageNum !== false){
1294                 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
1295                 this.doLoad(pageNum * this.pageSize);
1296             }
1297         }else if (k == e.HOME || k == e.END){
1298             e.stopEvent();
1299             pageNum = k == e.HOME ? 1 : d.pages;
1300             field.setValue(pageNum);
1301         }else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
1302             e.stopEvent();
1303             if((pageNum = this.readPage(d))){
1304                 var increment = e.shiftKey ? 10 : 1;
1305                 if(k == e.DOWN || k == e.PAGEDOWN){
1306                     increment *= -1;
1307                 }
1308                 pageNum += increment;
1309                 if(pageNum >= 1 & pageNum <= d.pages){
1310                     field.setValue(pageNum);
1311                 }
1312             }
1313         }
1314     },
1315
1316     // private
1317     getParams : function(){
1318         //retain backwards compat, allow params on the toolbar itself, if they exist.
1319         return this.paramNames || this.store.paramNames;
1320     },
1321
1322     // private
1323     getParams : function(){
1324         //retain backwards compat, allow params on the toolbar itself, if they exist.
1325         return this.paramNames || this.store.paramNames;
1326     },
1327
1328     // private
1329     beforeLoad : function(){
1330         if(this.rendered && this.refresh){
1331             this.refresh.disable();
1332         }
1333     },
1334
1335     // private
1336     doLoad : function(start){
1337         var o = {}, pn = this.getParams();
1338         o[pn.start] = start;
1339         o[pn.limit] = this.pageSize;
1340         if(this.fireEvent('beforechange', this, o) !== false){
1341             this.store.load({params:o});
1342         }
1343     },
1344
1345     /**
1346      * Move to the first page, has the same effect as clicking the 'first' button.
1347      */
1348     moveFirst : function(){
1349         this.doLoad(0);
1350     },
1351
1352     /**
1353      * Move to the previous page, has the same effect as clicking the 'previous' button.
1354      */
1355     movePrevious : function(){
1356         this.doLoad(Math.max(0, this.cursor-this.pageSize));
1357     },
1358
1359     /**
1360      * Move to the next page, has the same effect as clicking the 'next' button.
1361      */
1362     moveNext : function(){
1363         this.doLoad(this.cursor+this.pageSize);
1364     },
1365
1366     /**
1367      * Move to the last page, has the same effect as clicking the 'last' button.
1368      */
1369     moveLast : function(){
1370         var total = this.store.getTotalCount(),
1371             extra = total % this.pageSize;
1372
1373         this.doLoad(extra ? (total - extra) : total - this.pageSize);
1374     },
1375
1376     /**
1377      * Refresh the current page, has the same effect as clicking the 'refresh' button.
1378      */
1379     doRefresh : function(){
1380         this.doLoad(this.cursor);
1381     },
1382
1383     /**
1384      * Binds the paging toolbar to the specified {@link Ext.data.Store}
1385      * @param {Store} store The store to bind to this toolbar
1386      * @param {Boolean} initial (Optional) true to not remove listeners
1387      */
1388     bindStore : function(store, initial){
1389         var doLoad;
1390         if(!initial && this.store){
1391             if(store !== this.store && this.store.autoDestroy){
1392                 this.store.destroy();
1393             }else{
1394                 this.store.un('beforeload', this.beforeLoad, this);
1395                 this.store.un('load', this.onLoad, this);
1396                 this.store.un('exception', this.onLoadError, this);
1397             }
1398             if(!store){
1399                 this.store = null;
1400             }
1401         }
1402         if(store){
1403             store = Ext.StoreMgr.lookup(store);
1404             store.on({
1405                 scope: this,
1406                 beforeload: this.beforeLoad,
1407                 load: this.onLoad,
1408                 exception: this.onLoadError
1409             });
1410             doLoad = true;
1411         }
1412         this.store = store;
1413         if(doLoad){
1414             this.onLoad(store, null, {});
1415         }
1416     },
1417
1418     /**
1419      * Unbinds the paging toolbar from the specified {@link Ext.data.Store} <b>(deprecated)</b>
1420      * @param {Ext.data.Store} store The data store to unbind
1421      */
1422     unbind : function(store){
1423         this.bindStore(null);
1424     },
1425
1426     /**
1427      * Binds the paging toolbar to the specified {@link Ext.data.Store} <b>(deprecated)</b>
1428      * @param {Ext.data.Store} store The data store to bind
1429      */
1430     bind : function(store){
1431         this.bindStore(store);
1432     },
1433
1434     // private
1435     onDestroy : function(){
1436         this.bindStore(null);
1437         Ext.PagingToolbar.superclass.onDestroy.call(this);
1438     }
1439 });
1440
1441 })();
1442 Ext.reg('paging', Ext.PagingToolbar);