Skip to content

Commit

Permalink
Use File.webkitRelativePath over .name when we can
Browse files Browse the repository at this point in the history
Bump version to 0.0.7
  • Loading branch information
adamhooper committed Jul 14, 2014
1 parent 6671e02 commit 171b205
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 75 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-mass-upload",
"version": "0.0.6",
"version": "0.0.7",
"main": "mass-upload.js",
"ignore": [
"**/.*",
Expand Down
30 changes: 19 additions & 11 deletions dist/mass-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ define('MassUpload/FileInfo',[],function() {
return new FileInfo(obj.name, new Date(obj.lastModifiedDate), obj.total, obj.loaded);
};
FileInfo.fromFile = function(obj) {
return new FileInfo(obj.name, obj.lastModifiedDate, obj.size, 0);
return new FileInfo(obj.webkitRelativePath || obj.name, obj.lastModifiedDate, obj.size, 0);
};
return FileInfo;
});

define('MassUpload/Upload',['backbone', './FileInfo'], function(Backbone, FileInfo) {
define('MassUpload/Upload',['underscore', 'backbone', './FileInfo'], function(_, Backbone, FileInfo) {
var Upload;
return Upload = (function() {
Upload.prototype = Object.create(Backbone.Events);
Expand All @@ -35,13 +35,13 @@ define('MassUpload/Upload',['backbone', './FileInfo'], function(Backbone, FileIn
};

function Upload(attributes) {
var _ref, _ref1, _ref2, _ref3;
var _ref, _ref1, _ref2;
this.file = (_ref = attributes.file) != null ? _ref : null;
this.fileInfo = (_ref1 = attributes.fileInfo) != null ? _ref1 : null;
this.error = (_ref2 = attributes.error) != null ? _ref2 : null;
this.uploading = attributes.uploading || false;
this.deleting = attributes.deleting || false;
this.id = ((_ref3 = this.fileInfo) != null ? _ref3 : this.file).name;
this.id = this.file != null ? this.file.webkitRelativePath || this.file.name : this.fileInfo.name;
this.attributes = this;
}

Expand Down Expand Up @@ -246,6 +246,14 @@ define('MassUpload/UploadCollection',['backbone', './Upload'], function(Backbone
return (_ref = this._idToModel[id]) != null ? _ref : null;
};

UploadCollection.prototype.forFile = function(file) {
return this.get(file.webkitRelativePath || file.name);
};

UploadCollection.prototype.forFileInfo = function(fileInfo) {
return this.get(fileInfo.name);
};

UploadCollection.prototype.addFiles = function(files) {
var file, uploads;
uploads = (function() {
Expand Down Expand Up @@ -929,7 +937,7 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onUploaderStart = function(file) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.set({
uploading: true,
error: null
Expand All @@ -938,7 +946,7 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onUploaderStop = function(file) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
upload.set({
uploading: false
});
Expand All @@ -947,21 +955,21 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onUploaderProgress = function(file, progressEvent) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.updateWithProgress(progressEvent);
};

MassUpload.prototype._onUploaderError = function(file, errorDetail) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.set({
error: errorDetail
});
};

MassUpload.prototype._onUploaderSuccess = function(file) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.updateWithProgress({
loaded: upload.size(),
total: upload.size()
Expand All @@ -976,13 +984,13 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onDeleterSuccess = function(fileInfo) {
var upload;
upload = this.uploads.get(fileInfo.name);
upload = this.uploads.forFileInfo(fileInfo);
return this.uploads.remove(upload);
};

MassUpload.prototype._onDeleterError = function(fileInfo, errorDetail) {
var upload;
upload = this.uploads.get(fileInfo.name);
upload = this.uploads.forFileInfo(fileInfo);
return upload.set({
error: errorDetail
});
Expand Down
2 changes: 1 addition & 1 deletion dist/mass-upload.min.js

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions dist/mass-upload.no-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,12 @@ define('MassUpload/FileInfo',[],function() {
return new FileInfo(obj.name, new Date(obj.lastModifiedDate), obj.total, obj.loaded);
};
FileInfo.fromFile = function(obj) {
return new FileInfo(obj.name, obj.lastModifiedDate, obj.size, 0);
return new FileInfo(obj.webkitRelativePath || obj.name, obj.lastModifiedDate, obj.size, 0);
};
return FileInfo;
});

define('MassUpload/Upload',['backbone', './FileInfo'], function(Backbone, FileInfo) {
define('MassUpload/Upload',['underscore', 'backbone', './FileInfo'], function(_, Backbone, FileInfo) {
var Upload;
return Upload = (function() {
Upload.prototype = Object.create(Backbone.Events);
Expand All @@ -459,13 +459,13 @@ define('MassUpload/Upload',['backbone', './FileInfo'], function(Backbone, FileIn
};

function Upload(attributes) {
var _ref, _ref1, _ref2, _ref3;
var _ref, _ref1, _ref2;
this.file = (_ref = attributes.file) != null ? _ref : null;
this.fileInfo = (_ref1 = attributes.fileInfo) != null ? _ref1 : null;
this.error = (_ref2 = attributes.error) != null ? _ref2 : null;
this.uploading = attributes.uploading || false;
this.deleting = attributes.deleting || false;
this.id = ((_ref3 = this.fileInfo) != null ? _ref3 : this.file).name;
this.id = this.file != null ? this.file.webkitRelativePath || this.file.name : this.fileInfo.name;
this.attributes = this;
}

Expand Down Expand Up @@ -670,6 +670,14 @@ define('MassUpload/UploadCollection',['backbone', './Upload'], function(Backbone
return (_ref = this._idToModel[id]) != null ? _ref : null;
};

UploadCollection.prototype.forFile = function(file) {
return this.get(file.webkitRelativePath || file.name);
};

UploadCollection.prototype.forFileInfo = function(fileInfo) {
return this.get(fileInfo.name);
};

UploadCollection.prototype.addFiles = function(files) {
var file, uploads;
uploads = (function() {
Expand Down Expand Up @@ -1353,7 +1361,7 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onUploaderStart = function(file) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.set({
uploading: true,
error: null
Expand All @@ -1362,7 +1370,7 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onUploaderStop = function(file) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
upload.set({
uploading: false
});
Expand All @@ -1371,21 +1379,21 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onUploaderProgress = function(file, progressEvent) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.updateWithProgress(progressEvent);
};

MassUpload.prototype._onUploaderError = function(file, errorDetail) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.set({
error: errorDetail
});
};

MassUpload.prototype._onUploaderSuccess = function(file) {
var upload;
upload = this.uploads.get(file.name);
upload = this.uploads.forFile(file);
return upload.updateWithProgress({
loaded: upload.size(),
total: upload.size()
Expand All @@ -1400,13 +1408,13 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M

MassUpload.prototype._onDeleterSuccess = function(fileInfo) {
var upload;
upload = this.uploads.get(fileInfo.name);
upload = this.uploads.forFileInfo(fileInfo);
return this.uploads.remove(upload);
};

MassUpload.prototype._onDeleterError = function(fileInfo, errorDetail) {
var upload;
upload = this.uploads.get(fileInfo.name);
upload = this.uploads.forFileInfo(fileInfo);
return upload.set({
error: errorDetail
});
Expand Down
2 changes: 1 addition & 1 deletion dist/mass-upload.no-require.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-mass-upload",
"version": "0.0.6",
"version": "0.0.7",
"description": "Create upload UIs for thousands of files and gigabytes of data",
"scripts": {},
"repository": {
Expand Down
14 changes: 7 additions & 7 deletions src/coffee/MassUpload.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -228,38 +228,38 @@ define [
@_tick()

_onUploaderStart: (file) ->
upload = @uploads.get(file.name)
upload = @uploads.forFile(file)
upload.set
uploading: true
error: null

_onUploaderStop: (file) ->
upload = @uploads.get(file.name)
upload = @uploads.forFile(file)
upload.set(uploading: false)
@_tick()

_onUploaderProgress: (file, progressEvent) ->
upload = @uploads.get(file.name)
upload = @uploads.forFile(file)
upload.updateWithProgress(progressEvent)

_onUploaderError: (file, errorDetail) ->
upload = @uploads.get(file.name)
upload = @uploads.forFile(file)
upload.set(error: errorDetail)

_onUploaderSuccess: (file) ->
upload = @uploads.get(file.name)
upload = @uploads.forFile(file)
upload.updateWithProgress({ loaded: upload.size(), total: upload.size() })
# onUploaderDone sets uploading=false

_onDeleterStart: (fileInfo) ->
@set(status: 'uploading')

_onDeleterSuccess: (fileInfo) ->
upload = @uploads.get(fileInfo.name)
upload = @uploads.forFileInfo(fileInfo)
@uploads.remove(upload)

_onDeleterError: (fileInfo, errorDetail) ->
upload = @uploads.get(fileInfo.name)
upload = @uploads.forFileInfo(fileInfo)
upload.set(error: errorDetail)

_onDeleterStop: (fileInfo) ->
Expand Down
2 changes: 1 addition & 1 deletion src/coffee/MassUpload/FileInfo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define ->

FileInfo.fromFile = (obj) ->
new FileInfo(
obj.name,
obj.webkitRelativePath || obj.name,
obj.lastModifiedDate,
obj.size,
0
Expand Down
7 changes: 5 additions & 2 deletions src/coffee/MassUpload/Upload.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define [ 'backbone', './FileInfo' ], (Backbone, FileInfo) ->
define [ 'underscore', 'backbone', './FileInfo' ], (_, Backbone, FileInfo) ->
# Represents an upload of a local file to the server.
#
# This can have several states:
Expand Down Expand Up @@ -42,7 +42,10 @@ define [ 'backbone', './FileInfo' ], (Backbone, FileInfo) ->
@error = attributes.error ? null
@uploading = attributes.uploading || false
@deleting = attributes.deleting || false
@id = (@fileInfo ? @file).name
@id = if @file?
@file.webkitRelativePath || @file.name
else
@fileInfo.name

# Backbone.Model compatibility
@attributes = this
Expand Down
3 changes: 3 additions & 0 deletions src/coffee/MassUpload/UploadCollection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ define [ 'backbone', './Upload' ], (Backbone, Upload) ->
get: (id) ->
@_idToModel[id] ? null

forFile: (file) -> @get(file.webkitRelativePath || file.name)
forFileInfo: (fileInfo) -> @get(fileInfo.name)

# Adds some user-selected files to the collection.
#
# Files of the same name will be matched up to their server-side fileInfo
Expand Down
24 changes: 12 additions & 12 deletions src/coffee/MassUpload/views/UploadCollection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ define [ 'backbone', 'underscore', './humanReadableSize' ], (Backbone, _, humanR
""")

uploadTemplate: _.template("""
<li class="<%= status %>" data-cid="<%- upload.cid %>">
<li class="<%= status %>" data-id="<%- upload.id %>">
<a href="#" class="delete">Delete</a>
<a href="#" class="retry">Retry</a>
<h3><%- upload.id %></h3>
Expand Down Expand Up @@ -102,7 +102,7 @@ define [ 'backbone', 'underscore', './humanReadableSize' ], (Backbone, _, humanR
_onAdd: (upload, collection, options) ->
html = @_renderUpload(upload)
$li = Backbone.$(html)
@els[upload.cid] = liToEls($li)
@els[upload.id] = liToEls($li)

lis = @ul.childNodes

Expand All @@ -117,18 +117,18 @@ define [ 'backbone', 'underscore', './humanReadableSize' ], (Backbone, _, humanR
undefined

_onRemove: (upload) ->
cid = upload.cid
els = @els[cid]
id = upload.id
els = @els[id]
throw 'Element does not exist' if !els?

@ul.removeChild(els.li)
delete @els[cid]
delete @els[id]

undefined

_onChange: (upload) ->
cid = upload.cid
els = @els[cid]
id = upload.id
els = @els[id]

if els?
progress = upload.getProgress()
Expand All @@ -150,10 +150,10 @@ define [ 'backbone', 'underscore', './humanReadableSize' ], (Backbone, _, humanR
@$el.html(html)
@ul = @$el.children('ul.uploads')[0]

els = @els = {} # hash of cid to { li, progress, text, size, message }
els = @els = {} # hash of id to { li, progress, text, size, message }
@$el.find('ul.uploads>li').each (li) ->
cid = li.getAttribute('data-cid')
els[cid] = liToEls(li)
id = li.getAttribute('data-id')
els[id] = liToEls(li)

this

Expand All @@ -167,8 +167,8 @@ define [ 'backbone', 'underscore', './humanReadableSize' ], (Backbone, _, humanR
@trigger('add-files', files)

_eventToUpload: (e) ->
cid = Backbone.$(e.target).closest('[data-cid]').attr('data-cid')
@collection.get(cid)
id = Backbone.$(e.target).closest('[data-id]').attr('data-id')
@collection.get(id)

_onRetry: (e) ->
e.preventDefault()
Expand Down
Loading

0 comments on commit 171b205

Please sign in to comment.