{% extends "imports/base.html" %}
{% load i18n %}
{% load dashboard_tags %}

{% block title %}Import Users{% endblock %}

{% block body %}
<div class="t">
{% dashboard_nav user %}	
<div class="imports">
	<b>{% blocktrans with request.user.username as requser %}You ({{ requser }}) are importing the following file at (time) {% endblocktrans %}({% now "D d M Y P" %})</b>: <br> 
	<font color="red">
	{{ file_name }}
	</font>
	<br>
	{% trans "Note: User Logging Will be Suspended for the duration of import for this session only." %}<br>
	<br>
	<div class="results">
		<div class="loading-icon" style="position:absolute;top:100;left:50;width:300px;padding:5px;border:1px solid #071C7F;margin-bottom:3em;">
			<img src="{{ STATIC_URL }}images/icons/loading.gif" alt="loading"/> {% trans "loading ..." %}
		</div>
	</div>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
</div>
</div>
{% endblock %}

{% block extra_body %}
{{ block.super }}

<script text="text/javascript">
$(document).ready(function(){
    var i = 0;
    var completed = false;
    
    var poll_and_process = function(){
	    var myurl = "{% url import.user_upload_subprocess id %}";
	    var retval;
	    var doc_h;
	    //var dfd = $$.Deferred();

		$.ajax({
			type: "GET",
			url: myurl, 
			async: true,
			success: function(data){
				data = data.replace(/^\s+|\s+$/g, '');
				if (i == 0){
					$(".results").html(data);
				}
				else{
					$('.loading-icon').remove();
					$(".results").append(data);
				}
				
				if (data == ''){ 
			    	completed = true;
			    	$('.loading-icon').remove();
			    }
			    $(document).trigger('subprocess/continue');
			},
			error: function(errmsg){
				$('.loading-icon').remove();
				$(".results").append(errmsg);
				completed = true;
				$(document).trigger('subprocess/continue');
			}
		});
		i++;
	}

	poll_and_process();
	$(document).on('subprocess/continue', function(e){
	    if (!completed){
	        poll_and_process();
	    }
	})
    
}); 

</script>


{% endblock %}