<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">{{ product_name }} - {{ entry_store }}</h4>
</div>
<div class="modal-body">
  <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-product-store" class="form-horizontal">
    <div class="well well-sm" style="height: 200px; overflow: auto;">
	  {% for store in stores %}
        <div class="input-checkbox">
          <label class="label-store">
		    {% if store.store_id in product_store %}
              <input type="checkbox" class="checkbox" name="product_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="product_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>
  </form>
</div>
<div class="modal-footer">
  <div class="text-center"><a data-form="form-product-store" 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-product-store').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-product-store').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');				
									
				setTimeout(function(){
					$('#modal-product-edit').modal('hide');
				}, 1000)
			}
		}
	});
});   
//--></script>