Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / view / multisort / SortButton.js
1 /**
2  * @class Ext.multisort.SortButton
3  * @extends Ext.button.Button
4  * @author Ed Spencer
5  * 
6  * 
7  */
8 Ext.define('Ext.multisort.SortButton', {
9     extend: 'Ext.button.Button',
10     alias : 'widget.sortbutton',
11     
12     config: {
13         direction: "ASC",
14         dataIndex: undefined
15     },
16     
17     constructor: function(config) {
18         this.addEvents(
19             /**
20              * @event changeDirection
21              * Fired whenever the user clicks this button to change its direction
22              * @param {String} direction The new direction (ASC or DESC)
23              */
24             'changeDirection'
25         );
26         
27         this.initConfig(config);
28         
29         this.callParent(arguments);
30     },
31     
32     handler: function() {
33         this.toggleDirection();
34     },
35     
36     /**
37      * Sets the new direction of this button
38      * @param {String} direction The new direction
39      */
40     applyDirection: function(direction) {
41         this._direction = direction;
42         this.setIconCls('direction-' + direction.toLowerCase());
43         
44         this.fireEvent('changeDirection', direction);
45         
46         return direction;
47     },
48     
49     /**
50      * Toggles between ASC and DESC directions
51      */
52     toggleDirection: function() {
53         this.setDirection(Ext.String.toggle(this.getDirection(), "ASC", "DESC"));
54     }
55 });