diff --git a/bower.json b/bower.json index 9d2a1b5..baea417 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "js-mass-upload", - "version": "0.0.6", + "version": "0.0.7", "main": "mass-upload.js", "ignore": [ "**/.*", diff --git a/dist/mass-upload.js b/dist/mass-upload.js index 60894d3..0405f0e 100644 --- a/dist/mass-upload.js +++ b/dist/mass-upload.js @@ -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); @@ -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; } @@ -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() { @@ -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 @@ -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 }); @@ -947,13 +955,13 @@ 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 }); @@ -961,7 +969,7 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M 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() @@ -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 }); diff --git a/dist/mass-upload.min.js b/dist/mass-upload.min.js index fdd267a..4a49869 100644 --- a/dist/mass-upload.min.js +++ b/dist/mass-upload.min.js @@ -1 +1 @@ -define("MassUpload/FileInfo",[],function(){var t;return t=function(){function t(t,o,e,r){this.name=t,this.lastModifiedDate=o,this.total=e,this.loaded=r}return t}(),t.fromJson=function(o){return new t(o.name,new Date(o.lastModifiedDate),o.total,o.loaded)},t.fromFile=function(o){return new t(o.name,o.lastModifiedDate,o.size,0)},t}),define("MassUpload/Upload",["backbone","./FileInfo"],function(t,o){var e;return e=function(){function e(t){var o,e,r,n;this.file=null!=(o=t.file)?o:null,this.fileInfo=null!=(e=t.fileInfo)?e:null,this.error=null!=(r=t.error)?r:null,this.uploading=t.uploading||!1,this.deleting=t.deleting||!1,this.id=(null!=(n=this.fileInfo)?n:this.file).name,this.attributes=this}return e.prototype=Object.create(t.Events),e.prototype.defaults={file:null,fileInfo:null,error:null,uploading:!1,deleting:!1},e.prototype.get=function(t){return this[t]},e.prototype.set=function(t){var o,r;this._previousAttributes=new e(this);for(o in t)r=t[o],this[o]=r;return this.trigger("change",this),this._previousAttributes=null},e.prototype.previousAttributes=function(){return this._previousAttributes},e.prototype.size=function(){var t;return null!=this._size?this._size:this._size=null!=(t=this.file)?t.size:void 0},e.prototype.lastModifiedDate=function(){var t;return null!=this._lastModifiedDate?this._lastModifiedDate:this._lastModifiedDate=null!=(t=this.file)?t.lastModifiedDate:void 0},e.prototype.updateWithProgress=function(t){var e;return e=new o(this.id,this.lastModifiedDate(),t.total,t.loaded),this.set({fileInfo:e})},e.prototype.getProgress=function(){return null==this.fileInfo||this.hasConflict()?null!=this.file?{loaded:0,total:this.size()}:void 0:{loaded:this.fileInfo.loaded,total:this.fileInfo.total}},e.prototype.isFullyUploaded=function(){return null!=this.fileInfo&&null==this.error&&!this.uploading&&!this.deleting&&this.fileInfo.loaded===this.fileInfo.total},e.prototype.hasConflict=function(){return null!=this.fileInfo&&null!=this.file&&(this.fileInfo.name!==this.id||this.fileInfo.total!==this.size()||this.fileInfo.lastModifiedDate.getTime()!==this.lastModifiedDate().getTime())},e}()}),define("MassUpload/UploadCollection",["backbone","./Upload"],function(t,o){var e,r;return r=function(){function t(){this._clear()}return t.prototype._clear=function(){return this.deleting=[],this.uploading=[],this.unfinished=[],this.unstarted=[]},t.prototype.uploadAttributesToState=function(t){var o;return o=null!=t.error?null:t.deleting?"deleting":t.uploading?"uploading":null!=t.file&&null!=t.fileInfo&&t.fileInfo.loadedr;r++)e=t[r],o=this.uploadAttributesToState(e.attributes),null!=o&&this[o].push(e);return void 0},t.prototype._removeUploadFromArray=function(t,o){var e;return e=o.indexOf(t),e>=0?o.splice(e,1):void 0},t.prototype.remove=function(t){var o;return o=this.uploadAttributesToState(t.attributes),null!=o?this._removeUploadFromArray(t.attributes,this[o]):void 0},t.prototype.change=function(t){var o,e;return e=this.uploadAttributesToState(t.previousAttributes()),o=this.uploadAttributesToState(t.attributes),e!==o&&(null!=e&&this._removeUploadFromArray(t,this[e]),null!=o)?this[o].push(t):void 0},t.prototype.reset=function(t){return null==t&&(t=[]),this._clear(),this.addBatch(t)},t.prototype.next=function(){var t,o,e,r;return null!=(t=null!=(o=null!=(e=null!=(r=this.deleting[0])?r:this.uploading[0])?e:this.unfinished[0])?o:this.unstarted[0])?t:null},t}(),e=function(){function e(){this.models=[],this._priorityQueue=new r,this.reset([])}return e.prototype=Object.create(t.Events),e.prototype.each=function(t,o){return this.models.forEach(t,o)},e.prototype.map=function(t,o){return this.models.map(t,o)},e.prototype._prepareModel=function(t){return t instanceof o?t:new o(t)},e.prototype.reset=function(t){var o,e,r,n,i,s,l;for(s=this.models,e=0,n=s.length;n>e;e++)o=s[e],o.off("all",this._onUploadEvent,this);for(this.models=function(){var e,r,n,i;for(n=null!=t?t:[],i=[],e=0,r=n.length;r>e;e++)o=n[e],i.push(this._prepareModel(o));return i}.call(this),this.length=this.models.length,this._idToModel={},l=this.models,r=0,i=l.length;i>r;r++)o=l[r],o.on("all",this._onUploadEvent,this),this._idToModel[o.id]=o;return this._priorityQueue.reset(this.models),this.trigger("reset",this)},e.prototype.get=function(t){var o;return null!=(o=this._idToModel[t])?o:null},e.prototype.addFiles=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({file:e}));return i}(),this._addWithMerge(r)},e.prototype.addFileInfos=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({fileInfo:e}));return i}(),this._addWithMerge(r)},e.prototype.next=function(){return this._priorityQueue.next()},e.prototype.add=function(t){return null!=t.length?this.addBatch(t):this.addBatch([t])},e.prototype.addBatch=function(t){var o,e,r,n,i;for(e=0,n=t.length;n>e;e++)o=t[e],this._idToModel[o.id]=o,o.on("all",this._onUploadEvent,this),this.models.push(o);for(this.length+=t.length,this._priorityQueue.addBatch(t),r=0,i=t.length;i>r;r++)o=t[r],this.trigger("add",o);return this.trigger("add-batch",t)},e.prototype._onUploadEvent=function(t,o){return"add"!==t&&"remove"!==t&&this.trigger.apply(this,arguments),"change"===t?this._priorityQueue.change(o):void 0},e.prototype._addWithMerge=function(t){var o,e,r,n,i,s,l;for(n=[],s=0,l=t.length;l>s;s++)i=t[s],null!=(o=this.get(i.id))?(e=i.get("file"),r=i.get("fileInfo"),null!=e&&o.set({file:e}),null!=r&&o.set({fileInfo:r})):n.push(i);return n.length&&this.add(n),void 0},e}()}),define("MassUpload/FileLister",[],function(){var t;return t=function(){function t(t,o){this.doListFiles=t,this.callbacks=o,this.running=!1}return t.prototype.run=function(){var t,o=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(t=this.callbacks).onStart&&t.onStart(),this.doListFiles(function(t){var e;return"function"==typeof(e=o.callbacks).onProgress?e.onProgress(t):void 0},function(t){return o._onSuccess(t)},function(t){return o._onError(t)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop()},t.prototype._onError=function(t){return this.callbacks.onError(t),this._onStop()},t.prototype._onStop=function(){var t;return this.running=!1,"function"==typeof(t=this.callbacks).onStop?t.onStop():void 0},t}()}),define("MassUpload/FileUploader",["./FileInfo"],function(){var t;return t=function(){function t(t,o){this.doUpload=t,this.callbacks=o,this._file=null,this._abortCallback=null,this._aborting=!1}return t.prototype.run=function(t){var o,e=this;if(null!=this._file)throw"already running";return this._file=t,"function"==typeof(o=this.callbacks).onStart&&o.onStart(this._file),this._abortCallback=this.doUpload(t,function(o){return e._onProgress(t,o)},function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype.abort=function(){return this._file&&!this._aborting&&(this._aborting=!0,"function"==typeof this._abortCallback)?this._abortCallback():void 0},t.prototype._onProgress=function(t,o){var e;return"function"==typeof(e=this.callbacks).onProgress?e.onProgress(t,o):void 0},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this._file=null,this._abortCallback=null,this._aborting=!1,"function"==typeof(o=this.callbacks).onStop?o.onStop(t):void 0},t}()}),define("MassUpload/FileDeleter",[],function(){var t;return t=function(){function t(t,o){this.doDeleteFile=t,this.callbacks=null!=o?o:{},this.running=!1}return t.prototype.run=function(t){var o,e=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(o=this.callbacks).onStart&&o.onStart(t),this.doDeleteFile(t,function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this.running=!1,"function"==typeof(o=this.callbacks).onStop&&o.onStop(t),void 0},t}()}),define("MassUpload/State",[],function(){var t;return t=function(){function t(t){var o,e,r,n;null==t&&(t={}),this.loaded=null!=(o=t.loaded)?o:0,this.total=null!=(e=t.total)?e:0,this.status=null!=(r=t.status)?r:"waiting",this.errors=null!=(n=t.errors)?n:[]}return t.prototype._extend=function(o){var e,r,n,i;return new t({loaded:null!=(e=o.loaded)?e:this.loaded,total:null!=(r=o.total)?r:this.total,status:null!=(n=o.status)?n:this.status,errors:null!=(i=o.errors)?i:this.errors})},t.prototype.isComplete=function(){return this.total&&this.loaded===this.total&&"waiting"===this.status&&!this.errors.length&&!0||!1},t.prototype.withTotal=function(t){return this._extend({total:t})},t.prototype.withLoaded=function(t){return this._extend({loaded:t})},t.prototype.withStatus=function(t){return this._extend({status:t})},t.prototype.withAnError=function(t){var o;return o=this.errors.slice(0),o.push(t),this._extend({errors:o})},t.prototype.withoutAnError=function(t){var o,e;return e=this.errors.slice(0),o=e.indexOf(t),e.splice(o,1),this._extend({errors:e})},t}()}),define("MassUpload/UploadProgress",["backbone"],function(t){return t.Model.extend({defaults:{loaded:0,total:0},initialize:function(){var t;if(t=this.get("uploadCollection"),null==t)throw"Must initialize UploadProgress with `uploadCollection`, an UploadCollection";return this._idToLastKnownProgress={},this._updateAndStartListening()},_adjust:function(t,o){return this.set({loaded:this.get("loaded")+t,total:this.get("total")+o})},add:function(t){var o;return o=t.getProgress(),this._adjust(o.loaded,o.total),this._idToLastKnownProgress[t.id]=o},reset:function(t){var o,e,r,n,i,s,l,u;for(o=this._idToLastKnownProgress={},e=0,i=0,u=t.models,s=0,l=u.length;l>s;s++)r=u[s],n=r.getProgress(),o[r.id]=n,e+=n.loaded,i+=n.total;return this.set({loaded:e,total:i})},remove:function(t){var o;return o=t.getProgress(),this._adjust(-o.loaded,-o.total),this._idToLastKnownProgress[t.id]=o},change:function(t){var o,e;return e=this._idToLastKnownProgress[t.id],null!=e?(o=t.getProgress(),this._adjust(o.loaded-e.loaded,o.total-e.total),this._idToLastKnownProgress[t.id]=o):void 0},_updateAndStartListening:function(){var t,o,e,r,n;for(t=this.get("uploadCollection"),n=["add","remove","change","reset"],e=0,r=n.length;r>e;e++)o=n[e],this.listenTo(t,o,this[o]);return this.reset(t),void 0},inBatch:function(t){this.stopListening(this.get("uploadCollection"));try{return t()}finally{this._updateAndStartListening()}}})});var __hasProp={}.hasOwnProperty,__extends=function(t,o){function e(){this.constructor=t}for(var r in o)__hasProp.call(o,r)&&(t[r]=o[r]);return e.prototype=o.prototype,t.prototype=new e,t.__super__=o.prototype,t};define("MassUpload",["backbone","underscore","MassUpload/UploadCollection","MassUpload/FileLister","MassUpload/FileUploader","MassUpload/FileDeleter","MassUpload/State","MassUpload/UploadProgress"],function(t,o,e,r,n,i,s,l){var u;return u=function(t){function s(t){this._removedUploads=[],s.__super__.constructor.call(this,{},t)}return __extends(s,t),s.prototype.defaults=function(){return{status:"waiting",listFilesProgress:null,listFilesError:null,uploadProgress:null,uploadErrors:[]}},s.prototype.initialize=function(t,o){var r,n,i=this;return this._options=o,this.uploads=null!=(n=null!=o?o.uploads:void 0)?n:new e,this._uploadProgress=new l({uploadCollection:this.uploads}),r=function(){return i.set({uploadProgress:i._uploadProgress.pick("loaded","total")})},this.listenTo(this._uploadProgress,"change",r),r(),this.listenTo(this.uploads,"add-batch",this._onUploadBatchAdded),this.listenTo(this.uploads,"change",function(t){return i._onUploadChanged(t)}),this.listenTo(this.uploads,"reset",function(){return i._onUploadsReset()}),this.prepare()},s.prototype.prepare=function(){var t,o,e,s,l=this;return t=this._options,this.lister=null!=(o=null!=t?t.lister:void 0)?o:new r(t.doListFiles),this.lister.callbacks={onStart:function(){return l._onListerStart()},onProgress:function(t){return l._onListerProgress(t)},onSuccess:function(t){return l._onListerSuccess(t)},onError:function(t){return l._onListerError(t)},onStop:function(){return l._onListerStop()}},this.uploader=null!=(e=null!=t?t.uploader:void 0)?e:new n(t.doUploadFile),this.uploader.callbacks={onStart:function(t){return l._onUploaderStart(t)},onStop:function(t){return l._onUploaderStop(t)},onSuccess:function(t){return l._onUploaderSuccess(t)},onError:function(t,o){return l._onUploaderError(t,o)},onProgress:function(t,o){return l._onUploaderProgress(t,o)}},this.deleter=null!=(s=null!=t?t.deleter:void 0)?s:new i(t.doDeleteFile),this.deleter.callbacks={onStart:function(t){return l._onDeleterStart(t)},onSuccess:function(t){return l._onDeleterSuccess(t)},onError:function(t,o){return l._onDeleterError(t,o)},onStop:function(t){return l._onDeleterStop(t)}}},s.prototype.fetchFileInfosFromServer=function(){return this.lister.run()},s.prototype.retryListFiles=function(){return this.fetchFileInfosFromServer()},s.prototype.retryUpload=function(t){return t.set({error:null})},s.prototype.retryAllUploads=function(){return this.uploads.each(function(t){return t.set({error:null})})},s.prototype.addFiles=function(t){var o=this;return this._uploadProgress.inBatch(function(){return o.uploads.addFiles(t)})},s.prototype.removeUpload=function(t){return t.set({deleting:!0})},s.prototype.abort=function(){var t=this;return this.uploads.each(function(o){return t.removeUpload(o)}),this.uploads.reset(),this.prepare()},s.prototype._onListerStart=function(){return this.set({status:"listing-files",listFilesError:null})},s.prototype._onListerProgress=function(t){return this.set({listFilesProgress:t})},s.prototype._onListerSuccess=function(t){return this.uploads.addFileInfos(t),this._tick()},s.prototype._onListerError=function(t){return this.set({listFilesError:t,status:"listing-files-error"})},s.prototype._onListerStop=function(){},s.prototype._mergeUploadError=function(t,e,r){var n,i;return i=this.get("uploadErrors").slice(0),n=o.sortedIndex(i,{upload:t},function(t){return t.upload.id}),null==e?i.splice(n,0,{upload:t,error:r}):null==r?i.splice(n,1):i[n].error=r,this.set({uploadErrors:i})},s.prototype._onUploadBatchAdded=function(t){var o,e,r,n;for(r=0,n=t.length;n>r;r++)e=t[r],o=e.get("error"),null!=o&&this._mergeUploadError(e,null,o);return this._forceBestTick()},s.prototype._onUploadChanged=function(t){var o,e,r,n;return r=t.previousAttributes().error,n=t.get("error"),r!==n&&this._mergeUploadError(t,r,n),o=t.previousAttributes().deleting,e=t.get("deleting"),e&&!o&&this._removedUploads.push(t),this._forceBestTick()},s.prototype._onUploadsReset=function(){var t;return t=[],this.uploads.each(function(o){var e;return(e=o.get("error"))?t.push({upload:o,error:e}):void 0}),this.set({uploadErrors:t}),this._tick()},s.prototype._onUploaderStart=function(t){var o;return o=this.uploads.get(t.name),o.set({uploading:!0,error:null})},s.prototype._onUploaderStop=function(t){var o;return o=this.uploads.get(t.name),o.set({uploading:!1}),this._tick()},s.prototype._onUploaderProgress=function(t,o){var e;return e=this.uploads.get(t.name),e.updateWithProgress(o)},s.prototype._onUploaderError=function(t,o){var e;return e=this.uploads.get(t.name),e.set({error:o})},s.prototype._onUploaderSuccess=function(t){var o;return o=this.uploads.get(t.name),o.updateWithProgress({loaded:o.size(),total:o.size()})},s.prototype._onDeleterStart=function(){return this.set({status:"uploading"})},s.prototype._onDeleterSuccess=function(t){var o;return o=this.uploads.get(t.name),this.uploads.remove(o)},s.prototype._onDeleterError=function(t,o){var e;return e=this.uploads.get(t.name),e.set({error:o})},s.prototype._onDeleterStop=function(){return this._tick()},s.prototype._tick=function(){var t,o,e;return e=this.uploads.next(),this._currentUpload=e,null!=e&&(e.get("deleting")?this.deleter.run(e.get("fileInfo")):this.uploader.run(e.get("file"))),o=this.get("uploadErrors").length?"uploading-error":null!=e?"uploading":(t=this.get("uploadProgress"),t.loaded===t.total?"waiting":"waiting-error"),this.set({status:o})},s.prototype._forceBestTick=function(){var t;return t=this.uploads.next(),t!==this._currentUpload?this._currentUpload?this.uploader.abort():this._tick():void 0},s}(t.Model)}),define("mass-upload",["MassUpload"],function(t){return t}); \ No newline at end of file +define("MassUpload/FileInfo",[],function(){var t;return t=function(){function t(t,o,e,r){this.name=t,this.lastModifiedDate=o,this.total=e,this.loaded=r}return t}(),t.fromJson=function(o){return new t(o.name,new Date(o.lastModifiedDate),o.total,o.loaded)},t.fromFile=function(o){return new t(o.webkitRelativePath||o.name,o.lastModifiedDate,o.size,0)},t}),define("MassUpload/Upload",["underscore","backbone","./FileInfo"],function(t,o,e){var r;return r=function(){function t(t){var o,e,r;this.file=null!=(o=t.file)?o:null,this.fileInfo=null!=(e=t.fileInfo)?e:null,this.error=null!=(r=t.error)?r:null,this.uploading=t.uploading||!1,this.deleting=t.deleting||!1,this.id=null!=this.file?this.file.webkitRelativePath||this.file.name:this.fileInfo.name,this.attributes=this}return t.prototype=Object.create(o.Events),t.prototype.defaults={file:null,fileInfo:null,error:null,uploading:!1,deleting:!1},t.prototype.get=function(t){return this[t]},t.prototype.set=function(o){var e,r;this._previousAttributes=new t(this);for(e in o)r=o[e],this[e]=r;return this.trigger("change",this),this._previousAttributes=null},t.prototype.previousAttributes=function(){return this._previousAttributes},t.prototype.size=function(){var t;return null!=this._size?this._size:this._size=null!=(t=this.file)?t.size:void 0},t.prototype.lastModifiedDate=function(){var t;return null!=this._lastModifiedDate?this._lastModifiedDate:this._lastModifiedDate=null!=(t=this.file)?t.lastModifiedDate:void 0},t.prototype.updateWithProgress=function(t){var o;return o=new e(this.id,this.lastModifiedDate(),t.total,t.loaded),this.set({fileInfo:o})},t.prototype.getProgress=function(){return null==this.fileInfo||this.hasConflict()?null!=this.file?{loaded:0,total:this.size()}:void 0:{loaded:this.fileInfo.loaded,total:this.fileInfo.total}},t.prototype.isFullyUploaded=function(){return null!=this.fileInfo&&null==this.error&&!this.uploading&&!this.deleting&&this.fileInfo.loaded===this.fileInfo.total},t.prototype.hasConflict=function(){return null!=this.fileInfo&&null!=this.file&&(this.fileInfo.name!==this.id||this.fileInfo.total!==this.size()||this.fileInfo.lastModifiedDate.getTime()!==this.lastModifiedDate().getTime())},t}()}),define("MassUpload/UploadCollection",["backbone","./Upload"],function(t,o){var e,r;return r=function(){function t(){this._clear()}return t.prototype._clear=function(){return this.deleting=[],this.uploading=[],this.unfinished=[],this.unstarted=[]},t.prototype.uploadAttributesToState=function(t){var o;return o=null!=t.error?null:t.deleting?"deleting":t.uploading?"uploading":null!=t.file&&null!=t.fileInfo&&t.fileInfo.loadedr;r++)e=t[r],o=this.uploadAttributesToState(e.attributes),null!=o&&this[o].push(e);return void 0},t.prototype._removeUploadFromArray=function(t,o){var e;return e=o.indexOf(t),e>=0?o.splice(e,1):void 0},t.prototype.remove=function(t){var o;return o=this.uploadAttributesToState(t.attributes),null!=o?this._removeUploadFromArray(t.attributes,this[o]):void 0},t.prototype.change=function(t){var o,e;return e=this.uploadAttributesToState(t.previousAttributes()),o=this.uploadAttributesToState(t.attributes),e!==o&&(null!=e&&this._removeUploadFromArray(t,this[e]),null!=o)?this[o].push(t):void 0},t.prototype.reset=function(t){return null==t&&(t=[]),this._clear(),this.addBatch(t)},t.prototype.next=function(){var t,o,e,r;return null!=(t=null!=(o=null!=(e=null!=(r=this.deleting[0])?r:this.uploading[0])?e:this.unfinished[0])?o:this.unstarted[0])?t:null},t}(),e=function(){function e(){this.models=[],this._priorityQueue=new r,this.reset([])}return e.prototype=Object.create(t.Events),e.prototype.each=function(t,o){return this.models.forEach(t,o)},e.prototype.map=function(t,o){return this.models.map(t,o)},e.prototype._prepareModel=function(t){return t instanceof o?t:new o(t)},e.prototype.reset=function(t){var o,e,r,n,i,s,l;for(s=this.models,e=0,n=s.length;n>e;e++)o=s[e],o.off("all",this._onUploadEvent,this);for(this.models=function(){var e,r,n,i;for(n=null!=t?t:[],i=[],e=0,r=n.length;r>e;e++)o=n[e],i.push(this._prepareModel(o));return i}.call(this),this.length=this.models.length,this._idToModel={},l=this.models,r=0,i=l.length;i>r;r++)o=l[r],o.on("all",this._onUploadEvent,this),this._idToModel[o.id]=o;return this._priorityQueue.reset(this.models),this.trigger("reset",this)},e.prototype.get=function(t){var o;return null!=(o=this._idToModel[t])?o:null},e.prototype.forFile=function(t){return this.get(t.webkitRelativePath||t.name)},e.prototype.forFileInfo=function(t){return this.get(t.name)},e.prototype.addFiles=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({file:e}));return i}(),this._addWithMerge(r)},e.prototype.addFileInfos=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({fileInfo:e}));return i}(),this._addWithMerge(r)},e.prototype.next=function(){return this._priorityQueue.next()},e.prototype.add=function(t){return null!=t.length?this.addBatch(t):this.addBatch([t])},e.prototype.addBatch=function(t){var o,e,r,n,i;for(e=0,n=t.length;n>e;e++)o=t[e],this._idToModel[o.id]=o,o.on("all",this._onUploadEvent,this),this.models.push(o);for(this.length+=t.length,this._priorityQueue.addBatch(t),r=0,i=t.length;i>r;r++)o=t[r],this.trigger("add",o);return this.trigger("add-batch",t)},e.prototype._onUploadEvent=function(t,o){return"add"!==t&&"remove"!==t&&this.trigger.apply(this,arguments),"change"===t?this._priorityQueue.change(o):void 0},e.prototype._addWithMerge=function(t){var o,e,r,n,i,s,l;for(n=[],s=0,l=t.length;l>s;s++)i=t[s],null!=(o=this.get(i.id))?(e=i.get("file"),r=i.get("fileInfo"),null!=e&&o.set({file:e}),null!=r&&o.set({fileInfo:r})):n.push(i);return n.length&&this.add(n),void 0},e}()}),define("MassUpload/FileLister",[],function(){var t;return t=function(){function t(t,o){this.doListFiles=t,this.callbacks=o,this.running=!1}return t.prototype.run=function(){var t,o=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(t=this.callbacks).onStart&&t.onStart(),this.doListFiles(function(t){var e;return"function"==typeof(e=o.callbacks).onProgress?e.onProgress(t):void 0},function(t){return o._onSuccess(t)},function(t){return o._onError(t)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop()},t.prototype._onError=function(t){return this.callbacks.onError(t),this._onStop()},t.prototype._onStop=function(){var t;return this.running=!1,"function"==typeof(t=this.callbacks).onStop?t.onStop():void 0},t}()}),define("MassUpload/FileUploader",["./FileInfo"],function(){var t;return t=function(){function t(t,o){this.doUpload=t,this.callbacks=o,this._file=null,this._abortCallback=null,this._aborting=!1}return t.prototype.run=function(t){var o,e=this;if(null!=this._file)throw"already running";return this._file=t,"function"==typeof(o=this.callbacks).onStart&&o.onStart(this._file),this._abortCallback=this.doUpload(t,function(o){return e._onProgress(t,o)},function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype.abort=function(){return this._file&&!this._aborting&&(this._aborting=!0,"function"==typeof this._abortCallback)?this._abortCallback():void 0},t.prototype._onProgress=function(t,o){var e;return"function"==typeof(e=this.callbacks).onProgress?e.onProgress(t,o):void 0},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this._file=null,this._abortCallback=null,this._aborting=!1,"function"==typeof(o=this.callbacks).onStop?o.onStop(t):void 0},t}()}),define("MassUpload/FileDeleter",[],function(){var t;return t=function(){function t(t,o){this.doDeleteFile=t,this.callbacks=null!=o?o:{},this.running=!1}return t.prototype.run=function(t){var o,e=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(o=this.callbacks).onStart&&o.onStart(t),this.doDeleteFile(t,function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this.running=!1,"function"==typeof(o=this.callbacks).onStop&&o.onStop(t),void 0},t}()}),define("MassUpload/State",[],function(){var t;return t=function(){function t(t){var o,e,r,n;null==t&&(t={}),this.loaded=null!=(o=t.loaded)?o:0,this.total=null!=(e=t.total)?e:0,this.status=null!=(r=t.status)?r:"waiting",this.errors=null!=(n=t.errors)?n:[]}return t.prototype._extend=function(o){var e,r,n,i;return new t({loaded:null!=(e=o.loaded)?e:this.loaded,total:null!=(r=o.total)?r:this.total,status:null!=(n=o.status)?n:this.status,errors:null!=(i=o.errors)?i:this.errors})},t.prototype.isComplete=function(){return this.total&&this.loaded===this.total&&"waiting"===this.status&&!this.errors.length&&!0||!1},t.prototype.withTotal=function(t){return this._extend({total:t})},t.prototype.withLoaded=function(t){return this._extend({loaded:t})},t.prototype.withStatus=function(t){return this._extend({status:t})},t.prototype.withAnError=function(t){var o;return o=this.errors.slice(0),o.push(t),this._extend({errors:o})},t.prototype.withoutAnError=function(t){var o,e;return e=this.errors.slice(0),o=e.indexOf(t),e.splice(o,1),this._extend({errors:e})},t}()}),define("MassUpload/UploadProgress",["backbone"],function(t){return t.Model.extend({defaults:{loaded:0,total:0},initialize:function(){var t;if(t=this.get("uploadCollection"),null==t)throw"Must initialize UploadProgress with `uploadCollection`, an UploadCollection";return this._idToLastKnownProgress={},this._updateAndStartListening()},_adjust:function(t,o){return this.set({loaded:this.get("loaded")+t,total:this.get("total")+o})},add:function(t){var o;return o=t.getProgress(),this._adjust(o.loaded,o.total),this._idToLastKnownProgress[t.id]=o},reset:function(t){var o,e,r,n,i,s,l,u;for(o=this._idToLastKnownProgress={},e=0,i=0,u=t.models,s=0,l=u.length;l>s;s++)r=u[s],n=r.getProgress(),o[r.id]=n,e+=n.loaded,i+=n.total;return this.set({loaded:e,total:i})},remove:function(t){var o;return o=t.getProgress(),this._adjust(-o.loaded,-o.total),this._idToLastKnownProgress[t.id]=o},change:function(t){var o,e;return e=this._idToLastKnownProgress[t.id],null!=e?(o=t.getProgress(),this._adjust(o.loaded-e.loaded,o.total-e.total),this._idToLastKnownProgress[t.id]=o):void 0},_updateAndStartListening:function(){var t,o,e,r,n;for(t=this.get("uploadCollection"),n=["add","remove","change","reset"],e=0,r=n.length;r>e;e++)o=n[e],this.listenTo(t,o,this[o]);return this.reset(t),void 0},inBatch:function(t){this.stopListening(this.get("uploadCollection"));try{return t()}finally{this._updateAndStartListening()}}})});var __hasProp={}.hasOwnProperty,__extends=function(t,o){function e(){this.constructor=t}for(var r in o)__hasProp.call(o,r)&&(t[r]=o[r]);return e.prototype=o.prototype,t.prototype=new e,t.__super__=o.prototype,t};define("MassUpload",["backbone","underscore","MassUpload/UploadCollection","MassUpload/FileLister","MassUpload/FileUploader","MassUpload/FileDeleter","MassUpload/State","MassUpload/UploadProgress"],function(t,o,e,r,n,i,s,l){var u;return u=function(t){function s(t){this._removedUploads=[],s.__super__.constructor.call(this,{},t)}return __extends(s,t),s.prototype.defaults=function(){return{status:"waiting",listFilesProgress:null,listFilesError:null,uploadProgress:null,uploadErrors:[]}},s.prototype.initialize=function(t,o){var r,n,i=this;return this._options=o,this.uploads=null!=(n=null!=o?o.uploads:void 0)?n:new e,this._uploadProgress=new l({uploadCollection:this.uploads}),r=function(){return i.set({uploadProgress:i._uploadProgress.pick("loaded","total")})},this.listenTo(this._uploadProgress,"change",r),r(),this.listenTo(this.uploads,"add-batch",this._onUploadBatchAdded),this.listenTo(this.uploads,"change",function(t){return i._onUploadChanged(t)}),this.listenTo(this.uploads,"reset",function(){return i._onUploadsReset()}),this.prepare()},s.prototype.prepare=function(){var t,o,e,s,l=this;return t=this._options,this.lister=null!=(o=null!=t?t.lister:void 0)?o:new r(t.doListFiles),this.lister.callbacks={onStart:function(){return l._onListerStart()},onProgress:function(t){return l._onListerProgress(t)},onSuccess:function(t){return l._onListerSuccess(t)},onError:function(t){return l._onListerError(t)},onStop:function(){return l._onListerStop()}},this.uploader=null!=(e=null!=t?t.uploader:void 0)?e:new n(t.doUploadFile),this.uploader.callbacks={onStart:function(t){return l._onUploaderStart(t)},onStop:function(t){return l._onUploaderStop(t)},onSuccess:function(t){return l._onUploaderSuccess(t)},onError:function(t,o){return l._onUploaderError(t,o)},onProgress:function(t,o){return l._onUploaderProgress(t,o)}},this.deleter=null!=(s=null!=t?t.deleter:void 0)?s:new i(t.doDeleteFile),this.deleter.callbacks={onStart:function(t){return l._onDeleterStart(t)},onSuccess:function(t){return l._onDeleterSuccess(t)},onError:function(t,o){return l._onDeleterError(t,o)},onStop:function(t){return l._onDeleterStop(t)}}},s.prototype.fetchFileInfosFromServer=function(){return this.lister.run()},s.prototype.retryListFiles=function(){return this.fetchFileInfosFromServer()},s.prototype.retryUpload=function(t){return t.set({error:null})},s.prototype.retryAllUploads=function(){return this.uploads.each(function(t){return t.set({error:null})})},s.prototype.addFiles=function(t){var o=this;return this._uploadProgress.inBatch(function(){return o.uploads.addFiles(t)})},s.prototype.removeUpload=function(t){return t.set({deleting:!0})},s.prototype.abort=function(){var t=this;return this.uploads.each(function(o){return t.removeUpload(o)}),this.uploads.reset(),this.prepare()},s.prototype._onListerStart=function(){return this.set({status:"listing-files",listFilesError:null})},s.prototype._onListerProgress=function(t){return this.set({listFilesProgress:t})},s.prototype._onListerSuccess=function(t){return this.uploads.addFileInfos(t),this._tick()},s.prototype._onListerError=function(t){return this.set({listFilesError:t,status:"listing-files-error"})},s.prototype._onListerStop=function(){},s.prototype._mergeUploadError=function(t,e,r){var n,i;return i=this.get("uploadErrors").slice(0),n=o.sortedIndex(i,{upload:t},function(t){return t.upload.id}),null==e?i.splice(n,0,{upload:t,error:r}):null==r?i.splice(n,1):i[n].error=r,this.set({uploadErrors:i})},s.prototype._onUploadBatchAdded=function(t){var o,e,r,n;for(r=0,n=t.length;n>r;r++)e=t[r],o=e.get("error"),null!=o&&this._mergeUploadError(e,null,o);return this._forceBestTick()},s.prototype._onUploadChanged=function(t){var o,e,r,n;return r=t.previousAttributes().error,n=t.get("error"),r!==n&&this._mergeUploadError(t,r,n),o=t.previousAttributes().deleting,e=t.get("deleting"),e&&!o&&this._removedUploads.push(t),this._forceBestTick()},s.prototype._onUploadsReset=function(){var t;return t=[],this.uploads.each(function(o){var e;return(e=o.get("error"))?t.push({upload:o,error:e}):void 0}),this.set({uploadErrors:t}),this._tick()},s.prototype._onUploaderStart=function(t){var o;return o=this.uploads.forFile(t),o.set({uploading:!0,error:null})},s.prototype._onUploaderStop=function(t){var o;return o=this.uploads.forFile(t),o.set({uploading:!1}),this._tick()},s.prototype._onUploaderProgress=function(t,o){var e;return e=this.uploads.forFile(t),e.updateWithProgress(o)},s.prototype._onUploaderError=function(t,o){var e;return e=this.uploads.forFile(t),e.set({error:o})},s.prototype._onUploaderSuccess=function(t){var o;return o=this.uploads.forFile(t),o.updateWithProgress({loaded:o.size(),total:o.size()})},s.prototype._onDeleterStart=function(){return this.set({status:"uploading"})},s.prototype._onDeleterSuccess=function(t){var o;return o=this.uploads.forFileInfo(t),this.uploads.remove(o)},s.prototype._onDeleterError=function(t,o){var e;return e=this.uploads.forFileInfo(t),e.set({error:o})},s.prototype._onDeleterStop=function(){return this._tick()},s.prototype._tick=function(){var t,o,e;return e=this.uploads.next(),this._currentUpload=e,null!=e&&(e.get("deleting")?this.deleter.run(e.get("fileInfo")):this.uploader.run(e.get("file"))),o=this.get("uploadErrors").length?"uploading-error":null!=e?"uploading":(t=this.get("uploadProgress"),t.loaded===t.total?"waiting":"waiting-error"),this.set({status:o})},s.prototype._forceBestTick=function(){var t;return t=this.uploads.next(),t!==this._currentUpload?this._currentUpload?this.uploader.abort():this._tick():void 0},s}(t.Model)}),define("mass-upload",["MassUpload"],function(t){return t}); \ No newline at end of file diff --git a/dist/mass-upload.no-require.js b/dist/mass-upload.no-require.js index cafe094..7a3c075 100644 --- a/dist/mass-upload.no-require.js +++ b/dist/mass-upload.no-require.js @@ -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); @@ -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; } @@ -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() { @@ -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 @@ -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 }); @@ -1371,13 +1379,13 @@ 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 }); @@ -1385,7 +1393,7 @@ define('MassUpload',['backbone', 'underscore', 'MassUpload/UploadCollection', 'M 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() @@ -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 }); diff --git a/dist/mass-upload.no-require.min.js b/dist/mass-upload.no-require.min.js index cdd4909..e0751bf 100644 --- a/dist/mass-upload.no-require.min.js +++ b/dist/mass-upload.no-require.min.js @@ -4,4 +4,4 @@ * see: http://github.com/jrburke/almond for details */ -!function(){var t,o,e;!function(r){function n(t,o){return S.call(t,o)}function i(t,o){var e,r,n,i,s,l,u,a,p,d,c,h=o&&o.split("/"),f=y.map,g=f&&f["*"]||{};if(t&&"."===t.charAt(0))if(o){for(h=h.slice(0,h.length-1),t=t.split("/"),s=t.length-1,y.nodeIdCompat&&m.test(t[s])&&(t[s]=t[s].replace(m,"")),t=h.concat(t),p=0;p0&&(t.splice(p-1,2),p-=2)}t=t.join("/")}else 0===t.indexOf("./")&&(t=t.substring(2));if((h||g)&&f){for(e=t.split("/"),p=e.length;p>0;p-=1){if(r=e.slice(0,p).join("/"),h)for(d=h.length;d>0;d-=1)if(n=f[h.slice(0,d).join("/")],n&&(n=n[r])){i=n,l=p;break}if(i)break;!u&&g&&g[r]&&(u=g[r],a=p)}!i&&u&&(i=u,l=a),i&&(e.splice(0,l,i),t=e.join("/"))}return t}function s(t,o){return function(){return h.apply(r,U.call(arguments,0).concat([t,o]))}}function l(t){return function(o){return i(o,t)}}function u(t){return function(o){_[t]=o}}function a(t){if(n(v,t)){var o=v[t];delete v[t],b[t]=!0,c.apply(r,o)}if(!n(_,t)&&!n(b,t))throw new Error("No "+t);return _[t]}function p(t){var o,e=t?t.indexOf("!"):-1;return e>-1&&(o=t.substring(0,e),t=t.substring(e+1,t.length)),[o,t]}function d(t){return function(){return y&&y.config&&y.config[t]||{}}}var c,h,f,g,_={},v={},y={},b={},S=Object.prototype.hasOwnProperty,U=[].slice,m=/\.js$/;f=function(t,o){var e,r=p(t),n=r[0];return t=r[1],n&&(n=i(n,o),e=a(n)),n?t=e&&e.normalize?e.normalize(t,l(o)):i(t,o):(t=i(t,o),r=p(t),n=r[0],t=r[1],n&&(e=a(n))),{f:n?n+"!"+t:t,n:t,pr:n,p:e}},g={require:function(t){return s(t)},exports:function(t){var o=_[t];return"undefined"!=typeof o?o:_[t]={}},module:function(t){return{id:t,uri:"",exports:_[t],config:d(t)}}},c=function(t,o,e,i){var l,p,d,c,h,y,S=[],U=typeof e;if(i=i||t,"undefined"===U||"function"===U){for(o=!o.length&&e.length?["require","exports","module"]:o,h=0;hr;r++)e=t[r],o=this.uploadAttributesToState(e.attributes),null!=o&&this[o].push(e);return void 0},t.prototype._removeUploadFromArray=function(t,o){var e;return e=o.indexOf(t),e>=0?o.splice(e,1):void 0},t.prototype.remove=function(t){var o;return o=this.uploadAttributesToState(t.attributes),null!=o?this._removeUploadFromArray(t.attributes,this[o]):void 0},t.prototype.change=function(t){var o,e;return e=this.uploadAttributesToState(t.previousAttributes()),o=this.uploadAttributesToState(t.attributes),e!==o&&(null!=e&&this._removeUploadFromArray(t,this[e]),null!=o)?this[o].push(t):void 0},t.prototype.reset=function(t){return null==t&&(t=[]),this._clear(),this.addBatch(t)},t.prototype.next=function(){var t,o,e,r;return null!=(t=null!=(o=null!=(e=null!=(r=this.deleting[0])?r:this.uploading[0])?e:this.unfinished[0])?o:this.unstarted[0])?t:null},t}(),e=function(){function e(){this.models=[],this._priorityQueue=new r,this.reset([])}return e.prototype=Object.create(t.Events),e.prototype.each=function(t,o){return this.models.forEach(t,o)},e.prototype.map=function(t,o){return this.models.map(t,o)},e.prototype._prepareModel=function(t){return t instanceof o?t:new o(t)},e.prototype.reset=function(t){var o,e,r,n,i,s,l;for(s=this.models,e=0,n=s.length;n>e;e++)o=s[e],o.off("all",this._onUploadEvent,this);for(this.models=function(){var e,r,n,i;for(n=null!=t?t:[],i=[],e=0,r=n.length;r>e;e++)o=n[e],i.push(this._prepareModel(o));return i}.call(this),this.length=this.models.length,this._idToModel={},l=this.models,r=0,i=l.length;i>r;r++)o=l[r],o.on("all",this._onUploadEvent,this),this._idToModel[o.id]=o;return this._priorityQueue.reset(this.models),this.trigger("reset",this)},e.prototype.get=function(t){var o;return null!=(o=this._idToModel[t])?o:null},e.prototype.addFiles=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({file:e}));return i}(),this._addWithMerge(r)},e.prototype.addFileInfos=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({fileInfo:e}));return i}(),this._addWithMerge(r)},e.prototype.next=function(){return this._priorityQueue.next()},e.prototype.add=function(t){return null!=t.length?this.addBatch(t):this.addBatch([t])},e.prototype.addBatch=function(t){var o,e,r,n,i;for(e=0,n=t.length;n>e;e++)o=t[e],this._idToModel[o.id]=o,o.on("all",this._onUploadEvent,this),this.models.push(o);for(this.length+=t.length,this._priorityQueue.addBatch(t),r=0,i=t.length;i>r;r++)o=t[r],this.trigger("add",o);return this.trigger("add-batch",t)},e.prototype._onUploadEvent=function(t,o){return"add"!==t&&"remove"!==t&&this.trigger.apply(this,arguments),"change"===t?this._priorityQueue.change(o):void 0},e.prototype._addWithMerge=function(t){var o,e,r,n,i,s,l;for(n=[],s=0,l=t.length;l>s;s++)i=t[s],null!=(o=this.get(i.id))?(e=i.get("file"),r=i.get("fileInfo"),null!=e&&o.set({file:e}),null!=r&&o.set({fileInfo:r})):n.push(i);return n.length&&this.add(n),void 0},e}()}),e("MassUpload/FileLister",[],function(){var t;return t=function(){function t(t,o){this.doListFiles=t,this.callbacks=o,this.running=!1}return t.prototype.run=function(){var t,o=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(t=this.callbacks).onStart&&t.onStart(),this.doListFiles(function(t){var e;return"function"==typeof(e=o.callbacks).onProgress?e.onProgress(t):void 0},function(t){return o._onSuccess(t)},function(t){return o._onError(t)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop()},t.prototype._onError=function(t){return this.callbacks.onError(t),this._onStop()},t.prototype._onStop=function(){var t;return this.running=!1,"function"==typeof(t=this.callbacks).onStop?t.onStop():void 0},t}()}),e("MassUpload/FileUploader",["./FileInfo"],function(){var t;return t=function(){function t(t,o){this.doUpload=t,this.callbacks=o,this._file=null,this._abortCallback=null,this._aborting=!1}return t.prototype.run=function(t){var o,e=this;if(null!=this._file)throw"already running";return this._file=t,"function"==typeof(o=this.callbacks).onStart&&o.onStart(this._file),this._abortCallback=this.doUpload(t,function(o){return e._onProgress(t,o)},function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype.abort=function(){return this._file&&!this._aborting&&(this._aborting=!0,"function"==typeof this._abortCallback)?this._abortCallback():void 0},t.prototype._onProgress=function(t,o){var e;return"function"==typeof(e=this.callbacks).onProgress?e.onProgress(t,o):void 0},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this._file=null,this._abortCallback=null,this._aborting=!1,"function"==typeof(o=this.callbacks).onStop?o.onStop(t):void 0},t}()}),e("MassUpload/FileDeleter",[],function(){var t;return t=function(){function t(t,o){this.doDeleteFile=t,this.callbacks=null!=o?o:{},this.running=!1}return t.prototype.run=function(t){var o,e=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(o=this.callbacks).onStart&&o.onStart(t),this.doDeleteFile(t,function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this.running=!1,"function"==typeof(o=this.callbacks).onStop&&o.onStop(t),void 0},t}()}),e("MassUpload/State",[],function(){var t;return t=function(){function t(t){var o,e,r,n;null==t&&(t={}),this.loaded=null!=(o=t.loaded)?o:0,this.total=null!=(e=t.total)?e:0,this.status=null!=(r=t.status)?r:"waiting",this.errors=null!=(n=t.errors)?n:[]}return t.prototype._extend=function(o){var e,r,n,i;return new t({loaded:null!=(e=o.loaded)?e:this.loaded,total:null!=(r=o.total)?r:this.total,status:null!=(n=o.status)?n:this.status,errors:null!=(i=o.errors)?i:this.errors})},t.prototype.isComplete=function(){return this.total&&this.loaded===this.total&&"waiting"===this.status&&!this.errors.length&&!0||!1},t.prototype.withTotal=function(t){return this._extend({total:t})},t.prototype.withLoaded=function(t){return this._extend({loaded:t})},t.prototype.withStatus=function(t){return this._extend({status:t})},t.prototype.withAnError=function(t){var o;return o=this.errors.slice(0),o.push(t),this._extend({errors:o})},t.prototype.withoutAnError=function(t){var o,e;return e=this.errors.slice(0),o=e.indexOf(t),e.splice(o,1),this._extend({errors:e})},t}()}),e("MassUpload/UploadProgress",["backbone"],function(t){return t.Model.extend({defaults:{loaded:0,total:0},initialize:function(){var t;if(t=this.get("uploadCollection"),null==t)throw"Must initialize UploadProgress with `uploadCollection`, an UploadCollection";return this._idToLastKnownProgress={},this._updateAndStartListening()},_adjust:function(t,o){return this.set({loaded:this.get("loaded")+t,total:this.get("total")+o})},add:function(t){var o;return o=t.getProgress(),this._adjust(o.loaded,o.total),this._idToLastKnownProgress[t.id]=o},reset:function(t){var o,e,r,n,i,s,l,u;for(o=this._idToLastKnownProgress={},e=0,i=0,u=t.models,s=0,l=u.length;l>s;s++)r=u[s],n=r.getProgress(),o[r.id]=n,e+=n.loaded,i+=n.total;return this.set({loaded:e,total:i})},remove:function(t){var o;return o=t.getProgress(),this._adjust(-o.loaded,-o.total),this._idToLastKnownProgress[t.id]=o},change:function(t){var o,e;return e=this._idToLastKnownProgress[t.id],null!=e?(o=t.getProgress(),this._adjust(o.loaded-e.loaded,o.total-e.total),this._idToLastKnownProgress[t.id]=o):void 0},_updateAndStartListening:function(){var t,o,e,r,n;for(t=this.get("uploadCollection"),n=["add","remove","change","reset"],e=0,r=n.length;r>e;e++)o=n[e],this.listenTo(t,o,this[o]);return this.reset(t),void 0},inBatch:function(t){this.stopListening(this.get("uploadCollection"));try{return t()}finally{this._updateAndStartListening()}}})});var r={}.hasOwnProperty,n=function(t,o){function e(){this.constructor=t}for(var n in o)r.call(o,n)&&(t[n]=o[n]);return e.prototype=o.prototype,t.prototype=new e,t.__super__=o.prototype,t};e("MassUpload",["backbone","underscore","MassUpload/UploadCollection","MassUpload/FileLister","MassUpload/FileUploader","MassUpload/FileDeleter","MassUpload/State","MassUpload/UploadProgress"],function(t,o,e,r,i,s,l,u){var a;return a=function(t){function l(t){this._removedUploads=[],l.__super__.constructor.call(this,{},t)}return n(l,t),l.prototype.defaults=function(){return{status:"waiting",listFilesProgress:null,listFilesError:null,uploadProgress:null,uploadErrors:[]}},l.prototype.initialize=function(t,o){var r,n,i=this;return this._options=o,this.uploads=null!=(n=null!=o?o.uploads:void 0)?n:new e,this._uploadProgress=new u({uploadCollection:this.uploads}),r=function(){return i.set({uploadProgress:i._uploadProgress.pick("loaded","total")})},this.listenTo(this._uploadProgress,"change",r),r(),this.listenTo(this.uploads,"add-batch",this._onUploadBatchAdded),this.listenTo(this.uploads,"change",function(t){return i._onUploadChanged(t)}),this.listenTo(this.uploads,"reset",function(){return i._onUploadsReset()}),this.prepare()},l.prototype.prepare=function(){var t,o,e,n,l=this;return t=this._options,this.lister=null!=(o=null!=t?t.lister:void 0)?o:new r(t.doListFiles),this.lister.callbacks={onStart:function(){return l._onListerStart()},onProgress:function(t){return l._onListerProgress(t)},onSuccess:function(t){return l._onListerSuccess(t)},onError:function(t){return l._onListerError(t)},onStop:function(){return l._onListerStop()}},this.uploader=null!=(e=null!=t?t.uploader:void 0)?e:new i(t.doUploadFile),this.uploader.callbacks={onStart:function(t){return l._onUploaderStart(t)},onStop:function(t){return l._onUploaderStop(t)},onSuccess:function(t){return l._onUploaderSuccess(t)},onError:function(t,o){return l._onUploaderError(t,o)},onProgress:function(t,o){return l._onUploaderProgress(t,o)}},this.deleter=null!=(n=null!=t?t.deleter:void 0)?n:new s(t.doDeleteFile),this.deleter.callbacks={onStart:function(t){return l._onDeleterStart(t)},onSuccess:function(t){return l._onDeleterSuccess(t)},onError:function(t,o){return l._onDeleterError(t,o)},onStop:function(t){return l._onDeleterStop(t)}}},l.prototype.fetchFileInfosFromServer=function(){return this.lister.run()},l.prototype.retryListFiles=function(){return this.fetchFileInfosFromServer()},l.prototype.retryUpload=function(t){return t.set({error:null})},l.prototype.retryAllUploads=function(){return this.uploads.each(function(t){return t.set({error:null})})},l.prototype.addFiles=function(t){var o=this;return this._uploadProgress.inBatch(function(){return o.uploads.addFiles(t)})},l.prototype.removeUpload=function(t){return t.set({deleting:!0})},l.prototype.abort=function(){var t=this;return this.uploads.each(function(o){return t.removeUpload(o)}),this.uploads.reset(),this.prepare()},l.prototype._onListerStart=function(){return this.set({status:"listing-files",listFilesError:null})},l.prototype._onListerProgress=function(t){return this.set({listFilesProgress:t})},l.prototype._onListerSuccess=function(t){return this.uploads.addFileInfos(t),this._tick()},l.prototype._onListerError=function(t){return this.set({listFilesError:t,status:"listing-files-error"})},l.prototype._onListerStop=function(){},l.prototype._mergeUploadError=function(t,e,r){var n,i;return i=this.get("uploadErrors").slice(0),n=o.sortedIndex(i,{upload:t},function(t){return t.upload.id}),null==e?i.splice(n,0,{upload:t,error:r}):null==r?i.splice(n,1):i[n].error=r,this.set({uploadErrors:i})},l.prototype._onUploadBatchAdded=function(t){var o,e,r,n;for(r=0,n=t.length;n>r;r++)e=t[r],o=e.get("error"),null!=o&&this._mergeUploadError(e,null,o);return this._forceBestTick()},l.prototype._onUploadChanged=function(t){var o,e,r,n;return r=t.previousAttributes().error,n=t.get("error"),r!==n&&this._mergeUploadError(t,r,n),o=t.previousAttributes().deleting,e=t.get("deleting"),e&&!o&&this._removedUploads.push(t),this._forceBestTick()},l.prototype._onUploadsReset=function(){var t;return t=[],this.uploads.each(function(o){var e;return(e=o.get("error"))?t.push({upload:o,error:e}):void 0}),this.set({uploadErrors:t}),this._tick()},l.prototype._onUploaderStart=function(t){var o;return o=this.uploads.get(t.name),o.set({uploading:!0,error:null})},l.prototype._onUploaderStop=function(t){var o;return o=this.uploads.get(t.name),o.set({uploading:!1}),this._tick()},l.prototype._onUploaderProgress=function(t,o){var e;return e=this.uploads.get(t.name),e.updateWithProgress(o)},l.prototype._onUploaderError=function(t,o){var e;return e=this.uploads.get(t.name),e.set({error:o})},l.prototype._onUploaderSuccess=function(t){var o;return o=this.uploads.get(t.name),o.updateWithProgress({loaded:o.size(),total:o.size()})},l.prototype._onDeleterStart=function(){return this.set({status:"uploading"})},l.prototype._onDeleterSuccess=function(t){var o;return o=this.uploads.get(t.name),this.uploads.remove(o)},l.prototype._onDeleterError=function(t,o){var e;return e=this.uploads.get(t.name),e.set({error:o})},l.prototype._onDeleterStop=function(){return this._tick()},l.prototype._tick=function(){var t,o,e;return e=this.uploads.next(),this._currentUpload=e,null!=e&&(e.get("deleting")?this.deleter.run(e.get("fileInfo")):this.uploader.run(e.get("file"))),o=this.get("uploadErrors").length?"uploading-error":null!=e?"uploading":(t=this.get("uploadProgress"),t.loaded===t.total?"waiting":"waiting-error"),this.set({status:o})},l.prototype._forceBestTick=function(){var t;return t=this.uploads.next(),t!==this._currentUpload?this._currentUpload?this.uploader.abort():this._tick():void 0},l}(t.Model)}),o(["./MassUpload"],function(t){return window.MassUpload=t}),e("index",function(){})}(); \ No newline at end of file +!function(){var t,o,e;!function(r){function n(t,o){return S.call(t,o)}function i(t,o){var e,r,n,i,s,l,u,a,p,d,f,c=o&&o.split("/"),h=y.map,g=h&&h["*"]||{};if(t&&"."===t.charAt(0))if(o){for(c=c.slice(0,c.length-1),t=t.split("/"),s=t.length-1,y.nodeIdCompat&&m.test(t[s])&&(t[s]=t[s].replace(m,"")),t=c.concat(t),p=0;p0&&(t.splice(p-1,2),p-=2)}t=t.join("/")}else 0===t.indexOf("./")&&(t=t.substring(2));if((c||g)&&h){for(e=t.split("/"),p=e.length;p>0;p-=1){if(r=e.slice(0,p).join("/"),c)for(d=c.length;d>0;d-=1)if(n=h[c.slice(0,d).join("/")],n&&(n=n[r])){i=n,l=p;break}if(i)break;!u&&g&&g[r]&&(u=g[r],a=p)}!i&&u&&(i=u,l=a),i&&(e.splice(0,l,i),t=e.join("/"))}return t}function s(t,o){return function(){return c.apply(r,U.call(arguments,0).concat([t,o]))}}function l(t){return function(o){return i(o,t)}}function u(t){return function(o){_[t]=o}}function a(t){if(n(v,t)){var o=v[t];delete v[t],b[t]=!0,f.apply(r,o)}if(!n(_,t)&&!n(b,t))throw new Error("No "+t);return _[t]}function p(t){var o,e=t?t.indexOf("!"):-1;return e>-1&&(o=t.substring(0,e),t=t.substring(e+1,t.length)),[o,t]}function d(t){return function(){return y&&y.config&&y.config[t]||{}}}var f,c,h,g,_={},v={},y={},b={},S=Object.prototype.hasOwnProperty,U=[].slice,m=/\.js$/;h=function(t,o){var e,r=p(t),n=r[0];return t=r[1],n&&(n=i(n,o),e=a(n)),n?t=e&&e.normalize?e.normalize(t,l(o)):i(t,o):(t=i(t,o),r=p(t),n=r[0],t=r[1],n&&(e=a(n))),{f:n?n+"!"+t:t,n:t,pr:n,p:e}},g={require:function(t){return s(t)},exports:function(t){var o=_[t];return"undefined"!=typeof o?o:_[t]={}},module:function(t){return{id:t,uri:"",exports:_[t],config:d(t)}}},f=function(t,o,e,i){var l,p,d,f,c,y,S=[],U=typeof e;if(i=i||t,"undefined"===U||"function"===U){for(o=!o.length&&e.length?["require","exports","module"]:o,c=0;cr;r++)e=t[r],o=this.uploadAttributesToState(e.attributes),null!=o&&this[o].push(e);return void 0},t.prototype._removeUploadFromArray=function(t,o){var e;return e=o.indexOf(t),e>=0?o.splice(e,1):void 0},t.prototype.remove=function(t){var o;return o=this.uploadAttributesToState(t.attributes),null!=o?this._removeUploadFromArray(t.attributes,this[o]):void 0},t.prototype.change=function(t){var o,e;return e=this.uploadAttributesToState(t.previousAttributes()),o=this.uploadAttributesToState(t.attributes),e!==o&&(null!=e&&this._removeUploadFromArray(t,this[e]),null!=o)?this[o].push(t):void 0},t.prototype.reset=function(t){return null==t&&(t=[]),this._clear(),this.addBatch(t)},t.prototype.next=function(){var t,o,e,r;return null!=(t=null!=(o=null!=(e=null!=(r=this.deleting[0])?r:this.uploading[0])?e:this.unfinished[0])?o:this.unstarted[0])?t:null},t}(),e=function(){function e(){this.models=[],this._priorityQueue=new r,this.reset([])}return e.prototype=Object.create(t.Events),e.prototype.each=function(t,o){return this.models.forEach(t,o)},e.prototype.map=function(t,o){return this.models.map(t,o)},e.prototype._prepareModel=function(t){return t instanceof o?t:new o(t)},e.prototype.reset=function(t){var o,e,r,n,i,s,l;for(s=this.models,e=0,n=s.length;n>e;e++)o=s[e],o.off("all",this._onUploadEvent,this);for(this.models=function(){var e,r,n,i;for(n=null!=t?t:[],i=[],e=0,r=n.length;r>e;e++)o=n[e],i.push(this._prepareModel(o));return i}.call(this),this.length=this.models.length,this._idToModel={},l=this.models,r=0,i=l.length;i>r;r++)o=l[r],o.on("all",this._onUploadEvent,this),this._idToModel[o.id]=o;return this._priorityQueue.reset(this.models),this.trigger("reset",this)},e.prototype.get=function(t){var o;return null!=(o=this._idToModel[t])?o:null},e.prototype.forFile=function(t){return this.get(t.webkitRelativePath||t.name)},e.prototype.forFileInfo=function(t){return this.get(t.name)},e.prototype.addFiles=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({file:e}));return i}(),this._addWithMerge(r)},e.prototype.addFileInfos=function(t){var e,r;return r=function(){var r,n,i;for(i=[],r=0,n=t.length;n>r;r++)e=t[r],i.push(new o({fileInfo:e}));return i}(),this._addWithMerge(r)},e.prototype.next=function(){return this._priorityQueue.next()},e.prototype.add=function(t){return null!=t.length?this.addBatch(t):this.addBatch([t])},e.prototype.addBatch=function(t){var o,e,r,n,i;for(e=0,n=t.length;n>e;e++)o=t[e],this._idToModel[o.id]=o,o.on("all",this._onUploadEvent,this),this.models.push(o);for(this.length+=t.length,this._priorityQueue.addBatch(t),r=0,i=t.length;i>r;r++)o=t[r],this.trigger("add",o);return this.trigger("add-batch",t)},e.prototype._onUploadEvent=function(t,o){return"add"!==t&&"remove"!==t&&this.trigger.apply(this,arguments),"change"===t?this._priorityQueue.change(o):void 0},e.prototype._addWithMerge=function(t){var o,e,r,n,i,s,l;for(n=[],s=0,l=t.length;l>s;s++)i=t[s],null!=(o=this.get(i.id))?(e=i.get("file"),r=i.get("fileInfo"),null!=e&&o.set({file:e}),null!=r&&o.set({fileInfo:r})):n.push(i);return n.length&&this.add(n),void 0},e}()}),e("MassUpload/FileLister",[],function(){var t;return t=function(){function t(t,o){this.doListFiles=t,this.callbacks=o,this.running=!1}return t.prototype.run=function(){var t,o=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(t=this.callbacks).onStart&&t.onStart(),this.doListFiles(function(t){var e;return"function"==typeof(e=o.callbacks).onProgress?e.onProgress(t):void 0},function(t){return o._onSuccess(t)},function(t){return o._onError(t)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop()},t.prototype._onError=function(t){return this.callbacks.onError(t),this._onStop()},t.prototype._onStop=function(){var t;return this.running=!1,"function"==typeof(t=this.callbacks).onStop?t.onStop():void 0},t}()}),e("MassUpload/FileUploader",["./FileInfo"],function(){var t;return t=function(){function t(t,o){this.doUpload=t,this.callbacks=o,this._file=null,this._abortCallback=null,this._aborting=!1}return t.prototype.run=function(t){var o,e=this;if(null!=this._file)throw"already running";return this._file=t,"function"==typeof(o=this.callbacks).onStart&&o.onStart(this._file),this._abortCallback=this.doUpload(t,function(o){return e._onProgress(t,o)},function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype.abort=function(){return this._file&&!this._aborting&&(this._aborting=!0,"function"==typeof this._abortCallback)?this._abortCallback():void 0},t.prototype._onProgress=function(t,o){var e;return"function"==typeof(e=this.callbacks).onProgress?e.onProgress(t,o):void 0},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this._file=null,this._abortCallback=null,this._aborting=!1,"function"==typeof(o=this.callbacks).onStop?o.onStop(t):void 0},t}()}),e("MassUpload/FileDeleter",[],function(){var t;return t=function(){function t(t,o){this.doDeleteFile=t,this.callbacks=null!=o?o:{},this.running=!1}return t.prototype.run=function(t){var o,e=this;if(this.running)throw"already running";return this.running=!0,"function"==typeof(o=this.callbacks).onStart&&o.onStart(t),this.doDeleteFile(t,function(){return e._onSuccess(t)},function(o){return e._onError(t,o)})},t.prototype._onSuccess=function(t){var o;return"function"==typeof(o=this.callbacks).onSuccess&&o.onSuccess(t),this._onStop(t)},t.prototype._onError=function(t,o){var e;return"function"==typeof(e=this.callbacks).onError&&e.onError(t,o),this._onStop(t)},t.prototype._onStop=function(t){var o;return this.running=!1,"function"==typeof(o=this.callbacks).onStop&&o.onStop(t),void 0},t}()}),e("MassUpload/State",[],function(){var t;return t=function(){function t(t){var o,e,r,n;null==t&&(t={}),this.loaded=null!=(o=t.loaded)?o:0,this.total=null!=(e=t.total)?e:0,this.status=null!=(r=t.status)?r:"waiting",this.errors=null!=(n=t.errors)?n:[]}return t.prototype._extend=function(o){var e,r,n,i;return new t({loaded:null!=(e=o.loaded)?e:this.loaded,total:null!=(r=o.total)?r:this.total,status:null!=(n=o.status)?n:this.status,errors:null!=(i=o.errors)?i:this.errors})},t.prototype.isComplete=function(){return this.total&&this.loaded===this.total&&"waiting"===this.status&&!this.errors.length&&!0||!1},t.prototype.withTotal=function(t){return this._extend({total:t})},t.prototype.withLoaded=function(t){return this._extend({loaded:t})},t.prototype.withStatus=function(t){return this._extend({status:t})},t.prototype.withAnError=function(t){var o;return o=this.errors.slice(0),o.push(t),this._extend({errors:o})},t.prototype.withoutAnError=function(t){var o,e;return e=this.errors.slice(0),o=e.indexOf(t),e.splice(o,1),this._extend({errors:e})},t}()}),e("MassUpload/UploadProgress",["backbone"],function(t){return t.Model.extend({defaults:{loaded:0,total:0},initialize:function(){var t;if(t=this.get("uploadCollection"),null==t)throw"Must initialize UploadProgress with `uploadCollection`, an UploadCollection";return this._idToLastKnownProgress={},this._updateAndStartListening()},_adjust:function(t,o){return this.set({loaded:this.get("loaded")+t,total:this.get("total")+o})},add:function(t){var o;return o=t.getProgress(),this._adjust(o.loaded,o.total),this._idToLastKnownProgress[t.id]=o},reset:function(t){var o,e,r,n,i,s,l,u;for(o=this._idToLastKnownProgress={},e=0,i=0,u=t.models,s=0,l=u.length;l>s;s++)r=u[s],n=r.getProgress(),o[r.id]=n,e+=n.loaded,i+=n.total;return this.set({loaded:e,total:i})},remove:function(t){var o;return o=t.getProgress(),this._adjust(-o.loaded,-o.total),this._idToLastKnownProgress[t.id]=o},change:function(t){var o,e;return e=this._idToLastKnownProgress[t.id],null!=e?(o=t.getProgress(),this._adjust(o.loaded-e.loaded,o.total-e.total),this._idToLastKnownProgress[t.id]=o):void 0},_updateAndStartListening:function(){var t,o,e,r,n;for(t=this.get("uploadCollection"),n=["add","remove","change","reset"],e=0,r=n.length;r>e;e++)o=n[e],this.listenTo(t,o,this[o]);return this.reset(t),void 0},inBatch:function(t){this.stopListening(this.get("uploadCollection"));try{return t()}finally{this._updateAndStartListening()}}})});var r={}.hasOwnProperty,n=function(t,o){function e(){this.constructor=t}for(var n in o)r.call(o,n)&&(t[n]=o[n]);return e.prototype=o.prototype,t.prototype=new e,t.__super__=o.prototype,t};e("MassUpload",["backbone","underscore","MassUpload/UploadCollection","MassUpload/FileLister","MassUpload/FileUploader","MassUpload/FileDeleter","MassUpload/State","MassUpload/UploadProgress"],function(t,o,e,r,i,s,l,u){var a;return a=function(t){function l(t){this._removedUploads=[],l.__super__.constructor.call(this,{},t)}return n(l,t),l.prototype.defaults=function(){return{status:"waiting",listFilesProgress:null,listFilesError:null,uploadProgress:null,uploadErrors:[]}},l.prototype.initialize=function(t,o){var r,n,i=this;return this._options=o,this.uploads=null!=(n=null!=o?o.uploads:void 0)?n:new e,this._uploadProgress=new u({uploadCollection:this.uploads}),r=function(){return i.set({uploadProgress:i._uploadProgress.pick("loaded","total")})},this.listenTo(this._uploadProgress,"change",r),r(),this.listenTo(this.uploads,"add-batch",this._onUploadBatchAdded),this.listenTo(this.uploads,"change",function(t){return i._onUploadChanged(t)}),this.listenTo(this.uploads,"reset",function(){return i._onUploadsReset()}),this.prepare()},l.prototype.prepare=function(){var t,o,e,n,l=this;return t=this._options,this.lister=null!=(o=null!=t?t.lister:void 0)?o:new r(t.doListFiles),this.lister.callbacks={onStart:function(){return l._onListerStart()},onProgress:function(t){return l._onListerProgress(t)},onSuccess:function(t){return l._onListerSuccess(t)},onError:function(t){return l._onListerError(t)},onStop:function(){return l._onListerStop()}},this.uploader=null!=(e=null!=t?t.uploader:void 0)?e:new i(t.doUploadFile),this.uploader.callbacks={onStart:function(t){return l._onUploaderStart(t)},onStop:function(t){return l._onUploaderStop(t)},onSuccess:function(t){return l._onUploaderSuccess(t)},onError:function(t,o){return l._onUploaderError(t,o)},onProgress:function(t,o){return l._onUploaderProgress(t,o)}},this.deleter=null!=(n=null!=t?t.deleter:void 0)?n:new s(t.doDeleteFile),this.deleter.callbacks={onStart:function(t){return l._onDeleterStart(t)},onSuccess:function(t){return l._onDeleterSuccess(t)},onError:function(t,o){return l._onDeleterError(t,o)},onStop:function(t){return l._onDeleterStop(t)}}},l.prototype.fetchFileInfosFromServer=function(){return this.lister.run()},l.prototype.retryListFiles=function(){return this.fetchFileInfosFromServer()},l.prototype.retryUpload=function(t){return t.set({error:null})},l.prototype.retryAllUploads=function(){return this.uploads.each(function(t){return t.set({error:null})})},l.prototype.addFiles=function(t){var o=this;return this._uploadProgress.inBatch(function(){return o.uploads.addFiles(t)})},l.prototype.removeUpload=function(t){return t.set({deleting:!0})},l.prototype.abort=function(){var t=this;return this.uploads.each(function(o){return t.removeUpload(o)}),this.uploads.reset(),this.prepare()},l.prototype._onListerStart=function(){return this.set({status:"listing-files",listFilesError:null})},l.prototype._onListerProgress=function(t){return this.set({listFilesProgress:t})},l.prototype._onListerSuccess=function(t){return this.uploads.addFileInfos(t),this._tick()},l.prototype._onListerError=function(t){return this.set({listFilesError:t,status:"listing-files-error"})},l.prototype._onListerStop=function(){},l.prototype._mergeUploadError=function(t,e,r){var n,i;return i=this.get("uploadErrors").slice(0),n=o.sortedIndex(i,{upload:t},function(t){return t.upload.id}),null==e?i.splice(n,0,{upload:t,error:r}):null==r?i.splice(n,1):i[n].error=r,this.set({uploadErrors:i})},l.prototype._onUploadBatchAdded=function(t){var o,e,r,n;for(r=0,n=t.length;n>r;r++)e=t[r],o=e.get("error"),null!=o&&this._mergeUploadError(e,null,o);return this._forceBestTick()},l.prototype._onUploadChanged=function(t){var o,e,r,n;return r=t.previousAttributes().error,n=t.get("error"),r!==n&&this._mergeUploadError(t,r,n),o=t.previousAttributes().deleting,e=t.get("deleting"),e&&!o&&this._removedUploads.push(t),this._forceBestTick()},l.prototype._onUploadsReset=function(){var t;return t=[],this.uploads.each(function(o){var e;return(e=o.get("error"))?t.push({upload:o,error:e}):void 0}),this.set({uploadErrors:t}),this._tick()},l.prototype._onUploaderStart=function(t){var o;return o=this.uploads.forFile(t),o.set({uploading:!0,error:null})},l.prototype._onUploaderStop=function(t){var o;return o=this.uploads.forFile(t),o.set({uploading:!1}),this._tick()},l.prototype._onUploaderProgress=function(t,o){var e;return e=this.uploads.forFile(t),e.updateWithProgress(o)},l.prototype._onUploaderError=function(t,o){var e;return e=this.uploads.forFile(t),e.set({error:o})},l.prototype._onUploaderSuccess=function(t){var o;return o=this.uploads.forFile(t),o.updateWithProgress({loaded:o.size(),total:o.size()})},l.prototype._onDeleterStart=function(){return this.set({status:"uploading"})},l.prototype._onDeleterSuccess=function(t){var o;return o=this.uploads.forFileInfo(t),this.uploads.remove(o)},l.prototype._onDeleterError=function(t,o){var e;return e=this.uploads.forFileInfo(t),e.set({error:o})},l.prototype._onDeleterStop=function(){return this._tick()},l.prototype._tick=function(){var t,o,e;return e=this.uploads.next(),this._currentUpload=e,null!=e&&(e.get("deleting")?this.deleter.run(e.get("fileInfo")):this.uploader.run(e.get("file"))),o=this.get("uploadErrors").length?"uploading-error":null!=e?"uploading":(t=this.get("uploadProgress"),t.loaded===t.total?"waiting":"waiting-error"),this.set({status:o})},l.prototype._forceBestTick=function(){var t;return t=this.uploads.next(),t!==this._currentUpload?this._currentUpload?this.uploader.abort():this._tick():void 0},l}(t.Model)}),o(["./MassUpload"],function(t){return window.MassUpload=t}),e("index",function(){})}(); \ No newline at end of file diff --git a/package.json b/package.json index 7817eb3..b45692d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/coffee/MassUpload.coffee b/src/coffee/MassUpload.coffee index dfebb04..905cdcc 100644 --- a/src/coffee/MassUpload.coffee +++ b/src/coffee/MassUpload.coffee @@ -228,26 +228,26 @@ 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 @@ -255,11 +255,11 @@ define [ @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) -> diff --git a/src/coffee/MassUpload/FileInfo.coffee b/src/coffee/MassUpload/FileInfo.coffee index 0d9e449..8a2eea0 100644 --- a/src/coffee/MassUpload/FileInfo.coffee +++ b/src/coffee/MassUpload/FileInfo.coffee @@ -12,7 +12,7 @@ define -> FileInfo.fromFile = (obj) -> new FileInfo( - obj.name, + obj.webkitRelativePath || obj.name, obj.lastModifiedDate, obj.size, 0 diff --git a/src/coffee/MassUpload/Upload.coffee b/src/coffee/MassUpload/Upload.coffee index 70f0136..bcf8c48 100644 --- a/src/coffee/MassUpload/Upload.coffee +++ b/src/coffee/MassUpload/Upload.coffee @@ -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: @@ -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 diff --git a/src/coffee/MassUpload/UploadCollection.coffee b/src/coffee/MassUpload/UploadCollection.coffee index b97be54..f9cd4c0 100644 --- a/src/coffee/MassUpload/UploadCollection.coffee +++ b/src/coffee/MassUpload/UploadCollection.coffee @@ -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 diff --git a/src/coffee/MassUpload/views/UploadCollection.coffee b/src/coffee/MassUpload/views/UploadCollection.coffee index 8b901c8..08e6cb1 100644 --- a/src/coffee/MassUpload/views/UploadCollection.coffee +++ b/src/coffee/MassUpload/views/UploadCollection.coffee @@ -65,7 +65,7 @@ define [ 'backbone', 'underscore', './humanReadableSize' ], (Backbone, _, humanR """) uploadTemplate: _.template(""" -
  • +
  • Delete Retry

    <%- upload.id %>

    @@ -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 @@ -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() @@ -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 @@ -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() diff --git a/src/js/MassUpload.js b/src/js/MassUpload.js index 113f5f3..c0b0482 100644 --- a/src/js/MassUpload.js +++ b/src/js/MassUpload.js @@ -244,7 +244,7 @@ define(['backbone', 'underscore', 'MassUpload/UploadCollection', 'MassUpload/Fil 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 @@ -253,7 +253,7 @@ define(['backbone', 'underscore', 'MassUpload/UploadCollection', 'MassUpload/Fil MassUpload.prototype._onUploaderStop = function(file) { var upload; - upload = this.uploads.get(file.name); + upload = this.uploads.forFile(file); upload.set({ uploading: false }); @@ -262,13 +262,13 @@ define(['backbone', 'underscore', 'MassUpload/UploadCollection', 'MassUpload/Fil 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 }); @@ -276,7 +276,7 @@ define(['backbone', 'underscore', 'MassUpload/UploadCollection', 'MassUpload/Fil 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() @@ -291,13 +291,13 @@ define(['backbone', 'underscore', 'MassUpload/UploadCollection', 'MassUpload/Fil 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 }); diff --git a/src/js/MassUpload/FileInfo.js b/src/js/MassUpload/FileInfo.js index 8598cfd..ae5079d 100644 --- a/src/js/MassUpload/FileInfo.js +++ b/src/js/MassUpload/FileInfo.js @@ -15,7 +15,7 @@ define(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; }); diff --git a/src/js/MassUpload/Upload.js b/src/js/MassUpload/Upload.js index fc670ce..e8fa8cf 100644 --- a/src/js/MassUpload/Upload.js +++ b/src/js/MassUpload/Upload.js @@ -1,4 +1,4 @@ -define(['backbone', './FileInfo'], function(Backbone, FileInfo) { +define(['underscore', 'backbone', './FileInfo'], function(_, Backbone, FileInfo) { var Upload; return Upload = (function() { Upload.prototype = Object.create(Backbone.Events); @@ -12,13 +12,13 @@ define(['backbone', './FileInfo'], function(Backbone, FileInfo) { }; 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; } diff --git a/src/js/MassUpload/UploadCollection.js b/src/js/MassUpload/UploadCollection.js index de76b28..3b75615 100644 --- a/src/js/MassUpload/UploadCollection.js +++ b/src/js/MassUpload/UploadCollection.js @@ -135,6 +135,14 @@ define(['backbone', './Upload'], function(Backbone, Upload) { 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() { diff --git a/src/js/MassUpload/views/UploadCollection.js b/src/js/MassUpload/views/UploadCollection.js index 3ea7990..2fe6acb 100644 --- a/src/js/MassUpload/views/UploadCollection.js +++ b/src/js/MassUpload/views/UploadCollection.js @@ -57,7 +57,7 @@ define(['backbone', 'underscore', './humanReadableSize'], function(Backbone, _, 'drop': '_onDrop' }, template: _.template("
      \n <%= collection.map(renderUpload).join('') %>\n
    \n
    \n \n \n
    "), - uploadTemplate: _.template("
  • \" data-cid=\"<%- upload.cid %>\">\n Delete\n Retry\n

    <%- upload.id %>

    \n
    \n \" max=\"<%= progress.total %>\">\n <%= humanReadableSize(progress.loaded) %> / <%= humanReadableSize(progress.total) %>\n <%= humanReadableSize(progress.total) %>\n <%- message %>\n
    \n
  • "), + uploadTemplate: _.template("
  • \" data-id=\"<%- upload.id %>\">\n Delete\n Retry\n

    <%- upload.id %>

    \n
    \n \" max=\"<%= progress.total %>\">\n <%= humanReadableSize(progress.loaded) %> / <%= humanReadableSize(progress.total) %>\n <%= humanReadableSize(progress.total) %>\n <%- message %>\n
    \n
  • "), initialize: function() { if (this.collection == null) { throw 'Must specify collection, an UploadCollection'; @@ -84,7 +84,7 @@ define(['backbone', 'underscore', './humanReadableSize'], function(Backbone, _, var $li, html, index, laterElement, lis; html = this._renderUpload(upload); $li = Backbone.$(html); - this.els[upload.cid] = liToEls($li); + this.els[upload.id] = liToEls($li); lis = this.ul.childNodes; index = (options != null ? options.index : void 0) || lis.length; if (index >= lis.length) { @@ -96,20 +96,20 @@ define(['backbone', 'underscore', './humanReadableSize'], function(Backbone, _, return void 0; }, _onRemove: function(upload) { - var cid, els; - cid = upload.cid; - els = this.els[cid]; + var els, id; + id = upload.id; + els = this.els[id]; if (els == null) { throw 'Element does not exist'; } this.ul.removeChild(els.li); - delete this.els[cid]; + delete this.els[id]; return void 0; }, _onChange: function(upload) { - var cid, els, progress, statusAndMessage; - cid = upload.cid; - els = this.els[cid]; + var els, id, progress, statusAndMessage; + id = upload.id; + els = this.els[id]; if (els != null) { progress = upload.getProgress(); statusAndMessage = uploadToStatusAndMessage(upload); @@ -135,9 +135,9 @@ define(['backbone', 'underscore', './humanReadableSize'], function(Backbone, _, this.ul = this.$el.children('ul.uploads')[0]; els = this.els = {}; this.$el.find('ul.uploads>li').each(function(li) { - var cid; - cid = li.getAttribute('data-cid'); - return els[cid] = liToEls(li); + var id; + id = li.getAttribute('data-id'); + return els[id] = liToEls(li); }); return this; }, @@ -153,9 +153,9 @@ define(['backbone', 'underscore', './humanReadableSize'], function(Backbone, _, } }, _eventToUpload: function(e) { - var cid; - cid = Backbone.$(e.target).closest('[data-cid]').attr('data-cid'); - return this.collection.get(cid); + var id; + id = Backbone.$(e.target).closest('[data-id]').attr('data-id'); + return this.collection.get(id); }, _onRetry: function(e) { var upload; diff --git a/test/coffee/MassUpload/FileInfoSpec.coffee b/test/coffee/MassUpload/FileInfoSpec.coffee index 6931632..4522e0e 100644 --- a/test/coffee/MassUpload/FileInfoSpec.coffee +++ b/test/coffee/MassUpload/FileInfoSpec.coffee @@ -39,3 +39,12 @@ define [ 'MassUpload/FileInfo' ], (FileInfo) -> it 'should have loaded=0', -> expect(subject.loaded).toEqual(0) + + it 'should use .webkitRelativePath if there is one', -> + subject = FileInfo.fromFile + name: 'name' + lastModifiedDaet: new Date() + size: 10000 + webkitRelativePath: 'foo/bar/name' + + expect(subject.name).toEqual('foo/bar/name') diff --git a/test/coffee/MassUpload/UploadCollectionSpec.coffee b/test/coffee/MassUpload/UploadCollectionSpec.coffee index 06ec180..1f0a637 100644 --- a/test/coffee/MassUpload/UploadCollectionSpec.coffee +++ b/test/coffee/MassUpload/UploadCollectionSpec.coffee @@ -121,6 +121,33 @@ define [ 'MassUpload/UploadCollection', 'underscore' ], (UploadCollection) -> expect(upload.attributes.file).toBe(file1) expect(upload.attributes.fileInfo).toBe(fileInfo1) + describe 'forFile', -> + it 'should search by webkitRelativePath if there is one', -> + file = + id: 'foo/bar.txt' + name: 'bar.txt' + webkitRelativePath: 'foo/bar.txt' + lastModifiedDate: date1 + size: 10000 + + subject.addFiles([ file ]) + expect(subject.forFile(file).file).toEqual(file) + + it 'should search by name if there is no webkitRelativePath', -> + file = + id: 'bar.txt' + name: 'bar.txt' + lastModifiedDate: date1 + size: 10000 + + subject.addFiles([ file ]) + expect(subject.forFile(file).file).toEqual(file) + + describe 'forFileInfo', -> + it 'should search by name', -> + subject.addFileInfos([ fileInfo1 ]) + expect(subject.forFileInfo(fileInfo1).fileInfo).toEqual(fileInfo1) + describe 'next', -> it 'should return null on empty collection', -> expect(subject.next()).toBe(null) diff --git a/test/coffee/MassUpload/UploadSpec.coffee b/test/coffee/MassUpload/UploadSpec.coffee index f14f6e7..126b41a 100644 --- a/test/coffee/MassUpload/UploadSpec.coffee +++ b/test/coffee/MassUpload/UploadSpec.coffee @@ -4,10 +4,11 @@ define [ 'MassUpload/Upload' ], (Upload) -> date2 = new Date('Mon, 12 Aug 2013 11:02:54 -0400') describe 'starting with a File', -> - file = { size: 10000, name: 'file.txt', lastModifiedDate: date1 } + file = undefined subject = undefined beforeEach -> + file = { size: 10000, name: 'file.txt', lastModifiedDate: date1 } subject = new Upload({ file: file }) it 'should have file, fileInfo, error, uploading and deleting attributes', -> @@ -20,6 +21,11 @@ define [ 'MassUpload/Upload' ], (Upload) -> it 'should have an id of the filename', -> expect(subject.id).toEqual('file.txt') + it 'should have an id of the webkitRelativePath if there is one', -> + file.webkitRelativePath = 'foo/bar/file.txt' + subject = new Upload({ file: file }) + expect(subject.id).toEqual('foo/bar/file.txt') + it 'should have no fileInfo or error', -> expect(subject.get('fileInfo')).toBe(null) expect(subject.get('error')).toBe(null) diff --git a/test/coffee/MassUploadSpec.coffee b/test/coffee/MassUploadSpec.coffee index bf0778f..19fb723 100644 --- a/test/coffee/MassUploadSpec.coffee +++ b/test/coffee/MassUploadSpec.coffee @@ -31,6 +31,9 @@ define [ 'MassUpload', 'backbone' ], (MassUpload, Backbone) -> FakeUploads = Backbone.Collection.extend model: FakeUpload + forFile: (f) -> @get(f.name) + forFileInfo: (fi) -> @get(fi.name) + next: -> @find((model) -> model.get('deleting') || (model.get('file')? && !model.get('error')?)) describe 'MassUpload', ->