diff options
Diffstat (limited to 'www/js/importer.js')
-rw-r--r-- | www/js/importer.js | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/www/js/importer.js b/www/js/importer.js index cbea665..7e72150 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -247,7 +247,7 @@ Rdxport.Importer.prototype.getUploadByCartNumber = function(cartNumber) { } var upload = null; $.each(this.uploads, function(index, currentUpload) { - if (currentUpload.cartNumber === cartNumber) { + if (parseInt(currentUpload.cartNumber) === parseInt(cartNumber)) { upload = currentUpload; return false; //break; } @@ -274,7 +274,7 @@ Rdxport.Importer.prototype.getUploadsByCartNumber = function(cartNumber) { return null; } return this.uploads.filter(function (currentUpload) { - return currentUpload.cartNumber === cartNumber; + return currentUpload.cartNumber === parseInt(cartNumber); }); }; @@ -300,10 +300,12 @@ Rdxport.Upload = function(fileOrsourceUri, group, groupView, cartNumber, useMeta this.filename = fileOrsourceUri.name; this.sourceUri = 'attachment://' + fileOrsourceUri.size + '/' + this.filename; } + this.title = this.filename; this.group = group; this.groupView = groupView; this.cartNumber = cartNumber; + this.cutNumber = null; this.useMetadata = useMetadata; this.uploadId = null; @@ -332,37 +334,44 @@ Rdxport.Upload.prototype.onerror = function(error) { console.log('error'); console.log(error); - var file = { - cartNumber: this.cartNumber - }; - this.importFileUploadError(file, 500, error); + this.importFileUploadError(500, error); }; Rdxport.Upload.prototype.onmessage = function(event) { var data = $.parseJSON(event.data); this.uploadId = data.ID; - var file = { - cartNumber: this.cartNumber - }; switch (data.TYPE.toLowerCase()) { case Rdxport.Importer.TYPE_ERROR: + this.importFileUploadError(data.RESPONSE_CODE, data.ERROR_STRING); + break; + case Rdxport.Importer.TYPE_ACK: console.log(data); - this.importFileUploadError(file, data.RESPONSE_CODE, data.ERROR_STRING); + this.groupView.uploadProgress(this); break; case Rdxport.Importer.TYPE_PROGRESS: + console.log(data); this.uploadprogress.current = data.CURRENT; this.uploadprogress.total = data.TOTAL; this.uploadprogress.progress = data.PROGRESS; this.uploadprogress.progress_step = data.PROGRESS_STEP; this.uploadprogress.progress_step_name = data.PROGRESS_STEP_NAME; - this.groupView.uploadProgress(this, file); + if (data.CART_NUMBER) { + this.cartNumber = data.CART_NUMBER; + } + if (data.CUT_NUMBER) { + this.cutNumber = data.CUT_NUMBER; + } + if (data.TITLE) { + this.title = data.TITLE; + } + this.groupView.uploadProgress(this); break; case Rdxport.Importer.TYPE_DONE: console.log(data); if(data.RESPONSE_CODE < 400) { this.importFileUploadSuccess(); } else { - this.importFileUploadError(file, data.RESPONSE_CODE, data.ERROR_STRING); + this.importFileUploadError(data.RESPONSE_CODE, data.ERROR_STRING); } break; } @@ -421,7 +430,7 @@ Rdxport.Upload.prototype.import = function() { sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.cartNumber + '/' + self.filename; sendOptions.CART_NUMBER = parseInt(self.cartNumber); } else if (self.group instanceof Rdxport.Musicpool) { - sendOptions.REFERENCE_ID = self.group.groupName + '/' + '/' + self.filename; + sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.filename; sendOptions.MUSIC_POOL_GROUP = self.group.groupName; } console.log(sendOptions); @@ -454,15 +463,16 @@ Rdxport.Upload.prototype.reconnect = function(id, reference) { Rdxport.Upload.prototype.close = function() { this.webSocket.close(); - this.group.fetchCarts(); importer.removeUpload(this); + this.group.fetchCarts(); }; Rdxport.Upload.prototype.cancel = function() { this.webSocket.send(JSON.stringify({ COMMAND: 'cancel' })); this.webSocket.close(); - this.group.fetchCarts(); + // todo: only do this when i get "done" importer.removeUpload(this); + this.group.fetchCarts(); }; Rdxport.Upload.prototype.importFileUploadSuccess = function() { @@ -470,9 +480,10 @@ Rdxport.Upload.prototype.importFileUploadSuccess = function() { this.group.fetchCarts(); }; -Rdxport.Upload.prototype.importFileUploadError = function(file, status, errorString) { +Rdxport.Upload.prototype.importFileUploadError = function(status, errorString) { + this.uploadprogress.progress_step = 99; // makes isUploading return false var self = this; - this.groupView.uploadError(this, file, status, errorString, function() { - self.cancel(); + this.groupView.uploadError(this, status, errorString, function() { + self.close(); }); }; |