src/main/webapp/js/singlepage-interface.js
/**
	 * Request the currently shown results as a CSV file, and save it.
	 *
	 * 'this' should be the tab containing the results to export.
	 * 'event.target' should be the element that was clicked.
	 *
	 * @param {Jquery.Event} event
	 */
Request the currently shown results as a CSV file, and save it.
'this' should be the tab containing the results to export.
'event.target' should be the element that was clicked.


Request the currently shown results as a CSV file and save it . ' this ' should be the tab containing the results to export . ' event . target ' should be the element that was clicked .
function onExportCsv(event) {
		var $tab = $(event.delegateTarget);
		var $button = $(event.target);
		if ($button.hasClass('disabled'))
			return;
		var pageParam = $.extend({},
			$tab.data('defaultParameters'),
			$tab.data('parameters'),
			$tab.data('constParameters'));
		var blsParam = SINGLEPAGE.BLS.getBlsParam(pageParam);
		blsParam.outputformat = 'csv';
		delete blsParam.number;
		delete blsParam.first;
		var url = new URI(BLS_URL).segment(pageParam.operation).addSearch(blsParam).toString();
		if (SINGLEPAGE.DEBUG) {
			console.log('CSV download url', url, blsParam);
		}
		$button
			.addClass('disabled')
			.attr('disabled', true)
			.prepend('<span class="fa fa-spinner fa-spin"></span>');
		$.ajax(url, {
			accepts: 'application/csv',
			cache: 'false',
			data: 'text',
			error: function(jqXHR, textStatus, errorThrown) {
			},
			success: function(data) {
				var b = new Blob([data], { type: 'application/csv' });
				saveAs(b, 'data.csv'); 
			},
			complete: function() {
				$button
					.removeClass('disabled')
					.attr('disabled', false)
					.find('.fa-spinner').remove();
			}
		});
	}
function onExportCsv ( event ) { var $tab = $ ( event . delegateTarget ) ; var $button = $ ( event . target ) ; if ( $button . hasClass ( 'disabled' ) ) return ; var pageParam = $ . extend ( { } , $tab . data ( 'defaultParameters' ) , $tab . data ( 'parameters' ) , $tab . data ( 'constParameters' ) ) ; var blsParam = SINGLEPAGE . BLS . getBlsParam ( pageParam ) ; blsParam . outputformat = 'csv' ; delete blsParam . number ; delete blsParam . first ; var url = new URI ( BLS_URL ) . segment ( pageParam . operation ) . addSearch ( blsParam ) . toString ( ) ; if ( SINGLEPAGE . DEBUG ) { console . log ( 'CSV download url' , url , blsParam ) ; } $button . addClass ( 'disabled' ) . attr ( 'disabled' , true ) . prepend ( '<span class="fa fa-spinner fa-spin"></span>' ) ; $ . ajax ( url , { accepts : 'application/csv' , cache : 'false' , data : 'text' , error : function ( jqXHR , textStatus , errorThrown ) { } , success : function ( data ) { var b = new Blob ( [ data ] , { type : 'application/csv' } ) ; saveAs ( b , 'data.csv' ) ; } , complete : function ( ) { $button . removeClass ( 'disabled' ) . attr ( 'disabled' , false ) . find ( '.fa-spinner' ) . remove ( ) ; } } ) ; }
Request the currently shown results as a CSV file, and save it.
Request the currently shown results as a CSV file and save it .
// FileSaver.js