← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10693: don't show offline (anonymous) event table if we are online

 

------------------------------------------------------------
revno: 10693
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-26 13:47:09 +0700
message:
  don't show offline (anonymous) event table if we are online
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/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-24 12:13:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2013-04-26 06:47:09 +0000
@@ -115,7 +115,6 @@
     <tr id="tr<%= programStageInstanceId %>" class="listRow">
         <td><%= index %></td>
         <td><%= executionDate %></td>
-        <td><%= organisationUnit %></td>
 
         <td align="right" style="padding-right:20px;">
             <% if( !completed ) { %>
@@ -127,6 +126,12 @@
     </tr>
 </script>
 
+<script id="no-offline-event-template" type="text/template">
+    <tr class="listRow">
+        <td colspan="3">No offline events</td>
+    </tr>
+</script>
+
 <div id='offlineListDiv'>
     <table class="listTable hidden">
         <thead>
@@ -138,7 +143,6 @@
         <tr>
             <th>#</th>
             <th>Report date</th>
-            <th>Organisation Unit</th>
             <th style="width:100px">Operations</th>
         </tr>
         </thead>

=== 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-24 13:19:01 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-04-26 06:47:09 +0000
@@ -55,7 +55,7 @@
     });
 }
 
-function showOfflineEvents() {
+function updateOfflineEvents() {
     DAO.offlineData.fetchAll(function(store, arr) {
         var orgUnitId = selection.getSelected();
         var programId = $('#programId').val();
@@ -63,8 +63,13 @@
         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 template = $( '#offline-event-template' );
             var matched = false;
 
             $.each( arr, function ( idx, item ) {
@@ -72,26 +77,31 @@
 
                 if ( event.organisationUnitId == orgUnitId && event.programId == programId ) {
                     event.index = idx + 1;
-                    var tmpl = _.template( template.html() );
-                    var html = tmpl( event );
+                    var html = offline_template_compiled( event );
                     target.append( html );
                     matched = true;
                 }
             } );
 
-            if ( matched ) {
-                $( "#offlineListDiv table" ).removeClass( 'hidden' );
-            } else {
-                $( "#offlineListDiv table" ).addClass( 'hidden' );
+            if ( !matched ) {
+                target.append( no_offline_template_compiled() );
             }
         } else {
-            $( "#offlineListDiv table" ).addClass( 'hidden' );
+            target.append( no_offline_template_compiled() );
         }
 
         $( document ).trigger('dhis2.anonymous.checkOfflineEvents');
     });
 }
 
+function showOfflineEvents() {
+    $( "#offlineListDiv table" ).removeClass( 'hidden' );
+}
+
+function hideOfflineEvents() {
+    $( "#offlineListDiv table" ).addClass( 'hidden' );
+}
+
 var haveLocalData = false;
 
 function checkOfflineData(callback) {
@@ -111,7 +121,7 @@
     } ).done(function(json) {
         if ( json.response == 'success' ) {
             DAO.offlineData.remove( item.key, function ( store ) {
-                showOfflineEvents();
+                updateOfflineEvents();
                 searchEvents( eval( getFieldValue( 'listAll' ) ) );
             } );
         }
@@ -161,7 +171,7 @@
 
     $( "#orgUnitTree" ).one( "ouwtLoaded", function () {
         $( document ).one( 'dhis2.anonymous.programStagesInitialized', initializePrograms );
-        $( document ).one( 'dhis2.anonymous.programsInitialized', showOfflineEvents );
+        $( document ).one( 'dhis2.anonymous.programsInitialized', updateOfflineEvents );
         $( document ).one( 'dhis2.anonymous.checkOfflineEvents', checkOfflineData );
         $( document ).one( 'dhis2.anonymous.checkOfflineData', function () {
             dhis2.availability.startAvailabilityCheck();
@@ -191,6 +201,8 @@
                 $('#commentInput').removeAttr('disabled');
                 $('#validateBtn').removeAttr('disabled');
             });
+
+            hideOfflineEvents();
         }
         else {
             var form = [
@@ -205,6 +217,8 @@
 
             setHeaderMessage( form );
             ajax_login();
+
+            showOfflineEvents();
         }
     } );
 
@@ -213,6 +227,7 @@
         $('#commentInput').attr('disabled', true);
         $('#validateBtn').attr('disabled', true);
         disableFiltering();
+        showOfflineEvents();
     } );
 } );
 
@@ -289,7 +304,7 @@
         updateProgramList( programs );
     } );
 
-    showOfflineEvents();
+    updateOfflineEvents();
 }
 
 function updateProgramList( arr ) {
@@ -353,6 +368,7 @@
         enable( 'programId' );
         hideById( 'listDiv' );
         setFieldValue( 'searchText' );
+        updateOfflineEvents();
         return;
     }
 
@@ -381,7 +397,7 @@
             enable( 'addBtn' );
         });
 
-    showOfflineEvents();
+    updateOfflineEvents();
 }
 
 function dataElementOnChange( this_ ) {
@@ -733,7 +749,7 @@
         if ( confirm( i18n_comfirm_delete_event ) ) {
             DAO.offlineData.remove(programStageId, function(store) {
                 // redisplay list
-                showOfflineEvents();
+                updateOfflineEvents();
             });
         }
     } else {
@@ -766,7 +782,7 @@
     showById( 'listDiv' );
     showById( 'offlineListDiv' );
 
-    showOfflineEvents();
+    updateOfflineEvents();
     searchEvents( eval( getFieldValue( 'listAll' ) ) );
 }