← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20428: Minor refactoring

 

------------------------------------------------------------
revno: 20428
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-01 12:26:37 +0200
message:
  Minor refactoring
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.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.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2015-09-30 18:50:42 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2015-10-01 10:26:37 +0000
@@ -292,13 +292,13 @@
     valueSaver.save();
 }
 
-function saveFileResource( dataElementId, optionComboId, fieldId, fileResource )
+function saveFileResource( dataElementId, optionComboId, fieldId, fileResource, onSuccessCallback )
 {
     fieldId = '#' + fieldId;
 
     var periodId = $( '#selectedPeriodId' ).val();
 
-    var valueSaver = new FileResourceValueSaver( dataElementId, periodId, optionComboId, fileResource, fieldId, dhis2.de.cst.colorGreen );
+    var valueSaver = new FileResourceValueSaver( dataElementId, periodId, optionComboId, fileResource, fieldId, dhis2.de.cst.colorGreen, onSuccessCallback );
     valueSaver.save();
 }
 
@@ -402,18 +402,11 @@
     }
 }
 
-function FileResourceValueSaver( de, pe, co, fileResource, fieldId, resultColor )
+function FileResourceValueSaver( de, pe, co, fileResource, fieldId, resultColor, onSuccessCallback )
 {
     var valueSaver = new ValueSaver( de, pe, co, fileResource.id, fieldId, resultColor );
 
-    valueSaver.setAfterHandleSuccess( function() {
-        var name = fileResource.name, size = '(' + filesize( fileResource.contentLength ) + ')';
-        var $field = $( fieldId );
-
-        $field.find( '.upload-fileinfo-name' ).text( name );
-        $field.find( '.upload-fileinfo-size' ).text( size );
-        $field.find( '.upload-progress-bar' ).toggleClass( 'upload-progress-bar-complete' );
-    } );
+    valueSaver.setAfterHandleSuccess( onSuccessCallback );
 
     return valueSaver;
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2015-09-30 18:50:42 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2015-10-01 10:26:37 +0000
@@ -743,6 +743,18 @@
             $progress.hide();
         };
 
+        var onFileDataValueSavedSuccess = function( fileResource ) {
+            var name = fileResource.name, size = '(' + filesize( fileResource.contentLength ) + ')';
+
+            $fileinfoName.text( name );
+            $fileinfoSize.text( size );
+            $progressBar.toggleClass( 'upload-progress-bar-complete' );
+            $fileinfo.show();
+            resetAndHideProgress();
+            setButtonDelete();
+            $button.button( 'enable' );
+        };
+
         // Initialize button
         $button.button( {
             text: false,
@@ -785,11 +797,11 @@
             },
             done: function( e, data )
             {
-                saveFileResource( dataElementId, optionComboId, id, data.result.response.fileResource );
-                $fileinfo.show();
-                resetAndHideProgress();
-                setButtonDelete();
-                $button.button( 'enable' );
+                var fileResource = data.result.response.fileResource;
+
+                saveFileResource( dataElementId, optionComboId, id, fileResource, function() {
+                    onFileDataValueSavedSuccess( fileResource );
+                } );
             }
         } );
     } );