<div class="modal-header">
  <button type="button" class="pull-right btn btn-danger btn-sm" data-dismiss="modal" aria-hidden="true"><i class="fa fa-close"></i></button>
  <h4 class="modal-title">{{ category_name }} - {{ text_stores }}</h4>
</div>
<div class="modal-body">
  <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-store-category" class="form-horizontal">
	<div class="form-group">
      <label class="col-sm-2 control-label">{{ entry_store }}</label>
      <div class="col-sm-10">
        <div class="well well-sm" style="height: 150px; overflow: auto;">
          {% for store in stores %}
			<div class="input-checkbox">
			  <label class="label-store">
				{% if store.store_id in category_store %}
				  <input type="checkbox" class="checkbox" name="category_store[]" value="{{ store.store_id }}" checked="checked" id="input-store{{ store.store_id }}" />
				  <label for="input-store{{ store.store_id }}"></label>
				  {% else %}
				  <input type="checkbox" class="checkbox" name="category_store[]" value="{{ store.store_id }}" id="input-store{{ store.store_id }}" />
				  <label for="input-store{{ store.store_id }}"></label>
				{% endif %}
				<span>{{ store.name }}</span>
			  </label>
			</div>
		  {% endfor %}
        </div>
      </div>
    </div>
	<div class="form-group">
      <label class="col-sm-2 control-label" for="input-column"><span data-toggle="tooltip" title="{{ help_column }}">{{ entry_column }}</span></label>
      <div class="col-sm-10">
        <input type="text" name="column" value="{{ column }}" placeholder="{{ entry_column }}" id="input-column" class="form-control" />
      </div>
    </div>
  </form>
</div>
<div class="modal-footer">
  <div class="text-center"><a data-form="form-store-category" class="button-save btn btn-primary"><i class="fa fa-save"></i> {{ button_save }}</a></div>
</div>
<script type="text/javascript"><!--
$(".button-save").on('click', function(){
	$.ajax({
		url: $('#' + $(this).data('form')).attr('action'),
		type: 'post',
		dataType: 'json',
		data: $('#' + $(this).data('form') + ' input[type=\'text\'], #' + $(this).data('form') + ' input[type=\'checkbox\']:checked'),
		success: function(json) {
			if (json['error']) {
				$('#form-store-category').before('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
				
				$('.alert-danger').delay(1500).fadeOut(500);
			}
									
			if (json['success']) {
				$('#form-store-category').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');				
									
				setTimeout(function(){
					$('#modal-category-edit').modal('hide');
				}, 1000)
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});   
//--></script>