← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15441: event capture updated for changes in web-api

 

------------------------------------------------------------
revno: 15441
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-05-28 10:15:56 +0200
message:
  event capture updated for changes in web-api
added:
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/orgunitTreeSearch.js
modified:
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.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-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2014-04-18 17:56:57 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2014-05-28 08:15:56 +0000
@@ -60,10 +60,7 @@
         var promise = def.promise();
         
         promise = promise.then( getUserProfile );
-        promise = promise.then( getMetaPrograms );     
-        promise = promise.then( getPrograms );      
-        promise = promise.then( getProgramStages );
-        
+        promise = promise.then( getMetaData );        
         promise.done( function() {           
             selection.responseReceived();                      
         });           
@@ -165,108 +162,50 @@
     return def.promise(); 
 }
 
-
-function getMetaPrograms()
+function getMetaData()
 {
     var def = $.Deferred();
 
     $.ajax({
-        url: '../api/programs',
+        url: '../api/programs.json',
         type: 'GET',
-        data:'type=3&paging=false'
-    }).done( function(response) {             
-        localStorage[PROGRAMS_METADATA] = JSON.stringify(response.programs);           
-        def.resolve(response.programs);
-    });
-    
-    return def.promise(); 
-}
-
-function getPrograms( programs )
-{
-    if( !programs ){
-        return;
-    }
-    
-    var def = $.Deferred();
-    var promise = def.promise();
-
-    _.each( _.values( programs ), function ( program ) {        
-        promise = promise.then( getProgram( program.href ) );
-    });
-    
-    promise = promise.then(function() {
-        return $.Deferred().resolve( programs );
-    });
-    
-    def.resolve( programs );
-    
-    return promise;   
-}
-
-function getProgram( url )
-{   
-
-    return function() {
-        return $.ajax( {
-            url: url,
-            type: 'GET'
-        }).done( function( program ){     
+        data: 'paging=false&filter=type:eq:3&include=id,name,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,organisationUnits[id,name],programStages[id,name,description,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type, optionSet[id,name,options]]]]'
+    }).done( function(response) {   
+        var programs = [];
+        _.each(_.values(response.programs), function(p) {
+            programs.push({id: p.id, name: p.name});            
+            var programForStorage = _.clone(p); 
+            
+            //save program stages
+            programForStorage.programStages = [];
+            _.each(_.values(p.programStages), function(ps){
+                localStorage[ps.id] = JSON.stringify(ps);
+                programForStorage.programStages.push({id: ps.id, name: ps.name});
+            });
             
             var ou = {};
-            _.each(_.values( program.organisationUnits), function(o){
+            _.each(_.values(programForStorage.organisationUnits), function(o) {
                 ou[o.id] = o.name;
             });
-            
-            program.organisationUnits = ou;
-            
+
+            programForStorage.organisationUnits = ou;
+
             var ur = {};
-            _.each(_.values( program.userRoles), function(u){
+            _.each(_.values(programForStorage.userRoles), function(u) {
                 ur[u.id] = u.name;
             });
-            
-            program.userRoles = ur;
-          
-            localStorage[program.id] = JSON.stringify(program);
-        });
-    };
-}
-
-function getProgramStages( programs )
-{
-    if( !programs ){
-        return;
-    }
-    
-    var def = $.Deferred();
-    var promise = def.promise();
-
-    _.each( _.values( programs ), function ( program ) {  
-        program = JSON.parse( localStorage[program.id] );
-        _.each( _.values( program.programStages ), function( programStage ) {
-            promise = promise.then( getProgramStage( programStage.href ) );
-        });        
-    });
-    
-    promise = promise.then(function() {
-        return def.resolve();
-    });
-    
-    def.resolve();
-    
-    return promise; 
-}
-
-function getProgramStage( url )
-{
-    return function() {
-        return $.ajax( {
-            url: url,
-            type: 'GET'
-        }).done( function( programStage ){
-            localStorage[programStage.id] = JSON.stringify(programStage);
-        });
-    };
+
+            programForStorage.userRoles = ur;            
+            
+            localStorage[programForStorage.id] = JSON.stringify(programForStorage);
+            
+        });
+        
+        localStorage[PROGRAMS_METADATA] = JSON.stringify(programs);
+        def.resolve(response.programs);
+    });
+    
+    return def.promise(); 
 }
 
 function uploadLocalData()

=== added file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/orgunitTreeSearch.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/orgunitTreeSearch.js	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/orgunitTreeSearch.js	2014-05-28 08:15:56 +0000
@@ -0,0 +1,15 @@
+jQuery(document).ready(function() {
+    jQuery("#searchIcon").click(function() {
+        jQuery("#searchSpan").toggle();
+        jQuery("#searchField").focus();
+    });
+
+    jQuery("#searchField").autocomplete({
+        source: "../dhis-web-commons/ouwt/getOrganisationUnitsByName.action",
+        select: function(event, ui) {
+            jQuery("#searchField").val(ui.item.value);
+            selection.findByName();
+        }
+    });
+});
+