dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42137
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21525: tracker-capture: display registration ou name in tei list
------------------------------------------------------------
revno: 21525
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-12-24 11:18:52 +0100
message:
tracker-capture: display registration ou name in tei list
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.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-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-12-23 09:29:34 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-12-24 10:18:52 +0000
@@ -1528,7 +1528,65 @@
};
})
-.service('TEIGridService', function(OrgUnitService, OptionSetService, CurrentSelection, DateUtils, $translate){
+/*Orgunit service for local db */
+.service('OuService', function($window, $q){
+
+ var indexedDB = $window.indexedDB;
+ var db = null;
+
+ var open = function(){
+ var deferred = $q.defer();
+
+ var request = indexedDB.open("dhis2ou");
+
+ request.onsuccess = function(e) {
+ db = e.target.result;
+ deferred.resolve();
+ };
+
+ request.onerror = function(){
+ deferred.reject();
+ };
+
+ return deferred.promise;
+ };
+
+ var get = function(uid){
+
+ var deferred = $q.defer();
+
+ if( db === null){
+ deferred.reject("DB not opened");
+ }
+ else{
+ var tx = db.transaction(["ou"]);
+ var store = tx.objectStore("ou");
+ var query = store.get(uid);
+
+ query.onsuccess = function(e){
+ if(e.target.result){
+ deferred.resolve(e.target.result);
+ }
+ else{
+ var t = db.transaction(["ouPartial"]);
+ var s = t.objectStore("ouPartial");
+ var q = s.get(uid);
+ q.onsuccess = function(e){
+ deferred.resolve(e.target.result);
+ };
+ }
+ };
+ }
+ return deferred.promise;
+ };
+
+ return {
+ open: open,
+ get: get
+ };
+})
+
+.service('TEIGridService', function(OuService, OptionSetService, CurrentSelection, DateUtils, $translate){
return {
format: function(grid, map, optionSets, invalidTeis){
@@ -1548,56 +1606,58 @@
var entityList = [];
var attributes = CurrentSelection.getAttributesById();
-
- angular.forEach(grid.rows, function(row){
- if(invalidTeis.indexOf(row[0]) === -1 ){
- var entity = {};
- var isEmpty = true;
-
- entity.id = row[0];
- entity.created = DateUtils.formatFromApiToUser( row[1] );
-
- entity.orgUnit = row[3];
- entity.type = row[4];
- entity.inactive = row[5] !== "" ? row[5] : false;
-
- OrgUnitService.get(row[3]).then(function(ou){
- if(ou && ou.name){
- entity.orgUnitName = ou.name;
- }
- });
-
- for(var i=6; i<row.length; i++){
- if(row[i] && row[i] !== ''){
- isEmpty = false;
- var val = row[i];
-
- if(attributes[grid.headers[i].name] &&
- attributes[grid.headers[i].name].optionSetValue &&
- optionSets &&
- attributes[grid.headers[i].name].optionSet &&
- optionSets[attributes[grid.headers[i].name].optionSet.id] ){
- val = OptionSetService.getName(optionSets[attributes[grid.headers[i].name].optionSet.id].options, val);
- }
- if(attributes[grid.headers[i].name] && attributes[grid.headers[i].name].valueType === 'date'){
- val = DateUtils.formatFromApiToUser( val );
- }
-
- entity[grid.headers[i].name] = val;
- }
- }
-
- if(!isEmpty){
- if(map){
- entityList[entity.id] = entity;
- }
- else{
- entityList.push(entity);
- }
- }
- }
+
+ OuService.open().then(function(){
+ angular.forEach(grid.rows, function(row){
+ if(invalidTeis.indexOf(row[0]) === -1 ){
+ var entity = {};
+ var isEmpty = true;
+
+ entity.id = row[0];
+ entity.created = DateUtils.formatFromApiToUser( row[1] );
+
+ entity.orgUnit = row[3];
+ entity.type = row[4];
+ entity.inactive = row[5] !== "" ? row[5] : false;
+
+ OuService.get(row[3]).then(function(ou){
+ if(ou && ou.n){
+ entity.orgUnitName = ou.n;
+ }
+ });
+
+ for(var i=6; i<row.length; i++){
+ if(row[i] && row[i] !== ''){
+ isEmpty = false;
+ var val = row[i];
+
+ if(attributes[grid.headers[i].name] &&
+ attributes[grid.headers[i].name].optionSetValue &&
+ optionSets &&
+ attributes[grid.headers[i].name].optionSet &&
+ optionSets[attributes[grid.headers[i].name].optionSet.id] ){
+ val = OptionSetService.getName(optionSets[attributes[grid.headers[i].name].optionSet.id].options, val);
+ }
+ if(attributes[grid.headers[i].name] && attributes[grid.headers[i].name].valueType === 'date'){
+ val = DateUtils.formatFromApiToUser( val );
+ }
+
+ entity[grid.headers[i].name] = val;
+ }
+ }
+
+ if(!isEmpty){
+ if(map){
+ entityList[entity.id] = entity;
+ }
+ else{
+ entityList.push(entity);
+ }
+ }
+ }
+ });
});
-
+
return {headers: attributes, rows: entityList, pager: grid.metaData.pager};
},