← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10752: reverted 10751

 

------------------------------------------------------------
revno: 10752
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-03 11:18:04 +0700
message:
  reverted 10751
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm
  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/caseagg.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm


--
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/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm	2013-05-03 04:18:04 +0000
@@ -39,9 +39,11 @@
 ../dhis-web-commons/javascripts/dhis2/dhis2.select.js
 ../dhis-web-commons/javascripts/dhis2/dhis2.comparator.js
 ../dhis-web-commons/javascripts/dhis2/dhis2.availability.js
+../dhis-web-commons/javascripts/dhis2/dhis2.storage.ls.js
+../dhis-web-commons/javascripts/dhis2/dhis2.storage.ss.js
+../dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js
+../dhis-web-commons/javascripts/dhis2/dhis2.storage.memory.js
 ../dhis-web-commons/javascripts/dhis2/dhis2.storage.js
-../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js
-../dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js
 ../dhis-web-commons/javascripts/jQuery/jquery.cookie.js
 ../dhis-web-commons/javascripts/jQuery/jquery.validate.js
 ../dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm	2013-05-03 04:18:04 +0000
@@ -78,3 +78,6 @@
 #parse( "dhis-web-commons/loader/loader.vm" )
 
 <div id='caseAggregationResult' style='none'></div>
+
+<span id='message'></span>
+

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm	2013-05-03 04:18:04 +0000
@@ -36,11 +36,11 @@
 						#elseif($velocityCount==2)
 							#set($categoryoptioncomboid=$col)
 						#elseif($velocityCount==3)
+							#set($periodid=$col)
+						#elseif($velocityCount==4)
 							#set($organisationunitid=$col)
 						#elseif($velocityCount==$row.size())
 							#set($value=$col)
-						#elseif($velocityCount==6)
-							#set($periodid=$col)
 						#end
 						#set($item=$dataelementid + '_' + $categoryoptioncomboid + '_' + $periodid + '_' + $organisationunitid + '_' + $value)
 					#end

=== 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-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-05-03 04:18:04 +0000
@@ -1,74 +1,134 @@
 var DAO = DAO || {};
 
-var PROGRAMS_STORE = 'anonymousPrograms';
-var PROGRAM_STAGES_STORE = 'anonymousProgramStages';
-var OPTION_SET_STORE = 'optionSets';
-var USERNAME_STORE = 'usernames';
-var OFFLINE_DATA_STORE = 'anonymousOfflineData';
-
-function initalizeProgramStages() {
-    DAO.programStages = new dhis2.storage.Store( {name: PROGRAM_STAGES_STORE, adapter: 'dom-ss'}, function(store) {
-        $( document ).trigger('dhis2.anonymous.programStagesInitialized');
-    });
-}
-
-function initializePrograms() {
-    DAO.programs = new dhis2.storage.Store( {name: PROGRAMS_STORE, adapter: 'dom-ss'}, function ( store ) {
-        jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
-            var keys = _.keys( data.metaData.programs );
-            var objs = _.values( data.metaData.programs );
-
-            DAO.programs.addAll( keys, objs, function ( store ) {
-                var deferred = $.Deferred();
-                var promise = deferred.promise();
-
-                _.each( _.values(data.metaData.programs), function(el, idx) {
-                    var psid = el.programStages[0].id;
-
-                    promise = promise.pipe(function () {
-                        return loadProgramStage(psid);
-                    });
-                });
-
-                promise = promise.pipe(function() {
-                    loadOptionSets( data.metaData.optionSets, data.metaData.usernames );
-                });
-
-                deferred.resolve();
-
-                selection.setListenerFunction( organisationUnitSelected );
-                $( document ).trigger('dhis2.anonymous.programsInitialized');
+DAO.metaData = new dhis2.storage.Store( {
+    name: 'dhis2',
+    adapters: [ dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter ],
+    objectStores: [ 'programs', 'programStages', 'optionSets', 'usernames' ]
+} );
+
+DAO.offlineData = new dhis2.storage.Store( {
+    name: 'dhis2',
+    adapters: [ dhis2.storage.DomLocalStorageAdapter, dhis2.storage.InMemoryAdapter ],
+    objectStores: [ 'dataValues' ]
+} );
+
+DAO.metaData.open();
+DAO.offlineData.open();
+
+function loadPrograms() {
+    var def = $.Deferred();
+
+    $.ajax({
+        url: 'getProgramMetaData.action',
+        dataType: 'json'
+    } ).done(function(data) {
+        var programs = _.values( data.metaData.programs );
+        DAO.metaData.setAll('programs', programs ).then(function() {
+            def.resolve(data.metaData);
+        });
+    } ).always(function() {
+        def.resolve();
+    });
+
+    return def.promise();
+}
+
+function loadProgramStages( metaData ) {
+    if(!metaData) {
+        return;
+    }
+
+    var deferred1 = $.Deferred();
+    var deferred2 = $.Deferred();
+    var promise = deferred2.promise();
+
+    _.each( _.values(metaData.programs), function(el, idx) {
+        var psid = el.programStages[0].id;
+        var data = createProgramStage(psid);
+
+        promise = promise.then(function() {
+            return $.ajax( {
+                url: 'dataentryform.action',
+                data: data,
+                dataType: 'html'
+            } ).done(function(data) {
+                var obj = {};
+                obj.id = psid;
+                obj.form = data;
+                DAO.metaData.set('programStages', obj);
+            });
+        });
+    });
+
+    promise = promise.then(function() {
+        deferred1.resolve( metaData );
+    });
+
+    deferred2.resolve();
+
+    return deferred1.promise();
+}
+
+function loadOptionSets(metaData) {
+    if(!metaData) {
+        return;
+    }
+
+    var deferred1 = $.Deferred();
+    var deferred2 = $.Deferred();
+    var promise = deferred2.promise();
+
+    _.each( metaData.optionSets, function ( item, idx ) {
+        promise = promise.then( function () {
+            return $.ajax( {
+                url: 'getOptionSet.action?dataElementUid=' + item,
+                dataType: 'json'
+            } ).done( function ( data ) {
+                var obj = {};
+                obj.id = item;
+                obj.optionSet = data.optionSet;
+                DAO.metaData.set('optionSets', obj);
             } );
-        } ).fail( function () {
-            DAO.optionSets = new dhis2.storage.Store( {name: OPTION_SET_STORE, adapter: 'dom-ss'}, function() {} );
-            DAO.usernames = new dhis2.storage.Store( {name: USERNAME_STORE, adapter: 'dom-ss'}, function() {} );
-
-            selection.setListenerFunction( organisationUnitSelected );
-            $( document ).trigger('dhis2.anonymous.programsInitialized');
         } );
     } );
-}
-
-function initializeOfflineData() {
-    DAO.offlineData = new dhis2.storage.Store( {name: OFFLINE_DATA_STORE, adapter: 'dom'}, function(store) {
-        $( document ).trigger('dhis2.anonymous.offlineData');
+
+    if ( metaData.usernames ) {
+        promise = promise.then( function() {
+            return $.ajax( {
+                url: 'getUsernames.action',
+                dataType: 'json'
+            } ).done( function (data) {
+                var obj = {};
+                obj.id = 'usernames';
+                obj.usernames = data.usernames;
+                DAO.metaData.set('usernames', obj);
+            } )
+        } );
+    }
+
+    promise = promise.then(function() {
+        deferred1.resolve( metaData );
     });
+
+    deferred2.resolve();
+
+    return deferred1.promise();
 }
 
 function updateOfflineEvents() {
-    DAO.offlineData.fetchAll(function(store, arr) {
+    var no_offline_template = $( '#no-offline-event-template' );
+    var no_offline_template_compiled = _.template( no_offline_template.html() );
+
+    var offline_template = $( '#offline-event-template' );
+    var offline_template_compiled = _.template( offline_template.html() );
+
+    return DAO.offlineData.getAll( 'dataValues' ).done( function ( arr ) {
         var orgUnitId = selection.getSelected();
         var programId = $('#programId').val();
 
         var target = $( '#offlineEventList' );
         target.children().remove();
 
-        var no_offline_template = $( '#no-offline-event-template' );
-        var no_offline_template_compiled = _.template( no_offline_template.html() );
-
-        var offline_template = $( '#offline-event-template' );
-        var offline_template_compiled = _.template( offline_template.html() );
-
         if ( arr.length > 0 ) {
             var matched = false;
 
@@ -89,9 +149,7 @@
         } else {
             target.append( no_offline_template_compiled() );
         }
-
-        $( document ).trigger('dhis2.anonymous.checkOfflineEvents');
-    });
+    } );
 }
 
 function showOfflineEvents() {
@@ -105,12 +163,10 @@
 var haveLocalData = false;
 
 function checkOfflineData(callback) {
-    DAO.offlineData.fetchAll( function ( store, arr ) {
+    return DAO.offlineData.getAll( 'dataValues' ).done( function ( arr ) {
         haveLocalData = arr.length > 0;
-        $( document ).trigger('dhis2.anonymous.checkOfflineData');
-
         if(callback && typeof callback == 'function') callback(haveLocalData);
-    } );
+    });
 }
 
 function uploadOfflineData( item ) {
@@ -120,7 +176,7 @@
         data: JSON.stringify( item )
     } ).done(function(json) {
         if ( json.response == 'success' ) {
-            DAO.offlineData.remove( item.key, function ( store ) {
+            DAO.offlineData.delete( 'dataValues', item.id ).done( function () {
                 updateOfflineEvents();
                 searchEvents( eval( getFieldValue( 'listAll' ) ) );
             } );
@@ -131,7 +187,7 @@
 function uploadLocalData() {
     setHeaderWaitMessage( i18n_uploading_data_notification );
 
-    DAO.offlineData.fetchAll( function ( store, arr ) {
+    DAO.offlineData.getAll( 'dataValues' ).done( function ( arr ) {
         if(arr.length == 0) {
             setHeaderDelayMessage( i18n_sync_success );
             return;
@@ -151,7 +207,7 @@
         });
 
         deferred.resolve();
-    } );
+    });
 }
 
 function sync_failed_button() {
@@ -170,16 +226,21 @@
     } );
 
     $( "#orgUnitTree" ).one( "ouwtLoaded", function () {
-        $( document ).one( 'dhis2.anonymous.programStagesInitialized', initializePrograms );
-        $( document ).one( 'dhis2.anonymous.programsInitialized', updateOfflineEvents );
-        $( document ).one( 'dhis2.anonymous.checkOfflineEvents', checkOfflineData );
-        $( document ).one( 'dhis2.anonymous.checkOfflineData', function () {
+        var def = $.Deferred();
+        var promise = def.promise();
+        promise = promise.then(loadPrograms);
+        promise = promise.then(loadProgramStages);
+        promise = promise.then(loadOptionSets);
+        promise = promise.then(updateOfflineEvents);
+        promise = promise.then(checkOfflineData);
+        promise = promise.then(function() {
+            selection.setListenerFunction( organisationUnitSelected );
+
             dhis2.availability.startAvailabilityCheck();
             selection.responseReceived();
-        } );
+        });
 
-        initalizeProgramStages();
-        initializeOfflineData();
+        def.resolve();
     } );
 
     $( document ).bind( 'dhis2.online', function ( event, loggedIn ) {
@@ -292,7 +353,7 @@
     hideById( 'listDiv' );
     hideById( 'dataEntryInfor' );
 
-    DAO.programs.fetchAll( function ( store, arr ) {
+    DAO.metaData.getAll( 'programs' ).done( function (arr) {
         var programs = [];
 
         $.each( arr, function ( idx, item ) {
@@ -317,7 +378,7 @@
 
     for ( var i = 0; i < arr.length; i++ ) {
         jQuery( '#programId' ).append(
-            '<option value="' + arr[i].key
+            '<option value="' + arr[i].id
             + '" puid="' + arr[i].uid
             + '" programType="' + arr[i].type
             + '" psid="' + arr[i].programStages[0].id
@@ -747,10 +808,9 @@
 
     if( s.indexOf("local") != -1) {
         if ( confirm( i18n_comfirm_delete_event ) ) {
-            DAO.offlineData.remove(programStageId, function(store) {
-                // redisplay list
+            DAO.offlineData.delete( 'dataValues', programStageId ).always( function () {
                 updateOfflineEvents();
-            });
+            } );
         }
     } else {
         removeItem( programStageId, '', i18n_comfirm_delete_event, 'removeCurrentEncounter.action' );
@@ -910,7 +970,7 @@
                 }
             } ).fail( function () {
                 if(programStageInstanceId == 0) {
-                    DAO.offlineData.keys(function(store, keys) {
+                    DAO.offlineData.getKeys( 'dataValues' ).done( function ( keys ) {
                         var i = 100;
 
                         for(; i<10000; i++) {
@@ -924,10 +984,11 @@
                         showUpdateEvent( programStageInstanceId );
 
                         var data = {};
+                        data.id = programStageInstanceId;
                         data.executionDate = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId);
                         data.executionDate.completed = false;
 
-                        DAO.offlineData.add(programStageInstanceId, data);
+                        this.set( 'dataValues', data );
                     });
                 } else {
                     // if we have a programStageInstanceId, just reuse that one
@@ -1003,65 +1064,35 @@
     return data;
 }
 
+function createProgramStage( programStageId, programStageInstanceId, organisationUnitId ) {
+    var data = {};
+
+    if(programStageId)
+        data.programStageId = programStageId;
+
+    if(programStageInstanceId)
+        data.programStageInstanceId = programStageInstanceId;
+
+    if(organisationUnitId)
+        data.organisationUnitId = organisationUnitId;
+
+    return data;
+}
+
 function loadProgramStage( programStageId, programStageInstanceId, organisationUnitId, success, fail ) {
-    DAO.programStages.fetch(programStageId, function(store, arr) {
-        if ( arr.length > 0 ) {
-            if(success) success(arr[0]);
-        } else {
-            var data = {};
-
-            if(programStageId)
-                data.programStageId = programStageId;
-
-            if(programStageInstanceId)
-                data.programStageInstanceId = programStageInstanceId;
-
-            if(organisationUnitId)
-                data.organisationUnitId = organisationUnitId;
-
-            $.ajax( {
-                url: 'dataentryform.action',
-                data: data,
-                dataType: 'html'
-            } ).done(function(data) {
-                DAO.programStages.add(programStageId, data);
-                if(success) success(data);
-            } ).fail(function() {
-                if(fail) fail();
-            });
-        }
+    var data = createProgramStage( programStageId, programStageInstanceId, organisationUnitId );
+
+    DAO.metaData.get('programStages', programStageId ).done(function(obj) {
+        if(success) success(obj.form);
+    } ).fail(function() {
+        $.ajax( {
+            url: 'dataentryform.action',
+            data: data,
+            dataType: 'html'
+        } ).done(function(data) {
+            if(success) success(data);
+        } ).fail(function() {
+            if(fail) fail();
+        });
     });
 }
-
-function loadOptionSets(uids, usernames, success ) {
-    DAO.optionSets = new dhis2.storage.Store( {name: OPTION_SET_STORE, adapter: 'dom-ss'}, function ( store ) {
-        DAO.usernames = new dhis2.storage.Store( {name: USERNAME_STORE, adapter: 'dom-ss'}, function ( store ) {
-            var deferred = $.Deferred();
-            var promise = deferred.promise();
-
-            _.each( uids, function(item, idx) {
-                promise = promise.pipe( $.ajax( {
-                    url: 'getOptionSet.action?dataElementUid=' + item,
-                    dataType: 'json',
-                    success: function ( json ) {
-                        DAO.optionSets.add( item, json );
-                        if ( success && typeof success == 'function' ) success( json );
-                    }
-                } ) );
-            });
-
-            if ( usernames ) {
-                promise = promise.pipe( $.ajax( {
-                    url: 'getUsernames.action',
-                    dataType: 'json',
-                    success: function ( json ) {
-                        DAO.usernames.add( 'usernames', json.usernames );
-                        if ( success && typeof success == 'function' ) success( json );
-                    }
-                } ) );
-            }
-
-            deferred.resolve();
-        });
-    } );
-}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js	2013-05-03 04:18:04 +0000
@@ -69,7 +69,7 @@
 		, function(){
 			$( "#loaderDiv" ).hide();
 			showById('caseAggregationForm');
-			setHeaderDelayMessage(i18n_aggregate_successfully);
+			setMessage(i18n_aggregate_successfully);
 		});
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/dhis2.storage.anonymous.js	2013-05-03 04:18:04 +0000
@@ -1,3 +1,4 @@
+/*
 dhis2.storage.Store.plugin( 'online-anonymous-programs', (function () {
     return {
         call: function ( args, success, failure ) {
@@ -28,3 +29,4 @@
         }
     };
 })() );
+*/

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-05-03 04:18:04 +0000
@@ -297,22 +297,21 @@
             var dataValueKey = $( '#programStageInstanceId' ).val();
             var key = dataElementUid;
 
-            DAO.offlineData.fetch( dataValueKey, function ( store, arr ) {
-                if ( arr.length == 0 ) {
+            DAO.offlineData.get( 'dataValues', dataValueKey ).done( function ( obj ) {
+                if ( !obj ) {
                     markValue( ERROR );
                     window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
                     return;
                 }
 
-                var obj = arr[0];
-
                 if ( !obj.values ) {
                     obj.values = {};
                 }
 
+                obj.id = dataValueKey;
                 obj.values[key] = data;
 
-                store.add( dataValueKey, obj );
+                this.set( 'dataValues', obj );
                 markValue( resultColor );
             } );
         } else {
@@ -598,12 +597,13 @@
                         jQuery(".stage-object-selected").css('border-color', COLOR_GREEN);
                         jQuery(".stage-object-selected").css('background-color', COLOR_LIGHT_GREEN);
 
-                        DAO.offlineData.fetch( programStageInstanceId, function ( store, arr ) {
-                            if ( arr.length > 0 ) {
-                                var obj = arr[0];
-                                obj.executionDate.completed = true;
-                                DAO.offlineData.add( programStageInstanceId, obj );
+                        DAO.offlineData.get( 'dataValues', programStageInstanceId ).done( function ( obj ) {
+                            if ( !obj ) {
+                                return;
                             }
+
+                            obj.executionDate.completed = true;
+                            DAO.offlineData.set('dataValues', obj);
                         } );
 
                         var blocked = jQuery('#entryFormContainer [id=blockEntryForm]').val();
@@ -645,12 +645,13 @@
                 var programStageInstanceId = getFieldValue( 'programStageInstanceId' );
 
                 if ( window.DAO && window.DAO.offlineData ) {
-                    DAO.offlineData.fetch( programStageInstanceId, function ( store, arr ) {
-                        if ( arr.length > 0 ) {
-                            var obj = arr[0];
-                            obj.executionDate.completed = false;
-                            DAO.offlineData.add( programStageInstanceId, obj );
+                    DAO.offlineData.get( 'dataValues', programStageInstanceId ).done( function ( obj ) {
+                        if(!obj) {
+                            return;
                         }
+
+                        obj.executionDate.completed = false;
+                        DAO.offlineData.set( 'dataValues', obj );
                     } );
                 }
 
@@ -723,27 +724,23 @@
         $( "#programStageInstanceId" ).val( programStageInstanceId );
         $( "#entryFormContainer input[id='programStageInstanceId']" ).val( programStageInstanceId );
 
-        DAO.offlineData.fetch(programStageInstanceId, function(store, arr) {
-            if(arr.length > 0 ) {
-                var obj = arr[0];
-
-                if(obj.values !== undefined ) {
-                    _.each( _.keys(obj.values), function(key, idx) {
-                        var fieldId = getProgramStageUid() + '-' + key + '-val';
-                        var field = $('#' + fieldId);
-
-                        if ( field ) {
-                            field.val( decodeURI( obj.values[key].value ) );
-                        }
-                    });
-                }
+        DAO.offlineData.get( 'dataValues', programStageInstanceId ).done( function ( obj ) {
+            if(obj && obj.values !== undefined ) {
+                _.each( _.keys(obj.values), function(key, idx) {
+                    var fieldId = getProgramStageUid() + '-' + key + '-val';
+                    var field = $('#' + fieldId);
+
+                    if ( field ) {
+                        field.val( decodeURI( obj.values[key].value ) );
+                    }
+                });
             }
 
             if( always ) always();
 
             $('#commentInput').attr('disabled', true);
             $('#validateBtn').attr('disabled', true);
-        });
+        } );
     } else {
         return $.ajax({
             url: 'getProgramStageInstance.action',
@@ -907,10 +904,9 @@
 }
 
 function searchOptionSet( uid, query, success ) {
-    if(window.DAO !== undefined && window.DAO.optionSets !== undefined ) {
-        DAO.optionSets.fetch(uid, function(store, arr) {
-            if ( arr.length > 0 ) {
-                var obj = arr[0];
+    if(window.DAO !== undefined && window.DAO.metaData !== undefined ) {
+        DAO.metaData.get( 'optionSets', uid ).done( function ( obj ) {
+            if(obj) {
                 var options = [];
 
                 if(query == null || query == "") {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm	2013-05-03 04:18:04 +0000
@@ -5,6 +5,7 @@
 #set( $psize = $programs.size() )
 #foreach( $program in $programs )
 "${program.id}":{
+    "id":"${program.id}",
     "name":"$encoder.jsonEncode( ${program.displayName} )",
     "uid":"$encoder.jsonEncode( ${program.uid} )",
     "description":"$encoder.jsonEncode( ${program.description} )",

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm	2013-05-03 03:27:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm	2013-05-03 04:18:04 +0000
@@ -50,6 +50,8 @@
 <div id='addRelationshipDiv'></div> <!-- Add relationship -->
 <div id='migrationPatientDiv'></div> <!-- Migration Patient -->
 			
+<span id='message'></span>
+
 <script type="text/javascript">
 	var i18n_none = '$encoder.jsEscape( $i18n.getString( "none" ) , "'")';
 	var i18n_please_select_village = '[' + '$encoder.jsEscape( $i18n.getString( "please_select_village" ), "'")' + ']';