<script type="text/javascript" src="/static/js/vendor/jquery.leanModal.min.js"></script>
<script type="text/javascript">

function setup_debug(element_id, edit_link, staff_context){
	$('#' + element_id + '_trig').leanModal(); 
	$('#' + element_id + '_xqa_log').leanModal();		
	$('#' + element_id + '_xqa_form').submit(function () {sendlog(element_id, edit_link, staff_context);});
}

function sendlog(element_id, edit_link, staff_context){

	var xqaLog = {
			authkey: staff_context.xqa_key,
			location: staff_context.location,
			category : staff_context.category,
			'username' : staff_context.user.username,
			'return' : 'query',
			format : 'html',
			email : staff_context.user.email,
			tag:$('#' + element_id + '_xqa_tag').val(),
			entry: $('#' + element_id + '_xqa_entry').val()
		};
			
	if (edit_link) xqaLog["giturl"] = edit_link;

	$.ajax({
		url: '${xqa_server}/log',
		type: 'GET',
		contentType: 'application/json',
		data: JSON.stringify(xqaLog),
		crossDomain: true,
		dataType: 'jsonp',
		beforeSend: function (xhr) { 
			xhr.setRequestHeader ("Authorization", "Basic eHFhOmFnYXJ3YWw="); },
		timeout : 1000,
		success: function(result) {
				$('#' + element_id + '_xqa_log_data').html(result);
		},
		error: function() {
			alert('Error: cannot connect to XQA server');
			console.log('error!');
		}
	});
	return false;
};

function getlog(element_id, staff_context){

	var xqaQuery = {
		authkey: staff_context.xqa_key,
		location: staff_context.location,
		format: 'html'
	};

	$.ajax({
		url: '${xqa_server}/query',
		type: 'GET',
		contentType: 'application/json',
		data: JSON.stringify(xqaQuery),
		crossDomain: true,
		dataType: 'jsonp',
		timeout : 1000,
		success: function(result) {
			$('#' + element_id + '_xqa_log_data').html(result);
		},
		error: function() {
			alert('Error: cannot connect to XQA server');
		}
	});


};
</script>