summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob/blob_file_dropzone.js
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
committerFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
commitaaa9509d120524573085e94af9de5cdde83e3271 (patch)
tree3824cffd4cdd132ee9cf75a00a7624f5ccc0dabd /app/assets/javascripts/blob/blob_file_dropzone.js
parent56b79181adc0bd6e9abef97ea075c14be971a01a (diff)
downloadgitlab-ce-aaa9509d120524573085e94af9de5cdde83e3271.tar.gz
ES6ify all the things!
Diffstat (limited to 'app/assets/javascripts/blob/blob_file_dropzone.js')
-rw-r--r--app/assets/javascripts/blob/blob_file_dropzone.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/app/assets/javascripts/blob/blob_file_dropzone.js b/app/assets/javascripts/blob/blob_file_dropzone.js
new file mode 100644
index 00000000000..f4044f22db2
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_file_dropzone.js
@@ -0,0 +1,62 @@
+(function() {
+ this.BlobFileDropzone = (function() {
+ function BlobFileDropzone(form, method) {
+ var dropzone, form_dropzone, submitButton;
+ form_dropzone = form.find('.dropzone');
+ Dropzone.autoDiscover = false;
+ dropzone = form_dropzone.dropzone({
+ autoDiscover: false,
+ autoProcessQueue: false,
+ url: form.attr('action'),
+ method: method,
+ clickable: true,
+ uploadMultiple: false,
+ paramName: "file",
+ maxFilesize: gon.max_file_size || 10,
+ parallelUploads: 1,
+ maxFiles: 1,
+ addRemoveLinks: true,
+ previewsContainer: '.dropzone-previews',
+ headers: {
+ "X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content")
+ },
+ init: function() {
+ this.on('addedfile', function(file) {
+ $('.dropzone-alerts').html('').hide();
+ });
+ this.on('success', function(header, response) {
+ window.location.href = response.filePath;
+ });
+ this.on('maxfilesexceeded', function(file) {
+ this.removeFile(file);
+ });
+ return this.on('sending', function(file, xhr, formData) {
+ formData.append('target_branch', form.find('.js-target-branch').val());
+ formData.append('create_merge_request', form.find('.js-create-merge-request').val());
+ formData.append('commit_message', form.find('.js-commit-message').val());
+ });
+ },
+ error: function(file, errorMessage) {
+ var stripped;
+ stripped = $("<div/>").html(errorMessage).text();
+ $('.dropzone-alerts').html('Error uploading file: \"' + stripped + '\"').show();
+ this.removeFile(file);
+ }
+ });
+ submitButton = form.find('#submit-all')[0];
+ submitButton.addEventListener('click', function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ if (dropzone[0].dropzone.getQueuedFiles().length === 0) {
+ alert("Please select a file");
+ }
+ dropzone[0].dropzone.processQueue();
+ return false;
+ });
+ }
+
+ return BlobFileDropzone;
+
+ })();
+
+}).call(this);