1
- /**
2
- * @class Ext.ux.Exporter.Button
3
- * @extends Ext.Button
4
- * @author Nige White, with modifications from Ed Spencer
5
- * Specialised Button class that allows downloading of data via data: urls.
6
- * Internally, this is just a link.
7
- * Pass it either an Ext.Component subclass with a 'store' property, or just a store:
8
- * new Ext.ux.Exporter.Button({component: someGrid});
9
- * new Ext.ux.Exporter.Button({store: someStore});
10
- * @cfg {Ext.Component} component The component the store is bound to
11
- * @cfg {Ext.data.Store} store The store to export (alternatively, pass a component with a store property)
12
- */
13
- Ext . ux . Exporter . Button = Ext . extend ( Ext . Button , {
14
- constructor : function ( config ) {
15
- config = config || { } ;
16
-
17
- Ext . applyIf ( config , {
18
- exportFunction : 'exportGrid' ,
19
- disabled : true ,
20
- text : 'Download' ,
21
- cls : 'download'
22
- } ) ;
23
-
24
- if ( config . store == undefined && config . component != undefined ) {
25
- Ext . applyIf ( config , {
26
- store : config . component . store
27
- } ) ;
28
- } else {
29
- Ext . applyIf ( config , {
30
- component : {
31
- store : config . store
32
- }
33
- } ) ;
34
- }
35
-
36
- Ext . ux . Exporter . Button . superclass . constructor . call ( this , config ) ;
37
-
38
- if ( this . store && Ext . isFunction ( this . store . on ) ) {
39
- var setLink = function ( ) {
40
- this . getEl ( ) . child ( 'a' , true ) . href = 'data:application/vnd.ms-excel;base64,' + Ext . ux . Exporter [ config . exportFunction ] ( this . component , null , config ) ;
41
-
42
- this . enable ( ) ;
43
- } ;
44
-
45
- if ( this . el ) {
46
- setLink . call ( this ) ;
47
- } else {
48
- this . on ( 'render' , setLink , this ) ;
49
- }
50
-
51
- this . store . on ( 'load' , setLink , this ) ;
52
- }
53
- } ,
54
-
55
- template : new Ext . Template (
56
- '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>' ,
57
- '<td class="x-btn-left"><i> </i></td><td class="x-btn-center"><a class="x-btn-text" href="{1}" target="{2}">{0}</a></td><td class="x-btn-right"><i> </i></td>' ,
58
- "</tr></tbody></table>" ) ,
59
-
60
- onRender : function ( ct , position ) {
61
- var btn , targs = [ this . text || ' ' , this . href , this . target || "_self" ] ;
62
- if ( position ) {
63
- btn = this . template . insertBefore ( position , targs , true ) ;
64
- } else {
65
- btn = this . template . append ( ct , targs , true ) ;
66
- }
67
- var btnEl = btn . child ( "a:first" ) ;
68
- btnEl . on ( 'focus' , this . onFocus , this ) ;
69
- btnEl . on ( 'blur' , this . onBlur , this ) ;
70
-
71
- this . initButtonEl ( btn , btnEl ) ;
72
- Ext . ButtonToggleMgr . register ( this ) ;
73
- } ,
74
-
75
- onClick : function ( e ) {
76
- if ( e . button != 0 ) return ;
77
-
78
- if ( ! this . disabled ) {
79
- this . fireEvent ( "click" , this , e ) ;
80
-
81
- if ( this . handler ) this . handler . call ( this . scope || this , this , e ) ;
82
- }
83
- }
84
- } ) ;
85
-
1
+ /**
2
+ * @class Ext.ux.Exporter.Button
3
+ * @extends Ext.Button
4
+ * @author Nige White, with modifications from Ed Spencer
5
+ * Specialised Button class that allows downloading of data via data: urls.
6
+ * Internally, this is just a link.
7
+ * Pass it either an Ext.Component subclass with a 'store' property, or just a store:
8
+ * new Ext.ux.Exporter.Button({component: someGrid});
9
+ * new Ext.ux.Exporter.Button({store: someStore});
10
+ * @cfg {Ext.Component} component The component the store is bound to
11
+ * @cfg {Ext.data.Store} store The store to export (alternatively, pass a component with a store property)
12
+ */
13
+ Ext . ux . Exporter . Button = Ext . extend ( Ext . Button , {
14
+ constructor : function ( config ) {
15
+ config = config || { } ;
16
+
17
+ Ext . applyIf ( config , {
18
+ exportFunction : 'exportGrid' ,
19
+ disabled : true ,
20
+ text : 'Download' ,
21
+ cls : 'download'
22
+ } ) ;
23
+
24
+ if ( config . store == undefined && config . component != undefined ) {
25
+ Ext . applyIf ( config , {
26
+ store : config . component . store
27
+ } ) ;
28
+ } else {
29
+ Ext . applyIf ( config , {
30
+ component : {
31
+ store : config . store
32
+ }
33
+ } ) ;
34
+ }
35
+
36
+ Ext . ux . Exporter . Button . superclass . constructor . call ( this , config ) ;
37
+
38
+ if ( this . store && Ext . isFunction ( this . store . on ) ) {
39
+ var setLink = function ( ) {
40
+ this . getEl ( ) . child ( 'a' , true ) . href = 'data:application/vnd.ms-excel;base64,' + Ext . ux . Exporter [ config . exportFunction ] ( this . component , null , config ) ;
41
+
42
+ this . enable ( ) ;
43
+ } ;
44
+
45
+ if ( this . el ) {
46
+ setLink . call ( this ) ;
47
+ } else {
48
+ this . on ( 'render' , setLink , this ) ;
49
+ }
50
+
51
+ this . store . on ( 'load' , setLink , this ) ;
52
+ }
53
+ } ,
54
+
55
+ template : new Ext . Template (
56
+ '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>' ,
57
+ '<td class="x-btn-left"><i> </i></td><td class="x-btn-center"><a class="x-btn-text" href="{1}" target="{2}">{0}</a></td><td class="x-btn-right"><i> </i></td>' ,
58
+ "</tr></tbody></table>" ) ,
59
+
60
+ onRender : function ( ct , position ) {
61
+ var btn , targs = [ this . text || ' ' , this . href , this . target || "_self" ] ;
62
+ if ( position ) {
63
+ btn = this . template . insertBefore ( position , targs , true ) ;
64
+ } else {
65
+ btn = this . template . append ( ct , targs , true ) ;
66
+ }
67
+ var btnEl = btn . child ( "a:first" ) ;
68
+ this . btnEl = btnEl ;
69
+ btnEl . on ( 'focus' , this . onFocus , this ) ;
70
+ btnEl . on ( 'blur' , this . onBlur , this ) ;
71
+
72
+ this . initButtonEl ( btn , btnEl ) ;
73
+ Ext . ButtonToggleMgr . register ( this ) ;
74
+ } ,
75
+
76
+ onClick : function ( e ) {
77
+ if ( e . button != 0 ) return ;
78
+
79
+ if ( ! this . disabled ) {
80
+ this . fireEvent ( "click" , this , e ) ;
81
+
82
+ if ( this . handler ) this . handler . call ( this . scope || this , this , e ) ;
83
+ }
84
+ }
85
+ } ) ;
86
+
86
87
Ext . reg ( 'exportbutton' , Ext . ux . Exporter . Button ) ;
0 commit comments