← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17711: some refactoring work

 

------------------------------------------------------------
revno: 17711
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-16 16:44:11 +0100
message:
  some refactoring work
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/column-modal.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js
  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/styles/style.css
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/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-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-12-15 14:00:36 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-12-16 15:44:11 +0000
@@ -315,8 +315,8 @@
             }
         });
 
-        modalInstance.result.then(function (eventGridColumns) {
-            $scope.eventGridColumns = eventGridColumns;
+        modalInstance.result.then(function (gridColumns) {
+            $scope.eventGridColumns = gridColumns;
         }, function () {
         });
     };

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css	2014-11-19 12:00:31 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css	2014-12-16 15:44:11 +0000
@@ -57,8 +57,8 @@
     cursor: default;
 }
 
-.update-error {
-    background-color: #ff6600;
+.input-error {
+    background-color: #fffe8c;
 }
 
 .update-success {

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/column-modal.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/column-modal.html	2014-08-19 11:45:47 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/column-modal.html	2014-12-16 15:44:11 +0000
@@ -4,7 +4,7 @@
 
 <div class="modal-body page">   
     <table class="listTable dhis2-table-striped-border">
-        <tr ng-repeat="eventGridColumn in eventGridColumns">
+        <tr ng-repeat="eventGridColumn in gridColumns">
             <td>
                 <span ng-if="eventGridColumn.id !== 'comment' && eventGridColumn.id !== 'uid'">{{eventGridColumn.name}}</span>
                 <span ng-if="eventGridColumn.id === 'comment' || eventGridColumn.id === 'uid'">{{eventGridColumn.name | translate}}</span>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-12-09 23:24:16 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-12-16 15:44:11 +0000
@@ -39,42 +39,46 @@
     $scope.selectedTei;    
     
     if($scope.selectedTeiId){
-        //Fetch the selected entity
-        TEIService.get($scope.selectedTeiId).then(function(data){
-            $scope.selectedTei = data;
+        
+        //get option sets
+        $scope.optionSets = [];
+        OptionSetService.getAll().then(function(optionSets){
             
-            //get the entity type
-            TEService.get($scope.selectedTei.trackedEntity).then(function(te){
-                $scope.trackedEntity = te;
-                
-                ProgramFactory.getAll().then(function(programs){  
-                    
-                    $scope.programs = []; 
-                    //get programs valid for the selected ou and tei
-                    angular.forEach(programs, function(program){
-                        if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id) &&
-                           program.trackedEntity.id === $scope.selectedTei.trackedEntity){
-                            $scope.programs.push(program);
-                        }
-
-                        if($scope.selectedProgramId && program.id === $scope.selectedProgramId){
-                            $scope.selectedProgram = program;
-                        }
-                    });
-                    
-                    $scope.optionSets = [];
-                    OptionSetService.getAll().then(function(optionSets){
-                        angular.forEach(optionSets, function(optionSet){                            
-                            $scope.optionSets[optionSet.id] = optionSet;
-                        });
+            angular.forEach(optionSets, function(optionSet){                            
+                $scope.optionSets[optionSet.id] = optionSet;
+            });
+        
+            //Fetch the selected entity
+            TEIService.get($scope.selectedTeiId, $scope.optionSets).then(function(response){
+                $scope.selectedTei = response.data;
+
+                //get the entity type
+                TEService.get($scope.selectedTei.trackedEntity).then(function(te){                    
+                    $scope.trackedEntity = te;
+
+                    ProgramFactory.getAll().then(function(programs){  
+
+                        $scope.programs = [];
+                        
+                        //get programs valid for the selected ou and tei
+                        angular.forEach(programs, function(program){
+                            if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id) &&
+                               program.trackedEntity.id === $scope.selectedTei.trackedEntity){
+                                $scope.programs.push(program);
+                            }
+
+                            if($scope.selectedProgramId && program.id === $scope.selectedProgramId){
+                                $scope.selectedProgram = program;
+                            }
+                        }); 
                         
                         //broadcast selected items for dashboard controllers
                         CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: null, optionSets: $scope.optionSets});
-                        $scope.broadCastSelections();  
+                        $scope.broadCastSelections();                        
                     });
-                });
-            });            
-        });      
+                });            
+            });    
+        });
     }    
     
     //listen for any change to program selection

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-12-08 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2014-12-16 15:44:11 +0000
@@ -6,6 +6,7 @@
                 storage,
                 ProgramStageFactory,
                 DHIS2EventFactory,
+                OptionSetService,
                 ModalService,
                 DialogService,
                 CurrentSelection,
