dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40775
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20743: Poll for StorageStatus.STORED after uploading file in data entry. Only enable link to file and de...
------------------------------------------------------------
revno: 20743
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-16 14:19:34 +0200
message:
Poll for StorageStatus.STORED after uploading file in data entry. Only enable link to file and delete-button once file has been confirmed stored by the server
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.fileresource.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.fileresource.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.fileresource.js 2015-10-14 22:01:58 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.fileresource.js 2015-10-16 12:19:34 +0000
@@ -115,24 +115,44 @@
};
var onFileDataValueSavedSuccess = function( fileResource ) {
- var name = fileResource.name, size = '(' + filesize( fileResource.contentLength ) + ')';
-
- //$fileinfoName.text( name );
-
- $('<a>', {
- text: name,
- title: name,
- href: createDownloadLink()
- } ).appendTo( $fileinfoName );
-
+ var name = fileResource.name;
+ var size = '(' + filesize( fileResource.contentLength ) + ')';
+
+ $fileinfoName.text( name );
$fileinfoSize.text( size );
$fileinfo.show();
- $progressBar.toggleClass( 'upload-progress-bar-complete' );
- $displayField.css( 'background-color', dhis2.de.cst.colorGreen );
-
+ $displayField.css( 'background-color', dhis2.de.cst.colorYellow );
resetAndHideProgress();
- setButtonDelete();
- $button.button( 'enable' );
+
+ function pollForFileResourceStored() {
+ $.ajax( {
+ url: '../api/fileResources/' + fileResource.id,
+ type: 'GET',
+ dataType: 'json'
+ } ).done( function( data, textStatus, jqXHR ) {
+ if ( data.storageStatus != 'STORED' ) {
+ setTimeout( pollForFileResourceStored, 4000 /* 4 sec polling time */ );
+ } else {
+ $fileinfoName.text( '' );
+
+ $( '<a>', {
+ text: name,
+ title: name,
+ href: '../api/dataValues/files?' + $.param( formData )
+ } ).appendTo( $fileinfoName );
+
+ $displayField.css( 'background-color', dhis2.de.cst.colorGreen );
+
+ setButtonDelete();
+ $button.button( 'enable' );
+ }
+ } ).fail( function( jqXHR, textStatus, errorThrown ) {
+ // Really shouldn't happen...
+ $displayField.css( 'background-color', dhis2.de.cst.colorRed );
+ throw 'Checking storage status of file failed: ' + errorThrown;
+ } );
+ }
+ setTimeout( pollForFileResourceStored, 1500 );
};
var updateProgress = function( loaded, total ) {
@@ -141,10 +161,6 @@
$progressInfo.text( percent + '%' );
};
- var createDownloadLink = function() {
- return "../api/dataValues/files?" + $.param( formData );
- };
-
var disableField = function() {
$button.button( 'disable' );
$displayField.toggleClass( 'upload-field-disabled', true );
@@ -182,7 +198,7 @@
},
fail: function( e, data ) {
console.error( data.errorThrown );
-
+ $displayField.css( 'background-color', dhis2.de.cst.colorRed );
setHeaderDelayMessage( i18n_file_upload_failed );
setButtonUpload();
},