← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20769: Refactored file entry component to be syntactically in line with existing entry fields.

 

------------------------------------------------------------
revno: 20769
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-10-19 16:07:54 +0200
message:
  Refactored file entry component to be syntactically in line with existing entry fields.
modified:
  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/form.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css


--
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-19 10:37:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.fileresource.js	2015-10-19 14:07:54 +0000
@@ -1,19 +1,19 @@
 ( function ( $ ) {
     $.fn.fileEntryField = function() {
-        var $container = $( this );
-
-        var $field = $container.find( '.entryfileresource' );
-        var $displayField = $container.find( '.upload-field' );
-
-        var $button = $container.find( '.upload-button' );
-
-        var $fileInput = $container.find( 'input[type=file]' );
-
-        var $fileinfo = $container.find( '.upload-fileinfo' );
+        var $field = $( this );
+
+        var $input = $field.find( 'input[class="entryfileresource-input"]');
+        var $displayField = $field.find( '.upload-field' );
+
+        var $button = $field.find( '.upload-button' );
+
+        var $fileInput = $field.find( 'input[type=file]' );
+
+        var $fileinfo = $field.find( '.upload-fileinfo' );
         var $fileinfoName = $fileinfo.find( '.upload-fileinfo-name' );
         var $fileinfoSize = $fileinfo.find( '.upload-fileinfo-size' );
 
-        var $progress = $container.find( '.upload-progress' );
+        var $progress = $field.find( '.upload-progress' );
         var $progressBar = $progress.find( '.upload-progress-bar' );
         var $progressInfo = $progress.find( '.upload-progress-info' );
 
@@ -46,7 +46,7 @@
                     $fileinfoName.text( '' );
                     $fileinfoSize.text( '' );
                     $displayField.css( 'background-color', '' );
-                    $field.val( '' );
+                    $input.val( '' );
                     setButtonUpload();
                 },
                 error: function( data ) {
@@ -173,7 +173,7 @@
         };
 
         $( document ).on( dhis2.de.event.dataValuesLoaded, function() {
-            ( !$field.val() ) ? setButtonUpload() : setButtonDelete();
+            ( !$input.val() ) ? setButtonUpload() : setButtonDelete();
         } );
 
         $( document ).on( "dhis2.offline", disableField );
@@ -205,9 +205,9 @@
             },
             done: function( e, data ) {
                 var fileResource = data.result.response.fileResource;
-                $field.val( fileResource.id );
+                $input.val( fileResource.id );
 
-                saveFileResource( dataElementId, optionComboId, id, fileResource, function() {
+                saveFileResource( dataElementId, optionComboId, $input.attr( 'id' ), fileResource, function() {
                     onFileDataValueSavedSuccess( fileResource );
                 } );
             }

=== 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-10-19 10:37:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2015-10-19 14:07:54 +0000
@@ -639,7 +639,7 @@
         } );
     } );
 
-    $( '.entryfileresource-container' ).each( function()
+    $( '.entryfileresource' ).each( function()
     {
         $( this ).fileEntryField();
     } );
@@ -1537,12 +1537,12 @@
 }
 
 function clearFileEntryFields() {
-    var $containers = $( '.entryfileresource-container' );
-    $containers.find( '.upload-fileinfo-name' ).text( '' );
-    $containers.find( '.upload-fileinfo-size' ).text( '' );
+    var $fields = $( '.entryfileresource' );
+    $fields.find( '.upload-fileinfo-name' ).text( '' );
+    $fields.find( '.upload-fileinfo-size' ).text( '' );
 
-    $containers.find( '.upload-field' ).css( 'background-color', dhis2.de.cst.colorWhite );
-    $containers.find( '.entryfileresource' ).val( '' );
+    $fields.find( '.upload-field' ).css( 'background-color', dhis2.de.cst.colorWhite );
+    $fields.find( 'input' ).val( '' );
 }
 
 function getAndInsertDataValues()
@@ -1677,7 +1677,9 @@
             }
             else if ( $( fieldId ).attr( 'class' ) == 'entryfileresource' )
             {
-                $( fieldId ).val( value.val );
+                var $field = $( fieldId );
+
+                $field.find( 'input[class="entryfileresource-input"]' ).val( value.val );
 
                 var split = dhis2.de.splitFieldId( value.id );
 
@@ -1688,8 +1690,6 @@
                     'pe': $( '#selectedPeriodId' ).val()
                 };
 
-                var $container = $( '.entryfileresource-container[name=' + value.id + '-val]' );
-
                 var name = "", size = "";
 
                 if ( value.fileMeta )
@@ -1702,7 +1702,7 @@
                     name = i18n_loading_file_info_failed;
                 }
 
-                var $filename = $container.find( '.upload-fileinfo-name' );
+                var $filename = $field.find( '.upload-fileinfo-name' );
 
                 $( '<a>', {
                     text: name,
@@ -1711,7 +1711,7 @@
                     href: "../api/dataValues/files?" + $.param( dvParams )
                 } ).appendTo( $filename );
 
-                $container.find( '.upload-fileinfo-size' ).text( size );
+                $field.find( '.upload-fileinfo-size' ).text( size );
             }
             else 
             {

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2015-10-14 15:30:50 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2015-10-19 14:07:54 +0000
@@ -102,8 +102,8 @@
         <td><textarea name="entryfield" class="entryfield entryarea" id="${dataEntryId}" tabindex="${tabIndex}" #if( $greyedField || !$hasAccess ) disabled="disabled"#end></textarea></td>
     #elseif( "FILE_RESOURCE" == $dataElement.valueType )
         <td>
-            <div class="entryfileresource-container" name="${dataEntryId}">
-                <input class="entryfileresource" id="${dataEntryId}" tabindex="${tabIndex}" #if( $greyedField || !$hasAccess ) disabled="disabled"#end>
+            <div class="entryfileresource" id="${dataEntryId}" tabindex="${tabIndex}">
+                <input class="entryfileresource-input" id="input-${dataEntryId}" #if( $greyedField || !$hasAccess ) disabled="disabled" #end>
                 <div class="upload-field">
                     <div class="upload-fileinfo">
                         <div class="upload-fileinfo-size"></div>

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css	2015-10-14 11:46:39 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css	2015-10-19 14:07:54 +0000
@@ -257,7 +257,7 @@
 
 /* FileResource - uploads */
 
-.entryfileresource
+.entryfileresource-input
 {
     display: none; /* Hidden field */
 }