Skip to content
Snippets Groups Projects
Commit 7517800a authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: Add cancel support to upload widget

parent 1a668998
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,12 @@ ...@@ -40,6 +40,12 @@
.filedrop .files .file .trash { .filedrop .files .file .trash {
cursor: pointer; cursor: pointer;
} }
.filedrop .progress {
margin-top: 5px;
}
.filedrop .cancel {
cursor: pointer;
}
/* Bootstrap 3.2 progress-bar */ /* Bootstrap 3.2 progress-bar */
@-webkit-keyframes progress-bar-stripes { @-webkit-keyframes progress-bar-stripes {
......
...@@ -49,9 +49,10 @@ ...@@ -49,9 +49,10 @@
} }
}); });
}, },
uploadStarted: function(i, file, n) { uploadStarted: function(i, file, n, xhr) {
var node = this.addNode(file).data('file', file); var node = this.addNode(file).data('file', file).data('xhr', xhr);
node.find('.trash').hide(); node.find('.trash').hide();
node.find('.cancel').show();
this.progressUpdated(i, file, 0); this.progressUpdated(i, file, 0);
}, },
uploadFinished: function(i, file, json, time, xhr) { uploadFinished: function(i, file, json, time, xhr) {
...@@ -67,6 +68,7 @@ ...@@ -67,6 +68,7 @@
.attr({'aria-valuenow': 100}) .attr({'aria-valuenow': 100})
e.find('.trash').show(); e.find('.trash').show();
e.find('.upload-rate').hide(); e.find('.upload-rate').hide();
e.find('.cancel').hide();
setTimeout(function() { e.find('.progress').hide(); }, 600); setTimeout(function() { e.find('.progress').hide(); }, 600);
return true; return true;
} }
...@@ -93,12 +95,21 @@ ...@@ -93,12 +95,21 @@
if (already_added) if (already_added)
return; return;
var filenode = $('<div class="file"></div>') var filenode = $('<div class="file"></div>');
filenode
.append($('<div class="filetype"></div>').addClass()) .append($('<div class="filetype"></div>').addClass())
.append($('<div class="filename"></div>') .append($('<div class="filename"></div>')
.append($('<span class="filesize"></span>').text( .append($('<span class="filesize"></span>').text(
this.fileSize(parseInt(file.size)) this.fileSize(parseInt(file.size))
)).append($('<div class="upload-rate pull-right"></div>')) ))
.append($('<div class="pull-right cancel"></div>')
.append($('<i class="icon-remove"></i>')
.attr('title', __('Cancel'))
)
.click($.proxy(this.cancelUpload, this, filenode))
.hide()
)
.append($('<div class="upload-rate pull-right"></div>'))
).append($('<div class="progress"></div>') ).append($('<div class="progress"></div>')
.append($('<div class="progress-bar"></div>')) .append($('<div class="progress-bar"></div>'))
.attr({'aria-valuemin':0,'aria-valuemax':100}) .attr({'aria-valuemin':0,'aria-valuemax':100})
...@@ -125,8 +136,14 @@ ...@@ -125,8 +136,14 @@
return filenode; return filenode;
}, },
deleteNode: function(filenode, e) { deleteNode: function(filenode, e) {
if (confirm(__('You sure?'))) if (!e || confirm(__('You sure?')))
filenode.remove(); filenode.remove();
},
cancelUpload: function(node) {
if (node.data('xhr')) {
node.data('xhr').abort();
return this.deleteNode(node, false);
}
} }
}; };
...@@ -557,7 +574,7 @@ ...@@ -557,7 +574,7 @@
global_progress[global_progress_index] = 0; global_progress[global_progress_index] = 0;
globalProgress(); globalProgress();
opts.uploadStarted(index, file, files_count); opts.uploadStarted(index, file, files_count, xhr);
xhr.onload = function() { xhr.onload = function() {
var serverResponse = null; var serverResponse = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment