dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30480
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15466: event capture - trimmed data feteched from server using include/exclude feature of the web api
------------------------------------------------------------
revno: 15466
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2014-05-29 15:50:01 +0200
message:
event capture - trimmed data feteched from server using include/exclude feature of the web api
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-05-28 08:15:56 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2014-05-29 13:50:01 +0000
@@ -60,7 +60,9 @@
var promise = def.promise();
promise = promise.then( getUserProfile );
- promise = promise.then( getMetaData );
+ promise = promise.then( getMetaPrograms );
+ promise = promise.then( getPrograms );
+ promise = promise.then( getProgramStages );
promise.done( function() {
selection.responseReceived();
});
@@ -162,52 +164,115 @@
return def.promise();
}
-function getMetaData()
+function getMetaPrograms()
{
var def = $.Deferred();
$.ajax({
- url: '../api/programs.json',
+ url: '../api/programs',
type: 'GET',
- 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(programForStorage.organisationUnits), function(o) {
- ou[o.id] = o.name;
- });
-
- programForStorage.organisationUnits = ou;
-
- var ur = {};
- _.each(_.values(programForStorage.userRoles), function(u) {
- ur[u.id] = u.name;
- });
-
- programForStorage.userRoles = ur;
-
- localStorage[programForStorage.id] = JSON.stringify(programForStorage);
-
- });
-
- localStorage[PROGRAMS_METADATA] = JSON.stringify(programs);
+ 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.id ) );
+ });
+
+ promise = promise.then(function() {
+ return $.Deferred().resolve( programs );
+ });
+
+ def.resolve( programs );
+
+ return promise;
+}
+
+function getProgram( id )
+{
+
+ return function() {
+ return $.ajax( {
+ url: '../api/programs.json?filter=id:eq:' + id +'&include=id,name,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,organisationUnits[id,name],programStages[id,name]',
+ type: 'GET'
+ }).done( function( response ){
+
+ _.each( _.values( response.programs ), function ( program ) {
+
+ var ou = {};
+ _.each(_.values( program.organisationUnits), function(o){
+ ou[o.id] = o.name;
+ });
+
+ program.organisationUnits = ou;
+
+ var ur = {};
+ _.each(_.values( program.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.id ) );
+ });
+ });
+
+ promise = promise.then(function() {
+ return def.resolve();
+ });
+
+ def.resolve();
+
+ return promise;
+}
+
+function getProgramStage( id )
+{
+ return function() {
+ return $.ajax( {
+ url: '../api/programStages.json?filter=id:eq:' + id +'&include=id,name,description,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id,name,options]]]',
+ type: 'GET'
+ }).done( function( response ){
+ _.each( _.values( response.programStages ), function( programStage ) {
+ localStorage[programStage.id] = JSON.stringify(programStage);
+ });
+ });
+ };
+}
+
function uploadLocalData()
{
if ( !dhis2.ec.storageManager.hasLocalData() )