Created
October 6, 2015 13:16
-
-
Save amitpatelx/75fcba98be3711d68de6 to your computer and use it in GitHub Desktop.
Dropzone with modal window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@document = current_user.client.documents.new(document_params.merge!({ user_id: current_user.id })) | |
if @document.save | |
# do some stuff | |
else | |
@errors = @document.errors.full_messages.to_sentence | |
end | |
respond_to do |format| | |
if @document.persisted? | |
format.json { render json: @document } | |
else | |
format.json { render json: @errors, status: :unprocessable_entity } | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#exampleModal.modal.fade{"aria-labelledby" => "exampleModalLabel", :role => "dialog", :tabindex => "-1"} | |
.modal-dialog{:role => "document"} | |
.modal-content | |
.modal-header | |
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"} | |
%span{"aria-hidden" => "true"} × | |
%h4#exampleModalLabel.modal-title Upload PDF | |
.modal-body | |
= form_for(current_user.client.documents.new, method: :post, html: { multipart: true, class: 'dropzone form', id: 'upload-pdf-dropzone' }) do |f| | |
.fallback | |
= f.file_field :pdf, accept: ['application/pdf'] | |
:javascript | |
$(function() { | |
var mediaDropzone; | |
var options = { paramName: 'document[pdf]', | |
acceptedFiles: 'application/pdf', | |
addRemoveLinks: true, | |
removedfile: function(file) { | |
var _ref; | |
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; | |
} | |
} | |
mediaDropzone = new Dropzone("#upload-pdf-dropzone", options); | |
mediaDropzone.on("complete", function(file) { | |
//mediaDropzone.removeFile(file); | |
//If all files uploaded | |
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) { | |
$('#exampleModal').modal('hide'); // hide modal window | |
window.location = '/'; // Go to home page | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment