10280c757044df6a8da1c040d30ab23801aff35f
[src/app-framework-demo.git] / afb-client / app / Frontend / widgets / FormInput / newjavascript.js
1 /* 
2  * Copyright (C) 2015 fulup
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18  var reader = new FileReader();
19  // Closure to capture the file information.
20       reader.onload = (function(theFile) {
21         return function(e) {
22           var $title = $("<h4>", {
23             text : theFile.name
24           });
25           $result.append($title);
26           var $fileContent = $("<ul>");
27           try {
28
29             var dateBefore = new Date();
30             // read the content of the file with JSZip
31             var zip = new JSZip(e.target.result);
32             var dateAfter = new Date();
33
34             $title.append($("<span>", {
35               text:" (parsed in " + (dateAfter - dateBefore) + "ms)"
36             }));
37
38             // that, or a good ol' for(var entryName in zip.files)
39             $.each(zip.files, function (index, zipEntry) {
40               $fileContent.append($("<li>", {
41                 text : zipEntry.name
42               }));
43               // the content is here : zipEntry.asText()
44             });
45             // end of the magic !
46
47           } catch(e) {
48             $fileContent = $("<div>", {
49               "class" : "alert alert-danger",
50               text : "Error reading " + theFile.name + " : " + e.message
51             });
52           }
53           $result.append($fileContent);
54         }
55       })(f);