<div class="popover-content">
  <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-category-name-{{ category_id }}">
	{% for language in languages %}
	  <div class="input-group">
	    <span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>
		<input type="text" name="category_description[{{ language.language_id }}][name]" value="{{ category_description[language.language_id] ? category_description[language.language_id].name }}" placeholder="{{ entry_name }}" class="form-control" />
	  </div>
	{% endfor %}
  </form>
</div>
<div class="popover-footer">
  <a data-form="form-category-name-{{ category_id }}" class="button-save btn btn-primary btn-sm"><i class="fa fa-save fa-fw"></i></a><a id="clear-category-name-{{ category_id }}" class="btn btn-danger btn-sm"><i class="fa fa-eraser fa-fw"></i></a>
</div>
<script type="text/javascript"><!--
$('.button-save').on('click', function() {	
	$.ajax({
		url: $('#' + $(this).data('form')).attr('action'),
		type: 'post',
		dataType: 'json',
		data: $('#form-category-name-{{ category_id }} input[type=\'text\']'),
		success: function(json) {									
			if (json['error']) {								
				$('.messages-body').html('<div class="alert alert-danger alert-messages"><i class="fa fa-check-circle"></i> ' + json['error'] + '</div>');$('.maxy-backdrop, .messages-body').show().delay(1500).fadeOut(500);
			}
									
			if (json['success']) {
				$('.messages-body').html('<div class="alert alert-success alert-messages"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');$('.maxy-backdrop, .messages-body').show().delay(1000).fadeOut(500);			
				
				$('#close-name-{{ category_id }}').trigger('click');
				
				setTimeout(function(){			
					location.reload(true);
				}, 500);
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
}); 

$('#close-name-{{ category_id }}').on('click', function() {
	$('#form-category-name-{{ category_id }}').empty();
	$('#category-name-{{ category_id }}').popoverMaxy('hide');
});	

$('#category-name-{{ category_id }}').on('hide.bs.modal', function () {
	$('#form-category-name-{{ category_id }}').empty();
});

$('#clear-category-name-{{ category_id }}').on('click', function() {
	$('#form-category-name-{{ category_id }}').find('input').val('');
});  
//--></script>