{% load i18n l10n %}

{% get_current_language as LANGUAGE_CODE %}

<style type ="text/css" media="screen" >
	.button_xslx
	{
		padding: 3px 3px 2px 2px;
		float:right;
	}

	.download_xslx
	{
		/*padding: 3px 3px 2px 2px;*/
		/*border:1px solid green;*/
		display: inline-block;

	}

</style>


<div id='{{view_name}}_{{button_name}}_xlsx' class = 'button_xslx'>
	<div id='{{view_name}}_{{button_name}}_download' class = 'download_xslx'> </div>
	<div id='{{view_name}}_{{button_name}}_button'> {{button_title}} </div>
</div>

<!-- <div id="{{view_name}}_div_excel_csv" class="excel_container">
	<a id = "excel_{{view_name}}" href="#"  alt="{% trans 'Save CDRs whith current settings' %}">Excel</a>
	<a id="csv_{{view_name}}" href="#"  alt="{% trans 'Save CDRs whith current settings' %}">CSV</a>
</div> -->


<script type="text/javascript" lang="text/javascript">

	$('#{{view_name}}_{{button_name}}_button').button({icons: {primary: "ui-icon-disk"}});


	$('#{{view_name}}_{{button_name}}_button').click(function(e){
		var button_name = '{{button_name}}';
		console.log('button_name-->',button_name);
		{{view_name}}_callback('xlsx',button_name);
	});

	function setExportFile(URL_XLSX,param){

			MEDIA_URL='/media/'


			url = URL_XLSX
			$.ajax({
				type: 'GET',
				url: url+'?'+param,
				dataType: 'json',
				success: function(response){
					// console.log('returned...',response);
					url_icon = '</span><a href="'+MEDIA_URL+response['file_url']+'" title=""><span class="ui-icon ui-icon-circle-arrow-s download_file"  id = "{{view_name}}_{{button_name}}_button_download" s></span></a></span></div>'
					createMessagesLocal('{{view_name}}_result_messages',"{% trans 'Generating excel ... ' %}", 'info', 3000);
			
					$('#{{view_name}}_{{button_name}}_download').html(url_icon);
					$('#{{view_name}}_{{button_name}}_button_download').click();
					$('#{{view_name}}_{{button_name}}_button_download').hide();

					// setCloseMessagesEvent();
				}
			});
		};

function saveFile(url,param)
{
	error = false;
	$.fileDownload(url, {
		data: param,
	    failCallback: function () {
	 		error = true
	 		createMessagesLocal('{{view_name}}_result_messages',"{% trans 'There was a problem generating your report, please try again.' %}", 'error', 3000);	
	    },
	});

	if (error == false){
		createMessagesLocal('{{view_name}}_result_messages',"{% trans 'We are preparing your report, please wait...' %}", 'success', 3000);	
	}
}

</script> 