diff --git a/lib/upload/Item.js b/lib/upload/Item.js index 3ea4510..e379688 100644 --- a/lib/upload/Item.js +++ b/lib/upload/Item.js @@ -13,6 +13,9 @@ Ext.define('Ext.ux.upload.Item', { STATUS_UPLOADED : 'uploaded', STATUS_UPLOAD_ERROR : 'uploaderror', + progress : null, + status : null, + config : { /** * @cfg {Object} fileApiObject (required) @@ -115,6 +118,20 @@ Ext.define('Ext.ux.upload.Item', { this.fireEvent('changestatus', this, status); }, + hasStatus : function(status) { + var itemStatus = this.getStatus(); + + if (Ext.isArray(status) && Ext.Array.contains(status, itemStatus)) { + return true; + } + + if (itemStatus === status) { + return true; + } + + return false; + }, + isReady : function() { return (this.status == this.STATUS_READY); }, diff --git a/lib/upload/Manager.js b/lib/upload/Manager.js index 000771c..d7befbe 100644 --- a/lib/upload/Manager.js +++ b/lib/upload/Manager.js @@ -15,7 +15,7 @@ Ext.define('Ext.ux.upload.Manager', { uploader : null, uploaderOptions : null, synchronous : true, - filenameEncoder: null + filenameEncoder : null }, DEFAULT_UPLOADER_CLASS : 'Ext.ux.upload.uploader.ExtJsUploader', @@ -83,7 +83,7 @@ Ext.define('Ext.ux.upload.Manager', { success : this.onUploadSuccess, failure : this.onUploadFailure, progress : this.onUploadProgress, - filenameEncoder: this.getFilenameEncoder() + filenameEncoder : this.getFilenameEncoder() }); this.uploader = Ext.create(uploaderClass, uploaderOptions); @@ -108,8 +108,6 @@ Ext.define('Ext.ux.upload.Manager', { this.startUpload(queue); - queue.reset(); - if (this.synchronous) { this.uploadQueueSync(queue); return; @@ -146,6 +144,8 @@ Ext.define('Ext.ux.upload.Manager', { }, startUpload : function(queue) { + queue.reset(); + this.uploadActive = true; this.currentQueue = queue; this.fireEvent('beforeupload', this, queue); @@ -174,7 +174,7 @@ Ext.define('Ext.ux.upload.Manager', { this.uploadNextItemSync(); } - if (this.currentQueue.isLast(item)) { + if (!this.currentQueue.existUploadingItems()) { this.finishUpload(); } }, diff --git a/lib/upload/Queue.js b/lib/upload/Queue.js index bfe2669..a87d686 100644 --- a/lib/upload/Queue.js +++ b/lib/upload/Queue.js @@ -76,24 +76,51 @@ Ext.define('Ext.ux.upload.Queue', { return this.getRange(); }, + /** + * Returns an array of items by the specified status. + * + * @param {String/Array} + * @return {Ext.ux.upload.Item[]} + */ + getItemsByStatus : function(status) { + var itemsByStatus = []; + + this.each(function(item, index, items) { + if (item.hasStatus(status)) { + itemsByStatus.push(item); + } + }); + + return itemsByStatus; + }, + /** * Returns an array of items, that have already been uploaded. * * @return {Ext.ux.upload.Item[]} */ getUploadedItems : function() { - var uploadedItems = []; - var num = this.getCount(); - var i; + return this.getItemsByStatus('uploaded'); + }, - for (i = 0; i < num; i++) { - var item = this.getAt(i); - if (item.isUploaded()) { - uploadedItems.push(item); - } - } + /** + * Returns an array of items, that have not been uploaded yet. + * + * @return {Ext.ux.upload.Item[]} + */ + getUploadingItems : function() { + return this.getItemsByStatus([ + 'ready', 'uploading' + ]); + }, - return uploadedItems; + /** + * Returns true, if there are items, that are currently being uploaded. + * + * @return {Boolean} + */ + existUploadingItems : function() { + return (this.getUploadingItems().length > 0); }, /**