← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16745: if form doesnt exist in browser cache, load it directly from server

 

------------------------------------------------------------
revno: 16745
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-09-18 18:23:17 +0700
message:
  if form doesnt exist in browser cache, load it directly from server
modified:
  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/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-09-17 11:43:40 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-09-18 11:23:17 +0000
@@ -121,7 +121,7 @@
 dhis2.de.on = function( event, fn )
 {
     $( document ).off( event ).on( event, fn );
-}
+};
 
 var DAO = DAO || {};
 
@@ -2080,7 +2080,11 @@
             if( typeof form !== 'undefined' ) {
                 def.resolve( form.data );
             } else {
-                def.resolve( "A form with that ID is not available. Please clear browser cache and try again." );
+                dhis2.de.storageManager.loadForm( dataSetId ).done(function( data ) {
+                    def.resolve( data );
+                }).error(function() {
+                    def.resolve( "A form with that ID is not available. Please clear browser cache and try again." );
+                });
             }
         });
 
@@ -2121,6 +2125,24 @@
     };
 
     /**
+     * Loads a form directly from the server, does not try to save it in the
+     * browser (so that it doesn't interfere with any current downloads).
+     *
+     * @param dataSetId
+     * @returns {*}
+     */
+    this.loadForm = function( dataSetId )
+    {
+        return $.ajax({
+            url: 'loadForm.action',
+            data: {
+                dataSetId: dataSetId
+            },
+            dataType: 'text'
+        });
+    };
+
+    /**
      * Downloads the form for the data set with the given identifier from the
      * remote server and saves the form locally. Potential existing forms with
      * the same identifier will be overwritten. Updates the form version.