Advertisement
guiil

upload.js

Feb 22nd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).on('ready page:load', function () { new Dropzone("#dropzone", {
  2.       autoProcessQueue: false,
  3.       uploadMultiple: true,
  4.       parallelUploads: 100,
  5.       addRemoveLinks: true,
  6.       maxFiles: 10,
  7.       maxFilesize: 10,
  8.       paramName: 'upload[document]',
  9.       init: function() {
  10.         var myDropzone = this;
  11.         // First change the button to actually tell Dropzone to process the queue.
  12.         $("#dropzone").submit(function(e) {
  13.           // Make sure that the form isn't actually being sent.
  14.           e.preventDefault();
  15.           e.stopPropagation();
  16.           myDropzone.processQueue();
  17.  
  18.         });
  19.       },
  20.       sendingMultiple: function(){
  21.           // Gets triggered when the form is actually being sent.
  22.           // Hide the success button or the complete form.
  23.       },
  24.       successmultiple: function(files, response) {
  25.           $(files.previewElement).find('.dz-remove').attr('id', response.uploadId);
  26.           $(files.previewElement).addClass('dz-success');
  27.       },
  28.       errormultiple: function(files, response) {
  29.           // Gets triggered when there was an error sending the files.
  30.           // Maybe show form again, and notify user of error
  31.       },
  32.  
  33.       removedfile: function(file) {
  34.         var id = $(file.previewTemplate).find('.dz-remove').attr('id');
  35.  
  36.         $.ajax({
  37.           type: 'DELETE',
  38.           url: '/uploads/' + id,
  39.           success: function(data) {
  40.             console.log(data.message);
  41.           }
  42.         });
  43.  
  44.         var previewElement;
  45.         return (previewElement = file.previewElement) != null ? (previewElement.parentNode.removeChild(file.previewElement)) : (void 0);
  46.       }
  47.     });
  48.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement