← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10547: support for offline execution dates, allow removal etc. upload not supported yet.

 

------------------------------------------------------------
revno: 10547
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-15 14:57:01 +0700
message:
  support for offline execution dates, allow removal etc. upload not supported yet.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm
  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/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/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2013-04-13 07:25:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2013-04-15 07:57:01 +0000
@@ -114,6 +114,40 @@
 	</div>
 </div>
 
+<script id="offline-event-template" type="text/template">
+    <tr id="tr<%= programStageInstanceId %>" class="listRow">
+        <td><%= index %></td>
+        <td><%= executionDate %></td>
+        <td><%= organisationUnit %></td>
+
+        <td align="right" style="padding-right:20px;">
+            <a href="javascript:showUpdateEvent( '<%= programStageInstanceId %>' )" title="Data entry"><img src="images/data_entry.png" alt="Data entry"></a>
+            <a href="javascript:removeEvent( '<%= programStageInstanceId %>' )" title="Remove"><img src="../images/delete.png" alt="Remove"></a>
+        </td>
+    </tr>
+</script>
+
+<div id='offlineListDiv'>
+    <table class="listTable hidden">
+        <thead>
+        <tr>
+            <th colspan="4">Offline Events</th>
+        </tr>
+        </thead>
+        <thead>
+        <tr>
+            <th>#</th>
+            <th>Report date</th>
+            <th>Organisation Unit</th>
+            <th style="width:100px">Operations</th>
+        </tr>
+        </thead>
+
+        <tbody id="offlineEventList">
+        </tbody>
+    </table>
+</div>
+
 <div id='listDiv'></div>
 
 <div id='dataEntryInfor' class='hidden'>

=== 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-04-15 07:46:11 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm	2013-04-15 07:57:01 +0000
@@ -15,6 +15,7 @@
 ../dhis-web-commons/javascripts/jQuery/jquery.glob.js
 ../dhis-web-commons/javascripts/jQuery/jquery.date.js
 ../dhis-web-commons/javascripts/jQuery/jquery.tmpl.js
+../dhis-web-commons/javascripts/underscore.min.js
 ../dhis-web-commons/i18nJavaScript.action
 ../dhis-web-commons/javascripts/commons.js
 ../dhis-web-commons/javascripts/lists.js
@@ -81,6 +82,7 @@
 images/ajax-loader-circle.gif
 images/close.gif
 images/data_entry.png
+../images/delete.png
 images/flag-blue.png
 images/open.gif
 images/representative.png

=== 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-15 04:23:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-15 07:57:01 +0000
@@ -1,9 +1,9 @@
 var DAO = DAO || {};
 
-var PROGRAMS_STORE = 'anonymous_programs';
-var PROGRAM_STAGES_STORE = 'anonymous_programStages';
-var EXECUTION_DATES_STORE = 'anonymous_executionDates';
-var DATA_VALUES_STORE = 'anonymous_dataValues';
+var PROGRAMS_STORE = 'anonymousPrograms';
+var PROGRAM_STAGES_STORE = 'anonymousProgramStages';
+var EXECUTION_DATES_STORE = 'anonymousExecutionDates';
+var DATA_VALUES_STORE = 'anonymousDataValues';
 
 function initalizeProgramStages() {
     DAO.programStages = new dhis2.storage.Store( {name: PROGRAM_STAGES_STORE, adapter: 'dom-ss'}, function(store) {
@@ -49,7 +49,31 @@
 
 function initializeDataValues() {
     DAO.dataValues = new dhis2.storage.Store( {name: DATA_VALUES_STORE, adapter: 'dom'}, function(store) {
-        $( document ).trigger('dhis2.anonymous.dataValueInitialized');
+        $( document ).trigger('dhis2.anonymous.dataValuesInitialized');
+    });
+}
+
+function showOfflineEvents() {
+    DAO.executionDates.fetchAll(function(store, arr) {
+        var target = $( '#offlineEventList' );
+        target.children().remove();
+
+        if ( arr.length > 0 ) {
+            var template = $( '#offline-event-template' );
+
+            $.each( arr, function ( idx, event ) {
+                event.index = idx + 1;
+                var tmpl = _.template( template.html() );
+                var html = tmpl(event);
+                target.append( html );
+            } );
+
+            $( "#offlineListDiv table" ).removeClass( 'hidden' );
+        } else {
+            $( "#offlineListDiv table" ).addClass( 'hidden' );
+        }
+
+        $( document ).trigger('dhis2.anonymous.showOfflineEvents');
     });
 }
 
@@ -60,12 +84,12 @@
     } );
 
     $( "#orgUnitTree" ).one( "ouwtLoaded", function () {
-        // initialize the stores, and then try and add the data
         $( document ).one('dhis2.anonymous.programStagesInitialized', initializePrograms);
-        $( document ).one('dhis2.anonymous.programsInitialized', initializeExecutionDates);
-        $( document ).one('dhis2.anonymous.executionDatesInitialized', initializeDataValues);
+        $( document ).one('dhis2.anonymous.programsInitialized', showOfflineEvents);
 
         initalizeProgramStages();
+        initializeExecutionDates();
+        initializeDataValues();
     } );
 
     $( document ).bind( 'dhis2.online', function ( event, loggedIn ) {
@@ -543,24 +567,24 @@
         success: function ( html ) {
             hideById( 'dataEntryInfor' );
             setInnerHTML( 'listDiv', html );
-
-            var searchInfor = (listAll) ? i18n_list_all_events : i18n_search_events_by_dataelements;
-            setInnerHTML( 'searchInforTD', searchInfor );
-
-            if ( !listAll && jQuery( '#filterBtn' ).attr( "disabled" ) == "disabled" ) {
-                showById( 'minimized-advanced-search' );
-                hideById( 'advanced-search' );
-            }
-            else {
-                hideById( 'minimized-advanced-search' );
-                hideById( 'advanced-search' );
-                showById( 'filterBtn' );
-            }
-
-            showById( 'listDiv' );
-            hideById( 'loaderDiv' );
-        }
-    } );
+        }
+    } ).complete(function() {
+        var searchInfor = (listAll) ? i18n_list_all_events : i18n_search_events_by_dataelements;
+        setInnerHTML( 'searchInforTD', searchInfor );
+
+        if ( !listAll && jQuery( '#filterBtn' ).attr( "disabled" ) == "disabled" ) {
+            showById( 'minimized-advanced-search' );
+            hideById( 'advanced-search' );
+        }
+        else {
+            hideById( 'minimized-advanced-search' );
+            hideById( 'advanced-search' );
+            showById( 'filterBtn' );
+        }
+
+        showById( 'listDiv' );
+        hideById( 'loaderDiv' );
+    });
 }
 
 function getValueFormula( value ) {
@@ -593,7 +617,18 @@
 }
 
 function removeEvent( programStageId ) {
-    removeItem( programStageId, '', i18n_comfirm_delete_event, 'removeCurrentEncounter.action' );
+    var s = "" + programStageId;
+
+    if( s.indexOf("local") != -1) {
+        if ( confirm( i18n_comfirm_delete_event ) ) {
+            DAO.executionDates.remove(programStageId, function(store) {
+                // redisplay list
+                showOfflineEvents();
+            });
+        }
+    } else {
+        removeItem( programStageId, '', i18n_comfirm_delete_event, 'removeCurrentEncounter.action' );
+    }
 }
 
 function showUpdateEvent( programStageInstanceId ) {
@@ -618,6 +653,9 @@
     showById( 'selectDiv' );
     showById( 'searchDiv' );
     showById( 'listDiv' );
+    showById( 'offlineListDiv' );
+
+    showOfflineEvents();
     searchEvents( eval( getFieldValue( 'listAll' ) ) );
 }
 
@@ -630,6 +668,7 @@
     hideById( 'selectDiv' );
     hideById( 'searchDiv' );
     hideById( 'listDiv' );
+    hideById( 'offlineListDiv' );
     showById( 'programName' );
     hideById( 'actionDiv' );
     showById( 'dataEntryInfor' );
@@ -739,14 +778,12 @@
                     showWarningMessage( json.message );
                 }
             } ).fail( function () {
-                var data = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId);
-
                 if(programStageInstanceId == 0) {
-                    /*anonymousExecutionDates.keys(function(store, keys) {
+                    DAO.executionDates.keys(function(store, keys) {
                         var i = 100;
 
                         for(; i<10000; i++) {
-                            if( keys.indexOf(i) == -1 ) break;
+                            if( keys.indexOf("local" + i) == -1 ) break;
                         }
 
                         programStageInstanceId = "local"+i;
@@ -754,8 +791,10 @@
                         setFieldValue( 'programStageInstanceId', programStageInstanceId );
                         jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
                         showUpdateEvent( programStageInstanceId );
+
+                        var data = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId);
+                        DAO.executionDates.add(programStageInstanceId, data);
                     });
-                    */
                 } else {
                     // if we have a programStageInstanceId, just reuse that one
                     setFieldValue( 'programStageInstanceId', programStageInstanceId );
@@ -822,8 +861,10 @@
     if(executionDate)
         data.executionDate = executionDate;
 
-    if(organisationUnitId)
+    if(organisationUnitId) {
         data.organisationUnitId = organisationUnitId;
+        data.organisationUnit = organisationUnits[organisationUnitId].n;
+    }
 
     return data;
 }