1
- ( function ( window , document ) {
1
+ ( function ( window , document ) {
2
2
angular . module ( 'ngExportButton' , [ 'ngExportButton.directive' ] ) ;
3
3
4
4
angular . module ( 'ngExportButton.directive' , [ 'mgcrea.ngStrap' , 'ngCsv' , 'ngSanitize' ] ) ;
5
5
6
- angular . module ( 'ngExportButton.directive' ) .
7
- directive ( 'exportButton' , [ '$modal' ,
8
- function ( $modal ) {
6
+ angular . module ( 'ngExportButton.directive' ) . directive ( 'exportButton' , [ '$modal' ,
7
+ function ( $modal ) {
9
8
10
- var linker = function ( scope , element , attrs ) {
9
+ var linker = function ( scope , element , attrs ) {
11
10
12
- //Init modal window instance
13
- var fileNameModal = $modal ( { scope : scope , template : 'templates/fileName-modal.tpl.html' , show : false } ) ;
11
+ //Init modal window instance
12
+ var fileNameModal = $modal ( { scope : scope , template : 'templates/fileName-modal.tpl.html' , show : false } ) ;
14
13
15
- //function that open modal window
16
- scope . showModal = function ( ) {
17
- fileNameModal . $promise . then ( fileNameModal . show ) ;
18
- } ;
14
+ //function that open modal window
15
+ scope . showModal = function ( ) {
16
+ fileNameModal . $promise . then ( fileNameModal . show ) ;
17
+ } ;
18
+
19
+
20
+ scope . CSVheaders = angular . copy ( scope . headers ) ;
19
21
20
- //function that create and return data for csv report.
21
- scope . getSCVArray = function ( ) {
22
- var data = [ ] ;
23
- angular . forEach ( scope . resources , function ( resource ) {
24
- var tmp = { }
25
- angular . forEach ( scope . fields , function ( field ) {
26
- tmp [ field ] = resource [ field ] ;
27
- } ) ;
28
- data . push ( tmp ) ;
22
+ //function that create and return data for csv report.
23
+ scope . getSCVArray = function ( ) {
24
+ var data = [ ] ;
25
+ angular . forEach ( scope . resources , function ( resource ) {
26
+ var tmp = { }
27
+ angular . forEach ( scope . fields , function ( field ) {
28
+ tmp [ field ] = resource [ field ] ;
29
29
} ) ;
30
- return data ;
31
- } ;
30
+ data . push ( tmp ) ;
31
+ } ) ;
32
+ return data ;
33
+ } ;
34
+
35
+ //function that create and return data for pdf table report.
36
+ scope . getPDFDef = function ( ) {
32
37
33
- //function that create and return data for pdf table report.
34
- scope . getPDFDef = function ( ) {
35
-
36
- var data = [ ] ;
37
- data . push ( scope . headers ) ;
38
- angular . forEach ( scope . resources , function ( resource ) {
39
- var tmp = [ ]
40
- angular . forEach ( scope . fields , function ( field ) {
41
- tmp . push ( resource [ field ] ) ;
42
- } ) ;
43
- data . push ( tmp ) ;
38
+ var data = [ ] ;
39
+ data . push ( scope . headers ) ;
40
+ angular . forEach ( scope . resources , function ( resource ) {
41
+ var tmp = [ ]
42
+ angular . forEach ( scope . fields , function ( field ) {
43
+ tmp . push ( resource [ field ] ) ;
44
44
} ) ;
45
+ data . push ( tmp ) ;
46
+ } ) ;
45
47
46
48
47
- var pdf = {
48
- content : [
49
- {
50
- table : {
51
- headerRows : 1 ,
52
- width : [ 'auto' , 'auto' , 'auto' ] ,
53
- body : data
54
- }
49
+ var pdf = {
50
+ content : [
51
+ {
52
+ table : {
53
+ headerRows : 1 ,
54
+ width : [ 'auto' , 'auto' , 'auto' ] ,
55
+ body : data
55
56
}
56
- ]
57
- } ;
58
-
59
- return pdf ;
57
+ }
58
+ ] ,
59
+ pageOrientation : scope . pageOrientation
60
60
} ;
61
61
62
- //function that download pdf file
63
- scope . downloadPDF = function ( filename ) {
62
+ return pdf ;
63
+ } ;
64
64
65
- var documentDef = scope . getPDFDef ( ) ;
65
+ //function that download pdf file
66
+ scope . downloadPDF = function ( filename ) {
66
67
67
- pdfMake . createPdf ( documentDef ) . download ( filename + '.pdf' ) ;
68
+ var documentDef = scope . getPDFDef ( ) ;
68
69
69
- } ;
70
+ pdfMake . createPdf ( documentDef ) . download ( filename + '.pdf' ) ;
70
71
71
- //function that open pdf print dialog
72
- scope . printPDF = function ( ) {
72
+ } ;
73
73
74
- var documentDef = scope . getPDFDef ( ) ;
74
+ //function that open pdf print dialog
75
+ scope . printPDF = function ( ) {
75
76
76
- pdfMake . createPdf ( documentDef ) . print ( ) ;
77
- } ;
77
+ var documentDef = scope . getPDFDef ( ) ;
78
78
79
+ pdfMake . createPdf ( documentDef ) . print ( ) ;
79
80
} ;
80
81
81
- return {
82
- restrict : 'AE' ,
83
- scope : {
84
- fileName : '=exportFileName' ,
85
- resources : '=resources' ,
86
- fields : '=fields' ,
87
- headers : '=headers'
88
- } ,
89
- link : linker ,
90
- transclude : true ,
91
- templateUrl : 'templates/export-button.tpl.html'
92
-
93
- } ;
94
- }
95
- ] ) ;
82
+ } ;
83
+
84
+ return {
85
+ restrict : 'AE' ,
86
+ scope : {
87
+ fileName : '=exportFileName' ,
88
+ resources : '=resources' ,
89
+ fields : '=fields' ,
90
+ headers : '=headers' ,
91
+ pageOrientation : '=pageOrientation'
92
+ } ,
93
+ link : linker ,
94
+ transclude : true ,
95
+ templateUrl : 'templates/export-button.tpl.html'
96
+
97
+ } ;
98
+ }
99
+ ] ) ;
96
100
97
101
} ) ( window , document ) ;
0 commit comments