← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10525: minor form js refactor

 

------------------------------------------------------------
revno: 10525
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-12 11:48:02 +0700
message:
  minor form js refactor
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.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-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-12 04:35:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-12 04:48:02 +0000
@@ -710,21 +710,13 @@
         },
 
         loadDataEntryForm: function( programStageId, programStageInstanceId, organisationUnitId ) {
-            $.ajax( {
-                url: 'dataentryform.action',
-                data: {
-                    programStageId: programStageId,
-                    programStageInstanceId: programStageInstanceId,
-                    organisationUnitId: organisationUnitId
-                },
-                dataType: 'html'
-            } ).done(function(data) {
+            loadFormAjax( programStageId, programStageInstanceId, organisationUnitId ).done(function ( data ) {
                 $( '#dataEntryFormDiv' ).html( data );
                 updateDataForm();
-            } ).fail(function() {
+            } ).fail( function () {
                 $( '#dataEntryFormDiv' ).html( "<div class='message message-info'>Unable to load form.</div>" );
                 hideById( 'loaderDiv' );
-            });
+            } );
         }
     }
 })();
@@ -769,3 +761,22 @@
         organisationUnitId: organisationUnitId
     }
 }
+
+function loadFormAjax( programStageId, programStageInstanceId, organisationUnitId ) {
+    var data = {};
+
+    if(programStageId)
+        data.programStageId = programStageId;
+
+    if(programStageInstanceId)
+        data.programStageInstanceId = programStageInstanceId;
+
+    if(organisationUnitId)
+        data.organisationUnitId = organisationUnitId;
+
+    return $.ajax( {
+        url: 'dataentryform.action',
+        data: data,
+        dataType: 'html'
+    } )
+}