<div class="popover-content">
  <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-option-name-{{ option_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="option_description[{{ language.language_id }}][name]" value="{{ option_description[language.language_id] ? option_description[language.language_id].name }}" placeholder="{{ entry_name }}" class="form-control" />
      </div>
	{% endfor %}
</div>
<div class="popover-footer">
  <a data-form="form-option-name-{{ option_id }}" class="button-save btn btn-primary btn-sm"><i class="fa fa-save fa-fw"></i></a><a id="clear-option-name-{{ option_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() {	
	var name = $('input[name="option_description[{{ config_language_id }}][name]"]').val(); 	
	$.ajax({
		url: $('#' + $(this).data('form')).attr('action'),
		type: 'post',
		dataType: 'json',
		data: $('#form-option-name-{{ option_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);			
								
				$('#option-name{{ option_id }}').html(name);
				$('#close-name-{{ option_id }}').trigger('click');
			}
		}
	});
}); 

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

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

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