← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20347: tracker-capture: some refactoring

 

------------------------------------------------------------
revno: 20347
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-24 15:11:48 +0200
message:
  tracker-capture: some refactoring
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.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/components/teiadd/tei-add-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.js	2015-09-24 12:19:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/teiadd/tei-add-controller.js	2015-09-24 13:11:48 +0000
@@ -111,6 +111,8 @@
             $scope.programs = response.programs;
             $scope.selectedProgram = response.selectedProgram;
         });
+        
+        $scope.selectedTei = {};
     }
     
     if(angular.isObject($scope.programs) && $scope.programs.length === 1){
@@ -280,6 +282,7 @@
             $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
         });
         
+        
         $scope.search( $scope.selectedSearchMode );        
     }; 
     
@@ -503,7 +506,7 @@
     $scope.attributesById = CurrentSelection.getAttributesById();
     
     var selections = CurrentSelection.get();
-    $scope.programs = selections.prs;    
+    $scope.programs = selections.prs;
     
     $scope.attributesById = CurrentSelection.getAttributesById();
     if(!$scope.attributesById){
@@ -526,17 +529,44 @@
             });
 
             CurrentSelection.setOptionSets($scope.optionSets);
-            
-            console.log('the option sets:  ', $scope.optionSets);
         });
     }
+    
+    var assignInheritance = function(){
+        if($scope.addingRelationship){
+            var mainTei = CurrentSelection.getRelationshipOwner();
+            angular.forEach($scope.attributes, function(att){
+                if(att.inherit && mainTei[att.id]){
+                    $scope.selectedTei[att.id] = mainTei[att.id];
+                }
+            });
+        }
+        else{
+            $scope.selectedTei = {};
+        }
+    };
+    
+    var getRules = function(){
+        $scope.allProgramRules = {constants: [], programIndicators: {}, programValidations: [], programVariables: [], programRules: []};
+        if( angular.isObject($scope.selectedProgramForRelative) && $scope.selectedProgramForRelative.id ){
+            TrackerRulesFactory.getRules($scope.selectedProgramForRelative.id).then(function(rules){                    
+                $scope.allProgramRules = rules;
+            });
+        }
+    };
   
+    
     if(angular.isObject($scope.programs) && $scope.programs.length === 1){
         $scope.selectedProgramForRelative = $scope.programs[0];
         AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){
             $scope.attributes = atts;
+            
+            assignInheritance();
+            
+            console.log('the tei:  ', $scope.selectedTei);
+            getRules();
         });
-    }  
+    }
     
     //watch for selection of program
     $scope.$watch('selectedProgramForRelative', function() {        
@@ -557,21 +587,8 @@
                     $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'RELATIONSHIP');
                 }
 
-                if($scope.addingRelationship){
-                    var mainTei = CurrentSelection.getRelationshipOwner();
-                    angular.forEach($scope.attributes, function(att){
-                        if(att.inherit && mainTei[att.id]){
-                            $scope.selectedTei[att.id] = mainTei[att.id];
-                        }
-                    });
-                }
-
-                $scope.allProgramRules = {constants: [], programIndicators: {}, programValidations: [], programVariables: [], programRules: []};
-                if( angular.isObject($scope.selectedProgramForRelative) && $scope.selectedProgramForRelative.id ){
-                    TrackerRulesFactory.getRules($scope.selectedProgramForRelative.id).then(function(rules){                    
-                        $scope.allProgramRules = rules;
-                    });
-                }
+                assignInheritance();
+                getRules();                
             });
         }
     });