@model Web.Models.DodaciList.DodaciListModel
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog">
    <div class="modal-conten">
      <form>
        <div action="~/DodaciList/SaveUploadedFile" method="post" class="dropzone" id="dropzoneForm"></div>
      </form>
    </div>
    <button id="stred" class="btn btn-primary col-md-2" onclick="redirect()"> Potvrď </button>

  </div>

</div>

<style>
  .modal-dialog {
    transform: translate(0,80%) !important;
    -ms-transform: translate(0,80%) !important;
    -webkit-transform: translate(0,80%) !important;
  }

  .RbtnMargin {
    margin-left: 90px;
  }
</style>

<script>
  $(document).ready(function () {
    $("#myModal").modal({
      backdrop: 'static'
    });

  });
  function redirect() {
    window.location.href = '@Url.Action("Detail", "DodaciList", new { id = @Model.Id })';
  }
  Dropzone.autoDiscover = false;

  Dropzone.options.dropzoneForm = {
    maxFiles: 2,
    maxFilesize: 5,
    dictDefaultMessage: "Faktury nahrajte zde",
    init: function () {

      this.on("addedfile", function (file) {
        // Create the remove button
        var odstranitTlacitko = Dropzone.createElement("<a class=\"dz-remove\">Remove file</a>");
        // Capture the Dropzone instance as closure.
        var _this = this;
        // Listen to the click event
        odstranitTlacitko.addEventListener("click", function (e) {
          e.preventDefault();
          e.stopPropagation();
          // Remove the file preview.
          _this.removeFile(file);
          // If you want to the delete the file on the server as well,
          // you can do the AJAX request here.
        });
        // Add the button to the file preview element.
        file.previewElement.appendChild(odstranitTlacitko);
        
        var stahnoutTlacitko = Dropzone.createElement("<a class=\"dz-remove\">Download file</a>");
        // Capture the Dropzone instance as closure.
        var _this = this;
        // Listen to the click event
        var tdata = { id: file.id };
        stahnoutTlacitko.addEventListener("click", function (e) {
          window.location.href = '@Url.Action("StahnoutFakturu", "DodaciList")'+'/'+file.id;
        });
        // Add the button to the file preview element.
        file.previewElement.appendChild(stahnoutTlacitko);
        $(".dz-progress").remove();

      });
    }
  };

  var myDropzone = new Dropzone("#dropzoneForm");
  Dropzone.options.myDropzone = {
    maxFiles: 2,
    maxFilesize: 5,
    dictDefaultMessage: "Faktury nahrajte zde",

  };

  myDropzone.on("addedfile", function(file) {
    /* Maybe display some more file information on your page */
  });

  $.getJSON("/DodaciList/NactiFaktury/@Model.Id").done(function (data) {
    if (data != '') {
      $.each(data, function (index, item) {
        // Create the mock file:
        var mockFile = {
          name: item.NazevSouboru,
          size: item.Obsah.length,
          id: item.Id
        };

        // Call the default addedfile event handler
        myDropzone.files.push(mockFile);
        myDropzone.emit('addedfile', mockFile);

        var existingFileCount = 1;
        myDropzone.options.maxFiles = myDropzone.options.maxFiles - existingFileCount;

      });
    }
  });


</script>
