Dropzone.autoDiscover = false;
$(document).ready(function(){
  var DropZone = new Dropzone('#DropZone',{				
    maxFiles: 10,
    paramName: "Image", // The name that will be used to transfer the file
    maxFilesize: 2, // MB
    dictDefaultMessage: '<input type="button" value="SELECT FILES" class="fileInputBtn"/><p style="width:100%; padding:0; text-align:center;">Or Drag And Drop Files Here</p>',
    uploadMultiple: true,
    previewsContainer: ".dropzone-previews",
    createImageThumbnails: false,
    addRemoveLinks: false,
    autoProcessQueue: false,
    autoQueue: true,
    url: "includes/ajax/processing-scripts/gallery/process-gallery.php",
    acceptedFiles: "image/*",
    init: function() {
      this.on("addedfile", function(file) { 
        //do nothing
      });
      this.on("sending", function(file, xhr, formData){
        var now = new Date();
        if (document.getElementById('Admin_Form')) {
          var fields = document.getElementById('Admin_Form').elements;
          var field_name = '';
          var field_value = '';
          var field_type = '';
          var field_choice = '';
          for (var i = 0; i < fields.length; i++) {
            field_name = fields[i].name;
            field_type = fields[i].type;
            switch (field_type) {
              case "text":
                field_value = document.getElementById(field_name).value;               
                formData.append(field_name,field_value);
                break;              
              case 'textarea':
                field_value = document.getElementById(field_name).value;
                formData.append(field_name, field_value);				
              break;
              case 'select-one':
                field_choice = document.getElementById(field_name).selectedIndex;
                field_value = document.getElementById(field_name).options[field_choice].value;
                formData.append(field_name, field_value);
              break;
              case 'hidden':
                field_value = document.getElementById(field_name).value;
                formData.append(field_name, field_value);
              break;
            }
          }
        }
        formData.append('Now', now);
      });            
    },
    success: function (file, response) {  
      var cssClass = '';
      var msg = '';
      var status = '';
      var albumId = '';
      var categoryId = '';
      var albumName = '';
      var categoryName = '';
      if(document.getElementById('Animation')){
        document.getElementById('Animation').style.display = 'none';
      }    
      if(document.getElementById('Submit_Paragraph')){
            document.getElementById('Submit_Paragraph').style.display = 'block';
      }                   
      if(document.getElementById('Result')){ 
        let option = document.getElementById('Option').value;
        const result = JSON.parse(response);
        cssClass = result.Class;
        msg = result.Msg;
        status = result.Status;
        albumId = result.AlbumId;                        
        albumName = result.AlbumName;
        categoryId = result.CategoryId;
        categoryName = result.CategoryName;
        document.getElementById("Result").className = cssClass;
        document.getElementById("Result").innerHTML = msg;
        document.getElementById("Result").style.display = "block";
        if(status == 1){          
          if(document.getElementById('Album').value == 'New'){
            albumName = document.getElementById('Album_Name').value;                                         
            var albumMenu = document.getElementById('Album');
            var newOption = document.createElement('option');
            newOption.value = albumId;
            newOption.text = albumName;                                         
            albumMenu.appendChild(newOption);
            if($("#AlbumName")){
              $("#Album option[value='"+albumId+"']").attr('selected',true);                                         
              $("#AlbumName").css("display","none");
            }
          }
        }                                                                                                                                                                                                                              
        clearImageForm('Admin_Form');
        this.removeAllFiles();        
      }
    }
  });					
});          