diff war/scripts/sti/STICore.js @ 86:ed444173aef0 trimmed_data

local CSV loading
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Thu, 07 Mar 2013 14:47:36 +0100
parents 108c853e0900
children 593cfbd58c3e
line wrap: on
line diff
--- a/war/scripts/sti/STICore.js	Thu Mar 07 14:35:30 2013 +0100
+++ b/war/scripts/sti/STICore.js	Thu Mar 07 14:47:36 2013 +0100
@@ -575,6 +575,59 @@
     },
     
     /**
+	 * retrieves and loads a CSV-file from the local system
+	 * 
+	 * @param {int}
+	 *            ds the datasource index
+	 * @param {File}
+	 *            file the file that the user selected
+	 */
+	retrieveLocalCsv: function(ds,filename){
+
+		var core = this;
+		if( this.blocked ){
+			setTimeout( function(){ core.retrieveLocalCsv(ds,filename); }, 100 );
+			return;
+		}
+		core.blockUI();
+		
+		var status = document.getElementById("statusText");
+		status.innerHTML = "Retrieving Data ...";
+		
+		var filelist = $('#localCSVFileChooser').get(0).files;
+		if (filelist.length > 0){
+			var file = filelist[0];
+			
+			var reader = new FileReader();
+			
+			reader.onloadend = (function(theFile) {
+		        return function(e) {
+					status.innerHTML = "Parsing Data ...";
+					
+					var kmlText = core.convertCsv(reader.result);
+					
+					var localkmlDoc;
+					try {
+						localkmlDoc = $.parseXML(kmlText);
+					} catch (e) {
+						alert("KML file is not valid XML. Please check opening/closing tags and check the spelling.");
+						
+						core.unblockUI();
+						
+						return;
+					}
+					
+					setTimeout( function(){ core.parseIt(localkmlDoc,filename,ds); }, 1 );
+				};
+		    })(file);
+						
+			reader.readAsText(file);
+		}
+
+		return;
+    },
+    
+    /**
 	 * parses the kml-file which includes the results for a given search request
 	 * 
 	 * @param {File}