Subversion Repositories DevTools

Rev

Rev 6683 | Rev 6787 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6683 Rev 6695
Line 12... Line 12...
12
/*
12
/*
13
**  Vix: Minor modifications to:
13
**  Vix: Minor modifications to:
14
**      Fill popup with entire TextArea
14
**      Fill popup with entire TextArea
15
**      Only select td in the current table - prevent picking up bits from nested tables
15
**      Only select td in the current table - prevent picking up bits from nested tables
16
**      'th' with a class of 'noCsv' will exclude the entire column from the output
16
**      'th' with a class of 'noCsv' will exclude the entire column from the output
-
 
17
**      The 'modal' display type
-
 
18
**      The 'title' option
17
*/
19
*/
18
jQuery.fn.TableCSVExport = function (options) {
20
jQuery.fn.TableCSVExport = function (options) {
19
    var options = jQuery.extend({
21
    var options = jQuery.extend({
20
        separator: ',',
22
        separator: ',',
21
        header: [],
23
        header: [],
22
        columns: [],
24
        columns: [],
23
        extraHeader: "",
25
        extraHeader: "",
24
        extraData: [],
26
        extraData: [],
25
        insertBefore: "",
27
        insertBefore: "",
26
        delivery: 'popup' /* popup, value, download */,
28
        delivery: 'popup' /* popup, value, download, modal */,
27
        emptyValue: '',
29
        emptyValue: '',
28
        showHiddenRows: false,
30
        showHiddenRows: false,
29
	    rowFilter: "",
31
	    rowFilter: "",
30
	    filename: "download.csv"
32
	    filename: "download.csv",
-
 
33
        title : "CSV Data"
31
    },
34
    },
32
    options);
35
    options);
33
 
36
 
34
    var csvData = [];
37
    var csvData = [];
35
    var headerArr = [];
38
    var headerArr = [];
Line 137... Line 140...
137
    }
140
    }
138
 
141
 
139
    if ((options.delivery == 'popup') || (options.delivery == 'download')) {
142
    if ((options.delivery == 'popup') || (options.delivery == 'download')) {
140
        var mydata = csvData.join('\n');
143
        var mydata = csvData.join('\n');
141
        return popup(mydata);
144
        return popup(mydata);
-
 
145
    } else if ( options.delivery == 'modal' ) {
-
 
146
        var mydata = csvData.join('<br>');
-
 
147
        return popup(mydata);
142
    } else {
148
    } else {
143
        var mydata = csvData.join('\n');
149
        var mydata = csvData.join('\n');
144
        return mydata;
150
        return mydata;
145
    }
151
    }
146
 
152
 
Line 164... Line 170...
164
        output = $(output).text().trim();
170
        output = $(output).text().trim();
165
        
171
        
166
        if (output == "") return '';
172
        if (output == "") return '';
167
        return '"' + output + '"';
173
        return '"' + output + '"';
168
    }
174
    }
-
 
175
 
169
    function popup(data) {
176
    function popup(data) {
170
        if (options.delivery == 'download') {
177
        if (options.delivery == 'download') {
171
            var blob = new Blob(['\ufeff'+data], { type: 'text/csv;charset=utf-8;' });
178
            var blob = new Blob(['\ufeff'+data], { type: 'text/csv;charset=utf-8;' });
172
            if (navigator.msSaveBlob) { // IE 10+
179
            if (navigator.msSaveBlob) { // IE 10+
173
                navigator.msSaveBlob(blob, options.filename);
180
                navigator.msSaveBlob(blob, options.filename);
Line 183... Line 190...
183
                document.body.appendChild(link);
190
                document.body.appendChild(link);
184
                link.click();
191
                link.click();
185
                document.body.removeChild(link);
192
                document.body.removeChild(link);
186
            }
193
            }
187
            return true;
194
            return true;
-
 
195
        } else if (options.delivery == 'modal') {
-
 
196
            var newDiv = $(document.createElement('div'));
-
 
197
            $(newDiv).html(data);
-
 
198
            $(newDiv).dialog({width: 400, height: 400, modal:true, position: { my: "top", at: "top+100", of: window }, title: options.title});
-
 
199
            return true;
188
        } else {
200
        } else {
189
            var generator = window.open('', 'csv', 'height=400,width=600');
201
            var generator = PopupCenter('', options.title, 600, 400);
190
            generator.document.write('<html><head><title>CSV</title>');
202
            generator.document.write('<html><head><title>'+options.title+'</title>');
191
            generator.document.write('</head><body >');
203
            generator.document.write('</head><body >');
192
            generator.document.write('<textArea style="width:100%; height:100%;" wrap="off" >');
204
            generator.document.write('<textArea style="width:100%; height:100%;" wrap="off" >');
193
            generator.document.write(data);
205
            generator.document.write(data);
194
            generator.document.write('</textArea>');
206
            generator.document.write('</textArea>');
195
            generator.document.write('</body></html>');
207
            generator.document.write('</body></html>');