Skip to content

Commit

Permalink
Add two changes:
Browse files Browse the repository at this point in the history
1. Add a new reset() method so the files uploaded can be removed from
the list when the upload is done.
2. Add a new option fireAtOnce (default false) which will submitt the
form at once when a file is dropped into the uploadarea.
  • Loading branch information
Tarjei Huse committed Mar 14, 2012
1 parent 9eb2879 commit 60b84d4
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Source/Form.Upload.js
Expand Up @@ -19,6 +19,7 @@ Form.Upload = new Class({

options: {
dropMsg: 'Please drop your files here',
fireAtOnce: false,
onComplete: function(){
// reload
window.location.href = window.location.href;
Expand Down Expand Up @@ -56,7 +57,11 @@ Form.Upload = new Class({
inputFiles = new Form.MultipleFileInput(input, list, drop, {
onDragenter: drop.addClass.pass('hover', drop),
onDragleave: drop.removeClass.pass('hover', drop),
onDrop: drop.removeClass.pass('hover', drop)
onDrop: function() {
drop.removeClass.pass('hover', drop);
if (self.options.fireAtOnce)
form.fireEvent("submit");
}
}),

uploadReq = new Request.File({
Expand All @@ -76,17 +81,26 @@ Form.Upload = new Class({
inputname = input.get('name');

form.addEvent('submit', function(event){
event.preventDefault();
if (event) {
event.preventDefault();
}
inputFiles.getFiles().each(function(file){
uploadReq.append(inputname , file);
});
uploadReq.send();
});

self.reset = function() {
var files = inputFiles.getFiles();
for (var i = 0; i < files.length; i++) {
inputFiles.remove(files[i]);
}
};
},

legacyUpload: function(input){

var rows = [];

var row = input.getParent('.formRow');
rowClone = row.clone(true, true),
add = function(event){
Expand All @@ -106,13 +120,21 @@ Form.Upload = new Class({

if (label) label.set('for', inputID);
newRow.inject(row, 'after');
rows.push(newRow);
};

new Element('a.addInputRow', {
text: '+',
events: {click: add}
}).inject(input, 'after');

this.reset = function() {
for (var i = 0; i < rows.length; i++) {
rows[i].destroy();
}
rows = [];
};

},

isModern: function(){
Expand Down

0 comments on commit 60b84d4

Please sign in to comment.