Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / view / multisort / SortButton.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.multisort.SortButton
17  * @extends Ext.button.Button
18  * @author Ed Spencer
19  * 
20  * 
21  */
22 Ext.define('Ext.multisort.SortButton', {
23     extend: 'Ext.button.Button',
24     alias : 'widget.sortbutton',
25     
26     config: {
27         direction: "ASC",
28         dataIndex: undefined
29     },
30     
31     constructor: function(config) {
32         this.addEvents(
33             /**
34              * @event changeDirection
35              * Fired whenever the user clicks this button to change its direction
36              * @param {String} direction The new direction (ASC or DESC)
37              */
38             'changeDirection'
39         );
40         
41         this.initConfig(config);
42         
43         this.callParent(arguments);
44     },
45     
46     handler: function() {
47         this.toggleDirection();
48     },
49     
50     /**
51      * Sets the new direction of this button
52      * @param {String} direction The new direction
53      */
54     applyDirection: function(direction) {
55         this._direction = direction;
56         this.setIconCls('direction-' + direction.toLowerCase());
57         
58         this.fireEvent('changeDirection', direction);
59         
60         return direction;
61     },
62     
63     /**
64      * Toggles between ASC and DESC directions
65      */
66     toggleDirection: function() {
67         this.setDirection(Ext.String.toggle(this.getDirection(), "ASC", "DESC"));
68     }
69 });