src/pyams_skin/resources/js/myams.js
changeset 498 7d479c20ee49
parent 490 135a744a7732
child 501 2f0eb9a77324
--- a/src/pyams_skin/resources/js/myams.js	Thu Dec 20 14:13:03 2018 +0100
+++ b/src/pyams_skin/resources/js/myams.js	Thu Dec 20 14:13:45 2018 +0100
@@ -2565,8 +2565,8 @@
 		shown: function(e) {
 
 			function resetViewport(ev) {
-				var top = $('.scrollmarker.top', viewport);
-				var topPosition = viewport.scrollTop();
+				var top = $('.scrollmarker.top', viewport),
+					topPosition = viewport.scrollTop();
 				if (topPosition > 0) {
 					top.show();
 				} else {
@@ -2580,11 +2580,11 @@
 				}
 			}
 
-			var modal = e.target;
-			var viewport = $('.modal-viewport', modal);
+			var modal = e.target,
+				viewport = $('.modal-viewport', modal);
 			if (viewport.exists()) {
-				var maxHeight = parseInt(viewport.css('max-height'));
-				var barWidth = $.scrollbarWidth();
+				var maxHeight = parseInt(viewport.css('max-height')),
+					barWidth = $.scrollbarWidth();
 				if ((viewport.css('overflow') !== 'hidden') &&
 					(viewport.height() === maxHeight)) {
 					$('<div></div>').addClass('scrollmarker')
@@ -2614,8 +2614,8 @@
 				}
 			});
 			// Call shown callbacks registered for this dialog
-			var index;
-			var callbacks = $('.modal-dialog', modal).data('shown-callbacks');
+			var index,
+				callbacks = $('.modal-dialog', modal).data('shown-callbacks');
 			if (callbacks) {
 				for (index=0; index < callbacks.length; index++) {
 					callbacks[index].call(modal);
@@ -5253,6 +5253,40 @@
 						}
 					});
 			}
+		},
+
+		/**
+		 * Export table to CSV
+		 */
+		exportTableToTSV: function() {
+			return function() {
+				var source = $(this);
+				ams.ajax && ams.ajax.check(globals.saveAs,
+										   ams.baseURL + 'ext/js-filesaver' + ams.devext + '.js',
+										   function() {
+												var table = $('table.datatable', source.parents('.ams-widget:first'));
+												var datatable = table.dataTable();
+												var output = '';
+												$('th', table).each(function(index) {
+													if (index > 0) {
+														output += '\t';
+													}
+													output += $(this).text();
+												});
+												output += '\n';
+												$(datatable.fnGetData()).each(function() {
+													$(this).each(function(index) {
+														if (index > 0) {
+															output += '\t';
+														}
+														output += this;
+													});
+													output += '\n';
+												});
+												var blob = new Blob([output], {type: 'text/tsv; charset=utf-8'});
+												saveAs(blob, "export.tsv");
+										   });
+			}
 		}
 	};