@@ -335,29 +336,33 @@
     
     $scope.saveDatavalue = function(prStDe){
         
-        $scope.currentElement = {id: prStDe.dataElement.id, saved: false};
-        
         //check for input validity
         $scope.dataEntryOuterForm.submitted = true;        
         if( $scope.dataEntryOuterForm.$invalid ){            
             return false;
         }
          
-        //input is valid
+        //input is valid        
+        var value = $scope.currentEvent[prStDe.dataElement.id];
+        
         $scope.updateSuccess = false;
-        var value = $scope.currentEvent[prStDe.dataElement.id];        
+        
+        $scope.currentElement = {id: prStDe.dataElement.id, saved: false};
+                
         if(!angular.isUndefined(value)){
             if(prStDe.dataElement.type === 'date'){                    
                 value = DateUtils.formatFromUserToApi(value);
             }
             if(prStDe.dataElement.type === 'string'){                    
-                if(prStDe.dataElement.optionSet && $scope.optionSets.optionCodesByName[  '"' + value + '"']){                        
-                    value = $scope.optionSets.optionCodesByName[  '"' + value + '"'];                                                      
+                if(prStDe.dataElement.optionSet && $scope.optionSets[prStDe.dataElement.optionSet.id] &&  $scope.optionSets[prStDe.dataElement.optionSet.id].options ) {
+                    value = OptionSetService.getCode($scope.optionSets[prStDe.dataElement.optionSet.id].options, value);
                 }                    
             }
 
             if($scope.currentEventOriginal[prStDe.dataElement.id] !== value){
+
                 
+        
                 var ev = {  event: $scope.currentEvent.event,
                             orgUnit: $scope.currentEvent.orgUnit,
                             program: $scope.currentEvent.program,

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html	2014-10-22 11:46:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/default-form.html	2014-12-16 15:44:11 +0000
@@ -31,19 +31,19 @@
                         </div>                        
                         <div ng-switch-when="string">                            
                             <div ng-if="prStDe.dataElement.optionSet">
-                                <div ng-if="!selectedProgram.dataEntryMethod || optionSets.optionSets[prStDe.dataElement.optionSet.id].options.length >= 7">
+                                <div ng-if="!selectedProgram.dataEntryMethod || optionSets[prStDe.dataElement.optionSet.id].options.length >= 7">
                                     <input type="text"
                                         ng-class='getInputNotifcationClass(prStDe.dataElement.id,false)'
                                         ng-model="currentEvent[prStDe.dataElement.id]" 
                                         ng-required={{prStDe.compulsory}} 
-                                        typeahead="option.name as option.name for option in optionSets.optionSets[prStDe.dataElement.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                        typeahead="option.name as option.name for option in optionSets[prStDe.dataElement.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                         typeahead-open-on-focus 
                                         typeahead-editable="false"
                                         ng-blur="saveDatavalue(prStDe)" 
                                         name="foo"/>
                                     <span ng-show="dataEntryOuterForm.submitted && dataEntryInnerForm.foo.$invalid || !currentEvent[prStDe.dataElement.id] && currentElement.id === prStDe.dataElement.id" class="error">{{'invalid'| translate}}</span>
                                 </div>
-                                <div ng-if="selectedProgram.dataEntryMethod && optionSets.optionSets[prStDe.dataElement.optionSet.id].options.length < 7">
+                                <div ng-if="selectedProgram.dataEntryMethod && optionSets[prStDe.dataElement.optionSet.id].options.length < 7">
                                     <label>                                        
                                         <input type="radio"
                                             ng-class='getInputNotifcationClass(prStDe.dataElement.id,true)'
@@ -53,7 +53,7 @@
                                             ng-change="saveDatavalue(prStDe)" 
                                             value=""> {{'no_value' | translate}}<br>                                       
                                     </label><br>
-                                    <span ng-repeat="option in optionSets.optionSets[prStDe.dataElement.optionSet.id].options">
+                                    <span ng-repeat="option in optionSets[prStDe.dataElement.optionSet.id].options">
                                         <label>
                                             <input type="radio"
                                                 ng-class='getInputNotifcationClass(prStDe.dataElement.id,true)'

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-12-08 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2014-12-16 15:44:11 +0000
@@ -19,7 +19,6 @@
     
     //listen for the selected items
     $scope.$on('selectedItems', function(event, args) {   
-        //programs for enrollment        
         $scope.enrollments = [];
         $scope.showEnrollmentDiv = false;
         $scope.showReSchedulingDiv = false;
@@ -27,11 +26,13 @@
         $scope.hasEnrollmentHistory = false;
         $scope.selectedEnrollment = null;
         $scope.newEnrollment = {};
+        
         var selections = CurrentSelection.get();
         $scope.selectedTei = angular.copy(selections.tei); 
         $scope.selectedEntity = selections.te;
         $scope.selectedProgram = selections.pr;
         $scope.optionSets = selections.optionSets;
+        
         $scope.programExists = args.programExists;
         
         $scope.selectedOrgUnit = storage.get('SELECTED_OU');
@@ -78,10 +79,6 @@
             if($scope.selectedEnrollment){//enrollment exists
                 $scope.selectedEnrollment.dateOfIncident = DateUtils.formatFromApiToUser($scope.selectedEnrollment.dateOfIncident);
                 $scope.selectedEnrollment.dateOfEnrollment = DateUtils.formatFromApiToUser($scope.selectedEnrollment.dateOfEnrollment);
-                
-                /*angular.forEach($scope.selectedProgram.programStages, function(stage){                    
-                    stage.dueDate = EventUtils.getEventDueDate(stage, $scope.selectedEnrollment);
-                });*/
             }
             else{//prepare for possible enrollment
                 AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
@@ -144,47 +141,10 @@
         
         //form is valid, continue with enrollment
         var tei = angular.copy($scope.selectedTei);
-        tei.attributes = [];
-        
-        //existing attributes
-        angular.forEach($scope.selectedTei.attributes, function(attribute){
-            if(!angular.isUndefined(attribute.value)){
-                if(attribute.type === 'date'){
-                    attribute.value = DateUtils.formatFromUserToApi(attribute.value);
-                }
-                if(attribute.type === 'optionSet' && $scope.optionSets.optionCodesByName[  '"' + attribute.value + '"']){   
-                    attribute.value = $scope.optionSets.optionCodesByName[  '"' + attribute.value + '"'];
-                }
-                tei.attributes.push({attribute: attribute.attribute, value: attribute.value});
-            } 
-        });
         
         //get enrollment attributes and their values - new attributes because of enrollment
-        angular.forEach($scope.attributesForEnrollment, function(attribute){
-            
-            if(attribute.valueType === 'trueOnly'){ 
-                if(!attribute.value){
-                    tei.attributes.push({attribute: attribute.id, value: ''});
-                    $scope.formEmpty = false;                    
-                }
-                else{
-                    tei.attributes.push({attribute: attribute.id, value: 'true'});
-                    $scope.formEmpty = false;
-                }
-            }            
-            else{
-                var val = attribute.value;
-                if(!angular.isUndefined(val) && val !== ''){
-                    if(attribute.valueType === 'date'){
-                        val = DateUtils.formatFromUserToApi(val);
-                    }
-                    if(attribute.valueType === 'optionSet' && $scope.optionSets.optionCodesByName[  '"' + val + '"']){   
-                        val = $scope.optionSets.optionCodesByName[  '"' + val + '"'];
-                    }                    
-                    $scope.formEmpty = false;
-                    tei.attributes.push({attribute: attribute.id, value: val});
-                }                
-            }
+        angular.forEach($scope.attributesForEnrollment, function(attribute){            
+            tei.attributes.push({attribute: attribute.id, value: attribute.value, type: attribute.valueType, displayName: attribute.name});                        
         });
         
         console.log('Finally:  ', tei);
@@ -195,7 +155,7 @@
                             dateOfIncident: $scope.newEnrollment.dateOfIncident ? DateUtils.formatFromUserToApi($scope.newEnrollment.dateOfIncident) : DateUtils.formatFromUserToApi($scope.newEnrollment.dateOfEnrollment)
                         };
                         
-        TEIService.update(tei).then(function(updateResponse){
+        TEIService.update(tei, $scope.optionSets).then(function(updateResponse){            
             
             if(updateResponse.status === 'SUCCESS'){
                 //registration is successful, continue for enrollment               
@@ -211,23 +171,7 @@
                     }
                     
                     //update tei attributes without refetching from the server
-                    angular.forEach($scope.attributesForEnrollment, function(attribute){
-                        $scope.selectedTei.attributes.push({attribute: attribute.id, value: attribute.value, type: attribute.valueType, displayName: attribute.name});
-                        /*var val = attribute.value;
-                        if(!angular.isUndefined(val)){
-                            if(attribute.valueType === 'number' && !isNaN(parseInt(val))){
-                                val = parseInt(val);
-                            }
-                            if(attribute.valueType === 'date'){
-                                val = DateUtils.formatFromApiToUser(val);
-                            }
-                            if(attribute.valueType === 'optionSet' && $scope.optionSets.optionNamesByCode[  '"' + attribute.value + '"']){   
-                                attribute.value = $scope.optionSets.optionNamesByCode[  '"' + attribute.value + '"'];
-                            } 
-                            
-                            $scope.selectedTei.attributes.push({attribute: attribute.id, value: attribute.value, type: attribute.valueType, displayName: attribute.name});
-                        }*/
-                    });
+                    $scope.selectedTei.attributes = tei.attributes;
                     
                     enrollment.enrollment = enrollmentResponse.reference;
                     $scope.selectedEnrollment = enrollment;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-10-22 11:46:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html	2014-12-16 15:44:11 +0000
@@ -136,17 +136,17 @@
                                         </select>                                        
                                     </div>
                                     <div ng-switch-when="optionSet">
-                                        <div ng-if="!selectedProgram.dataEntryMethod || optionSets.optionSets[attribute.optionSet.id].options.length >= 7">
+                                        <div ng-if="!selectedProgram.dataEntryMethod || optionSets[attribute.optionSet.id].options.length >= 7">
                                             <input type="text" 
                                                name="foo"
                                                class="form-control"
                                                ng-model="attribute.value"                                                 
-                                               typeahead="option.name as option.name for option in optionSets.optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                               typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                                typeahead-open-on-focus
                                                typeahead-editable="false"
                                                ng-required="attribute.mandatory"/>
                                         </div>
-                                        <div ng-if="selectedProgram.dataEntryMethod && optionSets.optionSets[attribute.optionSet.id].options.length < 7">
+                                        <div ng-if="selectedProgram.dataEntryMethod && optionSets[attribute.optionSet.id].options.length < 7">
                                             <label>                                        
                                                 <input type="radio"
                                                     name={{attribute.id}}
@@ -154,7 +154,7 @@
                                                     ng-model="attribute.value"
                                                     value=""> {{'no_value' | translate}}<br>                                       
                                             </label><br>
-                                            <span ng-repeat="option in optionSets.optionSets[attribute.optionSet.id].options">
+                                            <span ng-repeat="option in optionSets[attribute.optionSet.id].options">
                                                 <label>
                                                     <input type="radio"
                                                         name={{attribute.id}}

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js	2014-12-08 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js	2014-12-16 15:44:11 +0000
@@ -78,8 +78,7 @@
                     $scope.formEmpty = false;
                 }
                 tei.attributes.push({attribute: attribute.attribute, value: val});
-            }           
-             
+            }             
         });
         
         if($scope.formEmpty){

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html	2014-10-22 11:46:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html	2014-12-16 15:44:11 +0000
@@ -60,7 +60,7 @@
                                            name="foo"
                                            class="form-control"
                                            ng-model="attribute.value"                                                 
-                                           typeahead="option.name as option.name for option in optionSets.optionSets[attributes[attribute.attribute].optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                           typeahead="option.name as option.name for option in optionSets[attributes[attribute.attribute].optionSet.id].options | filter:$viewValue | limitTo:20" 
                                            typeahead-open-on-focus                                           
                                            ng-disabled="!editProfile" ng-required="attribute.mandatory"/>
                                 </span>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2014-12-15 14:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2014-12-16 15:44:11 +0000
@@ -21,11 +21,12 @@
     //listen for the selected entity       
     $scope.$on('dashboardWidgets', function(event, args) { 
         $scope.selections = CurrentSelection.get();
+        $scope.optionSets = $scope.selections.optionSets;
         $scope.selectedTei = angular.copy($scope.selections.tei);        
         $scope.trackedEntity = $scope.selections.te;
         $scope.selectedEnrollment = $scope.selections.enrollment;
         $scope.selectedProgram = $scope.selections.pr;
-        console.log('the program leading to relationship is:  ', $scope.selectedProgram);
+        
         if($scope.selectedProgram && $scope.selectedProgram.relationshipText){
             $scope.addRelationshipLabel = $scope.selectedProgram.relationshipText;
         }
@@ -105,19 +106,7 @@
     //Selection
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
     $scope.optionSets = selections.optionSets;
-    
-    //format tei values
-    $scope.selectedTeiForDisplay = angular.copy($scope.selectedTei);
-    angular.forEach($scope.selectedTeiForDisplay.attributes, function(attribute){
-        if(!angular.isUndefined(attribute.value) && attribute.value !== ''){
-            if(attribute.type === 'date'){   
-                attribute.value = DateUtils.formatFromApiToUser(attribute.value);
-            }
-            if(attribute.type === 'optionSet' && $scope.optionSets.optionNamesByCode[  '"' + attribute.value + '"']){   
-                attribute.value = $scope.optionSets.optionNamesByCode[  '"' + attribute.value + '"'];
-            }
-        }
-    });    
+    $scope.selectedTeiForDisplay = angular.copy($scope.selectedTei);       
    
     ProgramFactory.getAll().then(function(programs){
         $scope.programs = [];

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-12-08 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-12-16 15:44:11 +0000
@@ -69,7 +69,7 @@
                         $scope.optionSets.optionSets[optionSet.id] = optionSet;
                     });
                 });
-            }            
+            }
             $scope.loadPrograms($scope.selectedOrgUnit);                                
         }
     });
@@ -327,7 +327,6 @@
     };
     
     $scope.showHideColumns = function(){
-        
         $scope.hiddenGridColumns = 0;
         
         angular.forEach($scope.gridColumns, function(gridColumn){

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2014-12-15 14:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2014-12-16 15:44:11 +0000
@@ -2,278 +2,4 @@
 
 /* Directives */
 
-var trackerCaptureDirectives = angular.module('trackerCaptureDirectives', []);
-
-/*.directive('inputValidator', function() {
-    
-    return {
-        require: 'ngModel',
-        link: function (scope, element, attrs, ctrl) {  
-
-            ctrl.$parsers.push(function (value) {
-                return parseFloat(value || '');
-            });
-        }
-    };   
-})
-
-.directive('selectedOrgUnit', function($timeout, storage) {        
-
-    return {        
-        restrict: 'A',        
-        link: function(scope, element, attrs){
-            
-            //once ou tree is loaded, start meta-data download
-            $(function() {
-                dhis2.ou.store.open().done( function() {
-                    selection.load();
-                    $( "#orgUnitTree" ).one( "ouwtLoaded", function(event, ids, names) {
-                        console.log('Finished loading orgunit tree');                        
-                        downloadMetaData();
-                    });
-                });
-            });
-            
-            //listen to user selection, and inform angular         
-            selection.setListenerFunction( setSelectedOu, true );
-            
-            function setSelectedOu( ids, names ) {
-                var ou = {id: ids[0], name: names[0]};
-                $timeout(function() {
-                    scope.selectedOrgUnit = ou;
-                    scope.$apply();
-                });
-            }
-        }  
-    };
-})
-
-.directive('d2CustomForm', function($compile) {
-    return{ 
-        restrict: 'E',
-        link: function(scope, elm, attrs){            
-            scope.$watch('customForm', function(){
-                elm.html(scope.customForm);
-                $compile(elm.contents())(scope);
-            });
-        }
-    };
-})
-
-.directive('d2PopOver', function($compile, $templateCache){
-    return {        
-        restrict: 'EA',
-        link: function(scope, element, attrs){
-            var content = $templateCache.get("note.html");
-            content = $compile(content)(scope);
-            var options = {
-                    content: content,
-                    placement: 'bottom',
-                    trigger: 'hover',
-                    html: true,
-                    title: scope.title               
-                };            
-            $(element).popover(options);
-        },
-        scope: {
-            content: '=',
-            title: '@details',
-            template: "@template"
-        }
-    };
-})
-
-.directive('sortable', function() {        
-
-    return {        
-        restrict: 'A',        
-        link: function(scope, element, attrs){
-            element.sortable({
-                connectWith: ".connectedSortable",
-                placeholder: "ui-state-highlight",
-                tolerance: "pointer",
-                handle: '.handle'
-            });
-        }  
-    };
-})
-
-.directive('d2ContextMenu', function(ContextMenuSelectedItem) {
-        
-    return {        
-        restrict: 'A',
-        link: function(scope, element, attrs){
-            var contextMenu = $("#contextMenu");                   
-            
-            element.click(function (e) {
-                var selectedItem = $.parseJSON(attrs.selectedItem);
-                ContextMenuSelectedItem.setSelectedItem(selectedItem);
-                
-                var menuHeight = contextMenu.height();
-                var menuWidth = contextMenu.width();
-                var winHeight = $(window).height();
-                var winWidth = $(window).width();
-
-                var pageX = e.pageX;
-                var pageY = e.pageY;
-
-                contextMenu.show();
-
-                if( (menuWidth + pageX) > winWidth ) {
-                  pageX -= menuWidth;
-                }
-
-                if( (menuHeight + pageY) > winHeight ) {
-                  pageY -= menuHeight;
-
-                  if( pageY < 0 ) {
-                      pageY = e.pageY;
-                  }
-                }
-                
-                contextMenu.css({
-                    left: pageX,
-                    top: pageY
-                });
-
-                return false;
-            });
-            
-            contextMenu.on("click", "a", function () {                    
-                contextMenu.hide();
-            });
-
-            $(document).click(function () {                                        
-                contextMenu.hide();
-            });
-        }     
-    };
-})
-
-.directive('d2Date', function(DateUtils, CalendarService, storage, $parse) {
-    return {
-        restrict: 'A',
-        require: 'ngModel',        
-        link: function(scope, element, attrs, ctrl) {    
-            
-            var calendarSetting = CalendarService.getSetting();            
-            var dateFormat = 'yyyy-mm-dd';
-            if(calendarSetting.keyDateFormat === 'dd-MM-yyyy'){
-                dateFormat = 'dd-mm-yyyy';
-            }            
-            
-            var minDate = $parse(attrs.minDate)(scope), 
-                maxDate = $parse(attrs.maxDate)(scope),
-                calendar = $.calendars.instance(calendarSetting.keyCalendar);
-            
-            element.calendarsPicker({
-                changeMonth: true,
-                dateFormat: dateFormat,
-                yearRange: '-120:+30',
-                minDate: minDate,
-                maxDate: maxDate,
-                calendar: calendar, 
-                duration: "fast",
-                showAnim: "",
-                renderer: $.calendars.picker.themeRollerRenderer,
-                onSelect: function(date) {
-                    //scope.date = date;                    
-                    ctrl.$setViewValue(date);
-                    $(this).change();                    
-                    scope.$apply();
-                }
-            })
-            .change(function() {
-                
-                var rawDate = this.value;
-                var convertedDate = DateUtils.format(this.value);
-                
-                console.log('raw date:  ', rawDate);
-                console.log('cnv date:  ', convertedDate);
-
-                if(rawDate != convertedDate){
-                    console.log('It is invalid...');
-                    scope.invalidDate = true;
-                    ctrl.$setViewValue(this.value);                                   
-                    ctrl.$setValidity('foo', false);                    
-                    scope.$apply();     
-                }
-                else{
-                    scope.invalidDate = false;
-                    ctrl.$setViewValue(this.value);                                   
-                    ctrl.$setValidity('foo', true);                    
-                    scope.$apply();     
-                }
-            });
-        }      
-    };   
-})
-
-.directive('blurOrChange', function() {
-    
-    return function( scope, elem, attrs) {
-        elem.calendarsPicker({
-            onSelect: function() {
-                scope.$apply(attrs.blurOrChange);
-                $(this).change();                                        
-            }
-        }).change(function() {
-            scope.$apply(attrs.blurOrChange);
-        });
-    };
-})
-
-.directive('d2TypeaheadValidation', function() {
-    
-    return {
-        require: 'ngModel',
-        restrict: 'A',
-        link: function (scope, element, attrs, ctrl) {
-            element.bind('blur', function () {                
-                if(ctrl.$viewValue && !ctrl.$modelValue){
-                    ctrl.$setViewValue();
-                    ctrl.$render();
-                }                
-            });
-        }
-    };
-})
-
-.directive('typeaheadOpenOnFocus', function ($compile) {
-  return {
-    require: ['typeahead', 'ngModel'],
-    link: function (scope, element, attr, ctrls) {        
-        element.bind('focus', function () {          
-            ctrls[0].getMatchesAsync(ctrls[1].$viewValue);
-            scope.$watch(attr.ngModel, function(value) {
-                if(value === '' || angular.isUndefined(value)){
-                    ctrls[0].getMatchesAsync(ctrls[1].$viewValue);
-                }                
-            });
-      });
-    }
-  };
-})
-
-.directive('serversidePaginator', function factory() {
-    return {
-        restrict: 'E',
-        controller: function ($scope, Paginator) {
-            $scope.paginator = Paginator;
-        },
-        templateUrl: '../dhis-web-commons/paging/serverside-pagination.html'
-    };
-})
-
-.directive('d2Enter', function () {
-    return function (scope, element, attrs) {
-        element.bind("keydown keypress", function (event) {
-            if(event.which === 13) {
-                scope.$apply(function (){
-                    scope.$eval(attrs.d2Enter);
-                });
-                event.preventDefault();
-            }
-        });
-    };
-});*/
\ No newline at end of file
+var trackerCaptureDirectives = angular.module('trackerCaptureDirectives', []);
\ No newline at end of file

=== 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	2014-12-15 14:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-12-16 15:44:11 +0000
@@ -101,7 +101,6 @@
     };
 })
 
-
 /* Factory to fetch relationships */
 .factory('RelationshipFactory', function($q, $rootScope, TCStorageService) { 
     return {
@@ -369,34 +368,89 @@
 })
 
 /* Service for getting tracked entity instances */
-.factory('TEIService', function($http, $q, AttributesFactory, DateUtils) {
-
-    return {
-        
-        get: function(entityUid) {
-            var promise = $http.get(  '../api/trackedEntityInstances/' +  entityUid ).then(function(response){     
-                return response.data;
-            });            
-            return promise;
-        },        
-        getByOrgUnitAndProgram: function(orgUnitUid, programUid) {
-
-            var url = '../api/trackedEntityInstances.json?ou=' + orgUnitUid + '&program=' + programUid;
-            
-            var promise = $http.get( url ).then(function(response){
-                return response.data;
-            });            
-            return promise;
-        },
-        getByOrgUnit: function(orgUnitUid) {           
-            
-            var url =  '../api/trackedEntityInstances.json?ou=' + orgUnitUid;
-            
-            var promise = $http.get( url ).then(function(response){
-                return response.data;
-            });            
-            return promise;
-        },        
+.factory('TEIService', function($http, $q, AttributesFactory, OptionSetService, DateUtils) {
+
+    return {        
+        convertFromApiToUser: function(promise, optionSets){            
+            promise.then(function(response){
+                var tei = response.data;
+                var attsById = [];                
+                AttributesFactory.getAll().then(function(atts){
+                    angular.forEach(atts, function(att){                        
+                        attsById[att.id] = att;
+                    });
+
+                    angular.forEach(tei.attributes, function(att){                        
+                        var val = att.value;
+                        if(val){
+                            if(att.type === 'date'){
+                                val = DateUtils.formatFromApiToUser(val);
+                            }
+                            if(att.type === 'optionSet' && 
+                                    attsById[att.attribute] && 
+                                    attsById[att.attribute].optionSet && 
+                                    attsById[att.attribute].optionSet.id && 
+                                    optionSets[attsById[att.attribute].optionSet.id]){   
+                                val = OptionSetService.getName(optionSets[attsById[att.attribute].optionSet.id].options, val);                                
+                            }
+                            att.value = val;
+                        }                        
+                    });                    
+                });    
+                return tei;
+            });            
+            return promise;
+        },
+        convertFromUserToApi: function(_tei, optionSets){            
+            var attsById = [];      
+            var def = $q.defer();
+            
+            var tei = angular.copy(_tei);
+            AttributesFactory.getAll().then(function(atts){
+                angular.forEach(atts, function(att){                        
+                    attsById[att.id] = att;
+                });
+
+                angular.forEach(tei.attributes, function(att){                        
+                    
+                    if(att.type === 'trueOnly'){ 
+                        if(!att.value){
+                            att.value = '';
+                        }
+                        else{
+                            att.value = true;
+                        }
+                    }            
+                    else{
+                        var val = att.value;
+                        if(val){
+                            if(att.type === 'date'){
+                                val = DateUtils.formatFromUserToApi(val);
+                            }
+                            if(att.type === 'optionSet' && 
+                                    attsById[att.attribute] && 
+                                    attsById[att.attribute].optionSet && 
+                                    attsById[att.attribute].optionSet.id && 
+                                    optionSets[attsById[att.attribute].optionSet.id]){   
+                                val = OptionSetService.getCode(optionSets[attsById[att.attribute].optionSet.id].options, val);                                
+                            }
+                            att.value = val;
+                        }
+                    }                                            
+                });     
+                
+                def.resolve(tei);
+            });
+            
+            return def.promise;
+        },
+        get: function(entityUid, optionSets){            
+            var promise = $http.get(  '../api/trackedEntityInstances/' +  entityUid );
+            this.convertFromApiToUser(promise, optionSets).then(function(response){
+                return response.data; 
+            });
+            return promise;
+        },
         search: function(ouId, ouMode, queryUrl, programUrl, attributeUrl, pager, paging) {
                 
             var url =  '../api/trackedEntityInstances.json?ou=' + ouId + '&ouMode='+ ouMode;
@@ -425,13 +479,17 @@
             });            
             return promise;
         },                
-        update: function(tei){
-            
+        update: function(tei, optionSets){   
             var url = '../api/trackedEntityInstances';
-            var promise = $http.put( url + '/' + tei.trackedEntityInstance , tei).then(function(response){
-                return response.data;
+            var def = $q.defer();
+           
+            this.convertFromUserToApi(tei, optionSets).then(function(formattedTei){                
+                $http.put( url + '/' + formattedTei.trackedEntityInstance , formattedTei ).then(function(response){                    
+                    def.resolve( response.data );
+                });
             });
-            return promise;
+            
+            return def.promise;       
         },
         register: function(tei){
             
@@ -508,7 +566,7 @@
                     }                    
                     programAttributes.push(att);                
                 });
-                def.resolve(programAttributes);                                  
+                def.resolve(programAttributes);
             });
             return def.promise;    
         },
@@ -550,8 +608,6 @@
         },
         showRequiredAttributes: function(requiredAttributes, teiAttributes, fromEnrollment, optionSets){        
             
-            console.log('required attribtues:  ', requiredAttributes);
-            console.log('tei attribtue:  ', teiAttributes);
             //first reset teiAttributes
             for(var j=0; j<teiAttributes.length; j++){
                 teiAttributes[j].show = false;                
@@ -1084,95 +1140,4 @@
             return e;
         }
     }; 
-})
-
-/* service for getting calendar setting */
-.service('CalendarService', function(storage, $rootScope){    
-
-    return {
-        getSetting: function() {
-            
-            var dhis2CalendarFormat = {keyDateFormat: 'yyyy-MM-dd', keyCalendar: 'gregorian', momentFormat: 'YYYY-MM-DD'};                
-            var storedFormat = storage.get('CALENDAR_SETTING');
-            if(angular.isObject(storedFormat) && storedFormat.keyDateFormat && storedFormat.keyCalendar){
-                if(storedFormat.keyCalendar === 'iso8601'){
-                    storedFormat.keyCalendar = 'gregorian';
-                }
-
-                if(storedFormat.keyDateFormat === 'dd-MM-yyyy'){
-                    dhis2CalendarFormat.momentFormat = 'DD-MM-YYYY';
-                }
-                
-                dhis2CalendarFormat.keyCalendar = storedFormat.keyCalendar;
-                dhis2CalendarFormat.keyDateFormat = storedFormat.keyDateFormat;
-            }
-            $rootScope.dhis2CalendarFormat = dhis2CalendarFormat;
-            return dhis2CalendarFormat;
-        }
-    };            
-})
-
-/* service for dealing with dates */
-.service('DateUtils', function($filter, CalendarService){
-    
-    return {        
-        getDate: function(dateValue){
-            if(!dateValue){
-                return;
-            }            
-            var calendarSetting = CalendarService.getSetting();
-            dateValue = moment(dateValue, calendarSetting.momentFormat)._d;
-            return Date.parse(dateValue);
-        },
-        format: function(dateValue) {            
-            if(!dateValue){
-                return;
-            }
-            
-            if( isNaN( Date.parse(dateValue) ) ){
-                return;
-            }
-            var calendarSetting = CalendarService.getSetting();            
-            dateValue = moment(dateValue, calendarSetting.momentFormat)._d;
-            dateValue = $filter('date')(dateValue, calendarSetting.keyDateFormat);            
-            return dateValue;
-        },
-        formatToHrsMins: function(dateValue) {
-            var calendarSetting = CalendarService.getSetting();
-            var dateFormat = 'YYYY-MM-DD @ hh:mm A';
-            if(calendarSetting.keyDateFormat === 'dd-MM-yyyy'){
-                dateFormat = 'DD-MM-YYYY @ hh:mm A';
-            }            
-            return moment(dateValue).format(dateFormat);
-        },
-        getToday: function(){  
-            var calendarSetting = CalendarService.getSetting();
-            var tdy = $.calendars.instance(calendarSetting.keyCalendar).newDate();            
-            var today = moment(tdy._year + '-' + tdy._month + '-' + tdy._day, 'YYYY-MM-DD')._d;            
-            today = Date.parse(today);     
-            today = $filter('date')(today,  calendarSetting.keyDateFormat);
-            return today;
-        },
-        formatFromUserToApi: function(dateValue){            
-            if(!dateValue){
-                return;
-            }
-            var calendarSetting = CalendarService.getSetting();
-            dateValue = moment(dateValue, calendarSetting.momentFormat)._d;
-            dateValue = Date.parse(dateValue);     
-            dateValue = $filter('date')(dateValue, 'yyyy-MM-dd'); 
-            return dateValue;            
-        },
-        formatFromApiToUser: function(dateValue){            
-            if(!dateValue){
-                return;
-            }            
-            var calendarSetting = CalendarService.getSetting();
-            dateValue = moment(dateValue, 'YYYY-MM-DD')._d;
-            dateValue = Date.parse(dateValue);     
-            dateValue = $filter('date')(dateValue, calendarSetting.keyDateFormat); 
-            return dateValue;
-        }
-    };
 });
-

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-12-08 16:37:23 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-12-16 15:44:11 +0000
@@ -167,7 +167,7 @@
 }
 
 .input-error {
-    background-color: #ff6600;
+    background-color: #fffe8c;
 }
 
 .input-success {

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js	2014-12-08 15:06:43 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/controllers.js	2014-12-16 15:44:11 +0000
@@ -20,11 +20,11 @@
             hiddenGridColumns,
             gridColumns){
     
-    $scope.eventGridColumns = gridColumns;
+    $scope.gridColumns = gridColumns;
     $scope.hiddenGridColumns = hiddenGridColumns;
     
     $scope.close = function () {
-      $modalInstance.close($scope.eventGridColumns);
+      $modalInstance.close($scope.gridColumns);
     };
     
     $scope.showHideColumns = function(gridColumn){

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js	2014-12-09 23:24:16 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js	2014-12-16 15:44:11 +0000
@@ -154,7 +154,7 @@
             content = $compile(content)(scope);
             var options = {
                     content: content,
-                    placement: 'right',
+                    placement: 'bottom',
                     trigger: 'hover',
                     html: true,
                     title: scope.title               

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js	2014-12-15 14:00:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js	2014-12-16 15:44:11 +0000
@@ -127,10 +127,7 @@
             if(!dateValue){
                 return;
             }
-            
-            if( isNaN( Date.parse(dateValue) ) ){
-                return;
-            }
+
             var calendarSetting = CalendarService.getSetting();            
             dateValue = moment(dateValue, calendarSetting.momentFormat)._d;
             dateValue = $filter('date')(dateValue, calendarSetting.keyDateFormat);