← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18168: tracker-capture: custom registration/enrollment form - WIP

 

------------------------------------------------------------
revno: 18168
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-02-03 16:59:38 +0100
message:
  tracker-capture: custom registration/enrollment form - WIP
added:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/default-form.html
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-cache-cleaner/scripts/controllers.js
  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/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/registration/registration-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html
  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/d2Directives.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Services.js
  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-cache-cleaner/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-cache-cleaner/scripts/controllers.js	2014-12-17 14:17:16 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-cache-cleaner/scripts/controllers.js	2015-02-03 15:59:38 +0000
@@ -59,10 +59,10 @@
                 if(dbKey.remove){
                     idbStorageService.deleteDb(dbKey.id).then(function(res){
                         if(res){
-                            console.log('removed from local indexeddb:  ', dbKey.id);
+                            console.log('removed from indexeddb:  ', dbKey.id);
                         }
                         else{
-                            console.log('failed to remove from local indexeddb:  ', dbKey.id);
+                            console.log('failed to remove from indexeddb:  ', dbKey.id);
                         }
                         
                     });

=== 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	2015-01-19 15:47:22 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js	2015-02-03 15:59:38 +0000
@@ -87,11 +87,14 @@
     
     $scope.loadEnrollmentDetails = function(enrollment) {
         
+        $scope.attributesForEnrollment = [];
+        $scope.attributes = [];
         $scope.showEnrollmentHistoryDiv = false;
         $scope.selectedEnrollment = enrollment;
         
         if(!$scope.selectedEnrollment){//prepare for possible enrollment
             AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
+                $scope.attributes = atts;
                 $scope.attributesForEnrollment = [];
                 for(var i=0; i<atts.length; i++){
                     var exists = false;
@@ -116,6 +119,7 @@
         }
        
         $scope.showEnrollmentDiv = !$scope.showEnrollmentDiv;
+        $rootScope.$broadcast('enrollmentEditing', {enrollmentEditing: $scope.showEnrollmentDiv});
         
         if($scope.showEnrollmentDiv){            
             $scope.showEnrollmentHistoryDiv = false;
@@ -127,7 +131,7 @@
             //check custom form for enrollment
             $scope.selectedProgram.hasCustomForm = false;
             $scope.registrationForm = '';
-            TEFormService.getByProgram($scope.selectedProgram.id).then(function(teForm){
+            TEFormService.getByProgram($scope.selectedProgram, $scope.attributes).then(function(teForm){
                 if(angular.isObject(teForm)){
                     $scope.selectedProgram.hasCustomForm = true;
                     $scope.registrationForm = teForm;

=== added file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/default-form.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/default-form.html	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/default-form.html	2015-02-03 15:59:38 +0000
@@ -0,0 +1,77 @@
+<table class="table-borderless table-striped">
+    <tr ng-repeat="attribute in attributes">
+        <td>
+            {{attribute.name}}<span ng-if="attribute.mandatory" class="required">*</span>
+        </td>
+        <td>
+            <ng-form name="innerForm">
+                <span ng-switch="attribute.valueType">
+                    <span ng-switch-when="date">
+                        <input type="text" 
+                               placeholder="{{dhis2CalendarFormat.keyDateFormat}}" 
+                               name="foo" 
+                               class="form-control" 
+                               d2-date
+                               max-date="attribute.allowFutureDate ? '' : 0"
+                               ng-model="selectedTei[attribute.id]"
+                               ng-disabled="editingDisabled" 
+                               ng-required="attribute.mandatory"/>
+                    </span>
+                    <span ng-switch-when="trueOnly">
+                        <input type="checkbox" 
+                               name="foo" 
+                               class="form-control" 
+                               ng-model="selectedTei[attribute.id]" 
+                               ng-disabled="editingDisabled" 
+                               ng-required="attribute.mandatory"/>
+                    </span>
+                    <span ng-switch-when="bool">
+                        <select name="foo" 
+                                ng-model="selectedTei[attribute.id]" 
+                                class="form-control" 
+                                ng-disabled="editingDisabled" 
+                                ng-required="attribute.mandatory">
+                            <option value="">{{'please_select'| translate}}</option>                        
+                            <option value="false">{{'no'| translate}}</option>
+                            <option value="true">{{'yes'| translate}}</option>
+                        </select>
+                    </span>
+                    <span ng-switch-when="optionSet">
+                        <input type="text"
+                               name="foo"
+                               class="form-control"
+                               ng-model="selectedTei[attribute.id]"                                                 
+                               typeahead="option.name as option.name for option in optionSets[attributesById[attribute.id].optionSet.id].options | filter:$viewValue | limitTo:20" 
+                               typeahead-open-on-focus                                           
+                               ng-disabled="editingDisabled" ng-required="attribute.mandatory"/>
+                    </span>
+                    <span ng-switch-when="number">
+                        <input type="text" 
+                               name="foo" 
+                               class="form-control" 
+                               ng-model="selectedTei[attribute.id]" 
+                               ng-disabled="editingDisabled" 
+                               ng-required="attribute.mandatory"/>
+                    </span>
+                    <span ng-switch-when="email">
+                        <input type="email" 
+                               name="foo" 
+                               class="form-control" 
+                               ng-model="selectedTei[attribute.id]" 
+                               ng-disabled="editingDisabled" 
+                               ng-required="attribute.mandatory"/>
+                    </span>
+                    <span ng-switch-default>
+                        <input type="text" 
+                               name="foo" 
+                               class="form-control" 
+                               ng-model="selectedTei[attribute.id]" 
+                               ng-disabled="editingDisabled" 
+                               ng-required="attribute.mandatory"/>                                    
+                    </span>
+                </span>
+            </ng-form>
+            <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
+        </td>
+    </tr>           
+</table>
\ No newline at end of file

=== 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	2015-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js	2015-02-03 15:59:38 +0000
@@ -6,61 +6,74 @@
                 TEFormService,
                 TEIService,
                 DialogService,
-                AttributesFactory) {
+                AttributesFactory) {    
+    
+    $scope.editingDisabled = true;
+    $scope.enrollmentEditing = false;
     
     //attributes for profile    
-    $scope.attributes = [];    
-    $scope.editProfile = false;    
-    
+    $scope.attributes = []; 
+    $scope.attributesById = [];
     AttributesFactory.getAll().then(function(atts){
         angular.forEach(atts, function(att){
-            $scope.attributes[att.id] = att;
-        }); 
-    }); 
+            $scope.attributesById[att.id] = att;
+        });
+    });
     
-    //listen for the selected entity       
+    //listen for the selected entity
+    var selections = {};
     $scope.$on('dashboardWidgets', function(event, args) { 
-        var selections = CurrentSelection.get();
+        selections = CurrentSelection.get();
         $scope.selectedTei = angular.copy(selections.tei);
-
         $scope.trackedEntity = selections.te;
         $scope.selectedProgram = selections.pr;   
         $scope.selectedEnrollment = selections.selectedEnrollment;
         $scope.optionSets = selections.optionSets;
+        $scope.trackedEntityForm = null;
+        $scope.customForm = null;
+        $scope.attributes = [];
 
         //display only those attributes that belong to the selected program
-        //if no program, display attributesInNoProgram
-        TEIService.processAttributes($scope.selectedTei, $scope.selectedProgram, $scope.selectedEnrollment).then(function(tei){
-            $scope.selectedTei = tei;
-            if($scope.selectedProgram && $scope.selectedProgram.id){            
-                AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
-                    $scope.attributesById = [];
-                    angular.forEach(atts, function(att){
-                        $scope.attributesById[att.id] = att;
-                    });
+        //if no program, display attributesInNoProgram        
+        angular.forEach($scope.selectedTei.attributes, function(att){
+            $scope.selectedTei[att.attribute] = att.value;
+        });
+        delete $scope.selectedTei.attributes;
+        
+        if($scope.selectedProgram && $scope.selectedProgram.id){            
+            AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
+                $scope.attributes = atts;
 
-                    $scope.selectedProgram.hasCustomForm = false;               
-                    TEFormService.getByProgram($scope.selectedProgram, atts).then(function(teForm){                    
-                        if(angular.isObject(teForm)){                        
-                            $scope.selectedProgram.hasCustomForm = true;
-                            $scope.selectedProgram.displayCustomForm = $scope.selectedProgram.hasCustomForm ? true:false;
-                            $scope.trackedEntityForm = teForm;
-                            $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'PROFILE');
-                        }                    
-                    });  
-                });                
-            }
-        });
+                $scope.selectedProgram.hasCustomForm = false;               
+                TEFormService.getByProgram($scope.selectedProgram, atts).then(function(teForm){                    
+                    if(angular.isObject(teForm)){                        
+                        $scope.selectedProgram.hasCustomForm = true;
+                        $scope.selectedProgram.displayCustomForm = $scope.selectedProgram.hasCustomForm ? true:false;
+                        $scope.trackedEntityForm = teForm;
+                        $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'PROFILE');
+                    }                    
+                });
+            });                
+        }
+        else{            
+            AttributesFactory.getWithoutProgram().then(function(atts){
+                $scope.attributes = atts;
+            });
+        }
+    });
+    
+    //listen for enrollment editing
+    $scope.$on('enrollmentEditing', function(event, args) { 
+        $scope.enrollmentEditing = args.enrollmentEditing;
     });
     
     $scope.enableEdit = function(){
-        $scope.entityAttributes = angular.copy($scope.selectedTei.attributes);
-        $scope.editProfile = !$scope.editProfile; 
+        $scope.teiOriginal = angular.copy($scope.selectedTei);
+        $scope.editingDisabled = !$scope.editingDisabled; 
         $rootScope.profileWidget.expand = true;
     };
     
-    $scope.save = function(){        
-        
+    $scope.save = function(){
         //check for form validity
         $scope.outerForm.submitted = true;        
         if( $scope.outerForm.$invalid ){
@@ -72,19 +85,19 @@
         //but there could be a case where attributes are non-mandatory and
         //form comes empty, in this case enforce at least one value        
         $scope.formEmpty = true;
-        var tei = angular.copy($scope.selectedTei);
+        var tei = angular.copy(selections.tei);
         tei.attributes = [];
-        angular.forEach($scope.selectedTei.attributes, function(attribute){            
-            tei.attributes.push({attribute: attribute.attribute, value: attribute.value, type: attribute.type});
-            if(attribute.value && $scope.formEmpty){
+        for(var k in $scope.attributesById){
+            if( $scope.selectedTei[k] ){
+                tei.attributes.push({attribute: $scope.attributesById[k].id, value: $scope.selectedTei[k], type: $scope.attributesById[k].valueType});
                 $scope.formEmpty = false;
-            }           
-        });
+            }
+        }
         
-        if($scope.formEmpty){//form is empty  
+        if($scope.formEmpty){//form is empty
             return false;
         }
-        
+                
         TEIService.update(tei, $scope.optionSets).then(function(updateResponse){
             
             if(updateResponse.status !== 'SUCCESS'){//update has failed
@@ -96,14 +109,18 @@
                 return;
             }
             
-            $scope.editProfile = !$scope.editProfile;
-            CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets});   
+            $scope.editingDisabled = !$scope.editingDisabled;
+            CurrentSelection.set({tei: tei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets});   
             $scope.outerForm.submitted = false; 
         });
     };
     
     $scope.cancel = function(){
-        $scope.selectedTei.attributes = $scope.entityAttributes;  
-        $scope.editProfile = !$scope.editProfile;
+        $scope.selectedTei = $scope.teiOriginal;  
+        $scope.editingDisabled = !$scope.editingDisabled;
     };
+    
+    $scope.switchRegistrationForm = function(){
+        $scope.selectedProgram.displayCustomForm = !$scope.selectedProgram.displayCustomForm;
+    };    
 });
\ No newline at end of file

=== 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	2015-01-20 16:41:34 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html	2015-02-03 15:59:38 +0000
@@ -2,11 +2,14 @@
     <div class="panel-heading handle bold">
 
         {{profileWidget.title| translate}}
-        <span class="nav-pills">
-            | <a href ng-click="enableEdit()" title="{{'edit_profile'| translate}}"><span ng-class="{true: 'widget-link-active', false: 'widget-link'} [editProfile]">{{'edit'| translate}}</span></a>
+        <span class="nav-pills" ng-if="!enrollmentEditing">
+            | <a href ng-click="enableEdit()" title="{{'edit_profile'| translate}}"><span ng-class="{true: 'widget - link - active', false: 'widget - link'} [!editingDisabled]">{{'edit'| translate}}</span></a>
         </span>
-        
-        <span class="pull-right widget-link">
+
+        <span class="pull-right widget-link">            
+            <a ng-if="customForm" class="small-horizonal-spacing" href ng-click="switchRegistrationForm()" title="{{selectedProgram.displayCustomForm ? 'default_form' : 'custom_form'| translate}}">
+                <span><i class="fa fa-file-text"></i></span>
+            </a>
             <a class="small-horizonal-spacing" href ng-click="expandCollapse(profileWidget)">
                 <span ng-show="profileWidget.expand"><i class="fa fa-chevron-up" title="{{'collapse'| translate}}"></i></span>
                 <span ng-show="!profileWidget.expand"><i class="fa fa-chevron-down" title="{{'expand'| translate}}"></i></span>
@@ -16,98 +19,27 @@
     </div>
     <div ng-show="profileWidget.expand" class="panel-body dashboard-widget-container">
         <form name="outerForm" novalidate>
-            
-            <table class="table-borderless table-striped">
-                <tr ng-repeat="attribute in selectedTei.attributes" ng-show="attribute.show">
-                    <td>
-                        {{attribute.displayName}}
-                    </td>
-                    <td>
-                        <ng-form name="innerForm">
-                            <span ng-switch="attribute.type">
-                                <span ng-switch-when="date">
-                                    <input type="text" 
-                                           placeholder="{{dhis2CalendarFormat.keyDateFormat}}" 
-                                           name="foo" 
-                                           class="form-control" 
-                                           d2-date
-                                           max-date="attribute.allowFutureDate ? '' : 0"
-                                           ng-model="attribute.value"
-                                           ng-disabled="!editProfile" 
-                                           ng-required="attribute.mandatory"/>
-                                </span>
-                                <span ng-switch-when="trueOnly">
-                                    <input type="checkbox" 
-                                           name="foo" 
-                                           class="form-control" 
-                                           ng-model="attribute.value" 
-                                           ng-disabled="!editProfile" 
-                                           ng-required="attribute.mandatory"/>
-                                </span>
-                                <span ng-switch-when="bool">
-                                    <select name="foo" 
-                                            ng-model="attribute.value" 
-                                            class="form-control" 
-                                            ng-disabled="!editProfile" 
-                                            ng-required="attribute.mandatory">
-                                        <option value="">{{'please_select'| translate}}</option>                        
-                                        <option value="false">{{'no'| translate}}</option>
-                                        <option value="true">{{'yes'| translate}}</option>
-                                    </select>
-                                </span>
-                                <span ng-switch-when="optionSet">
-                                    <input type="text"
-                                           name="foo"
-                                           class="form-control"
-                                           ng-model="attribute.value"                                                 
-                                           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>
-                                <span ng-switch-when="number">
-                                    <input type="number" 
-                                           name="foo" 
-                                           class="form-control" 
-                                           ng-model="attribute.value" 
-                                           ng-disabled="!editProfile" 
-                                           ng-required="attribute.mandatory"/>
-                                </span>
-                                <span ng-switch-when="email">
-                                    <input type="email" 
-                                           name="foo" 
-                                           class="form-control" 
-                                           ng-model="attribute.value" 
-                                           ng-disabled="!editProfile" 
-                                           ng-required="attribute.mandatory"/>
-                                </span>
-                                <span ng-switch-default>
-                                    <input type="text" 
-                                           name="foo" 
-                                           class="form-control" 
-                                           ng-model="attribute.value" 
-                                           ng-disabled="!editProfile" 
-                                           ng-required="attribute.mandatory"/>                                    
-                                </span>
-                            </span>
-                        </ng-form>
-                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                    </td>
-                </tr>           
-            </table>
+            <div ng-if="!enrollmentEditing">
+                <div class="vertical-spacing" ng-if="selectedProgram && selectedProgram.displayCustomForm">
+                    <div ng-include="'../dhis-web-commons/customform/custom-form.html'"></div>
+                </div>
+                <div class="vertical-spacing" ng-if="!selectedProgram.displayCustomForm">            
+                    <div ng-include="'components/profile/default-form.html'"></div>
+                </div>
 
-            <div ng-if="editProfile" class="vertical-spacing">
-                <button type="button" 
-                        class="btn btn-primary small-horizonal-spacing"
-                        ng-click="save()">
-                    {{'save'| translate}}
-                </button>        
-                <button type="button" 
-                        class="btn btn-default small-horizonal-spacing" 
-                        ng-click="cancel()">
-                    {{'cancel'| translate}}
-                </button>
-            </div> 
-            
+                <div ng-if="!editingDisabled" class="vertical-spacing">
+                    <button type="button" 
+                            class="btn btn-primary small-horizonal-spacing"
+                            ng-click="save()">
+                        {{'save'| translate}}
+                    </button>        
+                    <button type="button" 
+                            class="btn btn-default small-horizonal-spacing" 
+                            ng-click="cancel()">
+                        {{'cancel'| translate}}
+                    </button>
+                </div>
+            </div>
         </form>
     </div>
 </div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-02-03 15:59:38 +0000
@@ -21,6 +21,12 @@
     $scope.trackedEntityForm = null;
     $scope.customForm = null;
     $scope.optionSets = CurrentSelection.getOptionSets();
+    $scope.attributesById = [];    
+    AttributesFactory.getAll().then(function(atts){
+        angular.forEach(atts, function(att){
+            $scope.attributesById[att.id] = att;
+        });
+    });
             
     if(!$scope.optionSets){
         $scope.optionSets = [];
@@ -34,11 +40,7 @@
     }
     
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
-    $scope.enrollment = {dateOfEnrollment: '', dateOfIncident: ''};   
-    
-    /*AttributesFactory.getWithoutProgram().then(function(atts){
-        $scope.attributes = atts;
-    });*/
+    $scope.selectedEnrollment = {dateOfEnrollment: '', dateOfIncident: ''};   
             
     $scope.trackedEntities = {available: []};
     TEService.getAll().then(function(entities){
@@ -57,11 +59,6 @@
         if($scope.selectedProgram && $scope.selectedProgram.id){            
             AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
                 $scope.attributes = atts;
-                $scope.attributesById = [];
-                angular.forEach(atts, function(att){
-                    $scope.attributesById[att.id] = att;
-                });
-
                 $scope.selectedProgram.hasCustomForm = false;               
                 TEFormService.getByProgram($scope.selectedProgram, $scope.attributes).then(function(teForm){                    
                     if(angular.isObject(teForm)){                        
@@ -76,10 +73,6 @@
         else{            
             AttributesFactory.getWithoutProgram().then(function(atts){
                 $scope.attributes = atts;
-                $scope.attributesById = [];
-                angular.forEach(atts, function(att){
-                    $scope.attributesById[att.id] = att;
-                });
             });
         }
     };
@@ -124,8 +117,8 @@
                     var enrollment = {trackedEntityInstance: teiId,
                                 program: $scope.selectedProgram.id,
                                 status: 'ACTIVE',
-                                dateOfEnrollment: DateUtils.formatFromUserToApi($scope.enrollment.dateOfEnrollment),
-                                dateOfIncident: $scope.enrollment.dateOfIncident === '' ? DateUtils.formatFromUserToApi($scope.enrollment.dateOfEnrollment) : DateUtils.formatFromUserToApi($scope.enrollment.dateOfIncident)
+                                dateOfEnrollment: DateUtils.formatFromUserToApi($scope.selectedEnrollment.dateOfEnrollment),
+                                dateOfIncident: $scope.selectedEnrollment.dateOfIncident === '' ? DateUtils.formatFromUserToApi($scope.selectedEnrollment.dateOfEnrollment) : DateUtils.formatFromUserToApi($scope.selectedEnrollment.dateOfIncident)
                             };                           
                     EnrollmentService.enroll(enrollment).then(function(data){
                         if(data.status !== 'SUCCESS'){
@@ -139,7 +132,7 @@
                         }
                         else{
                             enrollment.enrollment = data.reference;
-                            $scope.autoGenerateEvents(teiId,$scope.selectedProgram, $scope.selectedOrgUnit, $scope.enrollment);                          
+                            $scope.autoGenerateEvents(teiId,$scope.selectedProgram, $scope.selectedOrgUnit, $scope.selectedEnrollment);                          
                         }
                     });
                 }
@@ -160,8 +153,8 @@
                     delete attribute.value;                
                 });            
 
-                $scope.enrollment.dateOfEnrollment = '';
-                $scope.enrollment.dateOfIncident =  '';
+                $scope.selectedEnrollment.dateOfEnrollment = '';
+                $scope.selectedEnrollment.dateOfIncident =  '';
                 $scope.outerForm.submitted = false; 
 
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html	2015-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/index.html	2015-02-03 15:59:38 +0000
@@ -6,7 +6,7 @@
         <meta name="description" content="DHIS 2">
         <meta name="keywords" content="DHIS 2">        
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
-        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">              
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
         <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.min.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/ui/jquery-ui.min.js"></script>
@@ -74,6 +74,7 @@
         
         <script src="../dhis-web-commons/ouwt/ouwt.js"></script>
         <script src="scripts/tracker-capture.js"></script>
+        <!--<script src="scripts/idb.js"></script>-->
 
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/plugins/select2.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/plugins/angularjs-nvd3-directives.min.js"></script>

=== 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	2015-01-14 14:02:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2015-02-03 15:59:38 +0000
@@ -22,7 +22,8 @@
     //Selection
     $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];         
     $scope.selectedOuMode = $scope.ouModes[0];
-    $scope.dashboardProgramId = ($location.search()).program; 
+    $scope.dashboardProgramId = ($location.search()).program;
+    $scope.selectedOrgUnitId = ($location.search()).ou;
     $scope.treeLoaded = false;
     
     //Paging
@@ -48,7 +49,7 @@
     
     //Reporting
     $scope.showReportDiv = false;
-   
+    
     //watch for selection of org unit from tree
     $scope.$watch('selectedOrgUnit', function() {           
 
@@ -70,13 +71,12 @@
                     CurrentSelection.setOptionSets($scope.optionSets);
                 });
             }
-            $scope.loadPrograms($scope.selectedOrgUnit);                                
+            $scope.loadPrograms($scope.selectedOrgUnit);
         }
     });
     
     //watch for changes in ou mode - mode could be selected without notifcation to grid column generator
-    $scope.$watch('selectedOuMode.name', function() {           
-
+    $scope.$watch('selectedOuMode.name', function() {
         if( $scope.selectedOuMode.name && angular.isObject($scope.gridColumns)){
             var continueLoop = true;
             for(var i=0; i<$scope.gridColumns.length && continueLoop; i++){
@@ -89,8 +89,7 @@
     });
         
     //watch for program feedback (this is when coming back from dashboard)
-    if($scope.dashboardProgramId && $scope.dashboardProgramId !== 'null'){
-        $scope.selectedOrgUnit = storage.get('SELECTED_OU');            
+    if($scope.dashboardProgramId && $scope.dashboardProgramId !== 'null'){        
         ProgramFactory.get($scope.dashboardProgramId).then(function(program){
             $scope.selectedProgram = program;        
         });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Directives.js	2015-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Directives.js	2015-02-03 15:59:38 +0000
@@ -443,8 +443,10 @@
         restrict: 'E',
         link: function(scope, elm, attrs){
             scope.$watch('customForm', function(){
-                elm.html(scope.customForm.htmlCode);
-                $compile(elm.contents())(scope);
+                if(angular.isObject(scope.customForm)){
+                    elm.html(scope.customForm.htmlCode);
+                    $compile(elm.contents())(scope);
+                }                
             });
         }
     };

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Services.js	2015-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/d2Services.js	2015-02-03 15:59:38 +0000
@@ -376,13 +376,13 @@
                             newInputField = '<input type="text" ' +
                                             ' name="' + fieldName + '"' +                          
                                             ' element-id="' + i + '"' +
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +
                                             this.getAttributesAsString(attributes) +
                                             ' d2-validation ' +
                                             ' d2-number-validation ' +
                                             ' d2-focus-next-on-enter' + 
-                                            ' ng-model="registeredTei.' + attId + '" ' +                                             
-                                            ' ng-blur="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
+                                            ' ng-blur="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ';
                         }                                               
                         else if(trackedEntityFormAttributes[attId].valueType === "optionSet"){
@@ -390,10 +390,10 @@
                             newInputField = '<input type="text" ' +
                                             ' name="' + fieldName + '"' +
                                             ' element-id="' + i + '"' +
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +                                            
                                             this.getAttributesAsString(attributes) +
                                             ' d2-focus-next-on-enter' + 
-                                            ' ng-model="registeredTei.' + attId + '" ' +   
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
                                             ' d2-validation ' +
                                             ' d2-typeahead-validation ' +
                                             ' class="typeahead" ' +
@@ -401,18 +401,18 @@
                                             ' typeahead-editable="false" ' + 
                                             ' typeahead="option.name as option.name for option in optionSets.' + optionSetId + '.options | filter:$viewValue | limitTo:50"' +
                                             ' typeahead-open-on-focus ' +
-                                            ' ng-blur="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' ng-blur="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ';                            
                         }
                         else if(trackedEntityFormAttributes[attId].valueType === "bool"){
                             newInputField = '<select ' +
                                             ' name="' + fieldName + '"' +
-                                            ' element-id="' + i + '"' + 
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +                                            
+                                            ' element-id="' + i + '"' +
                                             this.getAttributesAsString(attributes) +
                                             ' d2-focus-next-on-enter' + 
-                                            ' ng-model="registeredTei.' + attId + '" ' +                                            
-                                            ' ng-change="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
+                                            ' ng-change="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ' +
                                             ' <option value="">{{\'please_select\'| translate}}</option>' +
                                             ' <option value="false">{{\'no\'| translate}}</option>' + 
@@ -422,57 +422,57 @@
                         else if(trackedEntityFormAttributes[attId].valueType === "date"){
                             newInputField = '<input type="text" ' +
                                             ' name="' + fieldName + '"' +
-                                            ' element-id="' + i + '"' + 
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +
+                                            ' element-id="' + i + '"' +
                                             this.getAttributesAsString(attributes) +
                                             ' d2-focus-next-on-enter' + 
                                             ' placeholder="{{dhis2CalendarFormat.keyDateFormat}}" ' +
-                                            ' ng-model="registeredTei.' + attId + '" ' +                                            
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
                                             ' max-date="' + attMaxDate + '"' + '\'' +
                                             ' d2-date' +
                                             ' d2-validation ' +
-                                            ' blur-or-change="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' blur-or-change="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ';
                         }
                         else if(trackedEntityFormAttributes[attId].valueType === "trueOnly"){
                             newInputField = '<input type="checkbox" ' +  
                                             ' name="' + fieldName + '"' +
-                                            ' element-id="' + i + '"' + 
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +
+                                            ' element-id="' + i + '"' +
                                             this.getAttributesAsString(attributes) + 
                                             ' d2-validation ' +
                                             ' d2-focus-next-on-enter' + 
-                                            ' ng-model="registeredTei.' + attId + '" ' +                                            
-                                            ' ng-change="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
+                                            ' ng-change="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ';
                         }
                         else if(trackedEntityFormAttributes[attId].valueType === "email"){
                             newInputField = '<input type="email" ' +    
                                             ' name="' + fieldName + '"' +                                              
-                                            ' element-id="' + i + '"' + 
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +
+                                            ' element-id="' + i + '"' +
                                             this.getAttributesAsString(attributes) +
                                             ' d2-validation ' +
                                             ' d2-focus-next-on-enter' + 
-                                            ' ng-model="registeredTei.' + attId + '" ' +                                            
-                                            ' ng-blur="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
+                                            ' ng-blur="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ';
                         }
                         else {
                             newInputField = '<input type="text" ' +
                                             ' name="' + fieldName + '"' +
-                                            ' element-id="' + i + '"' + 
-                                            ' element-code="' + trackedEntityFormAttributes[attId].code + '"' +                                            
+                                            ' element-id="' + i + '"' +                                             
                                             this.getAttributesAsString(attributes) +
                                             ' d2-validation ' +
                                             ' d2-focus-next-on-enter' + 
-                                            ' ng-model="registeredTei.' + attId + '" ' +                                            
-                                            ' ng-blur="validationAndSkipLogic(registeredTei,\'' + attId + '\')" ' +
+                                            ' ng-model="selectedTei.' + attId + '" ' +
+                                            ' ng-disabled="editingDisabled"' +
+                                            ' ng-blur="validationAndSkipLogic(selectedTei,\'' + attId + '\')" ' +
                                             ' ng-required=" ' + trackedEntityFormAttributes[attId].mandatory + '"> ';
                         } 
                     }                        
                  
-                    if(target === 'ENROLLMENT' && attributes.hasOwnProperty('programid')){
+                    if(attributes.hasOwnProperty('programid')){
                         hasProgramDate = true;
                         programId = attributes['programid'];                        
                         if(programId === 'enrollmentDate'){
@@ -484,13 +484,14 @@
                                             this.getAttributesAsString(attributes) +
                                             ' d2-focus-next-on-enter' + 
                                             ' placeholder="{{dhis2CalendarFormat.keyDateFormat}}" ' +
-                                            ' ng-model="enrollment.dateOfEnrollment" ' +
+                                            ' ng-model="selectedEnrollment.dateOfEnrollment" ' +
+                                            ' ng-disabled="\'' + target + '\' === \'PROFILE\'"' +
                                             ' d2-date' +
-                                            ' max-date="' + enMaxDate + '"' + '\'' +
+                                            ' max-date="' + enMaxDate + '"' +
                                             ' ng-required="true"> ';
                         }
-                        if(programId === 'dateOfIncident'){
-                            fieldName = 'dateOfEnrollment';
+                        if(programId === 'dateOfIncident' && trackedEntity.displayIncidentDate){
+                            fieldName = 'dateOfIncident';
                             var inMaxDate = trackedEntity.selectIncidentDatesInFuture ? '' : 0;                            
                             newInputField = '<input type="text" ' +
                                             ' name="' + fieldName + '"' +
@@ -498,17 +499,16 @@
                                             this.getAttributesAsString(attributes) +
                                             ' d2-focus-next-on-enter' + 
                                             ' placeholder="{{dhis2CalendarFormat.keyDateFormat}}" ' +
-                                            ' ng-model="enrollment.dateOfIncident" ' +
+                                            ' ng-model="selectedEnrollment.dateOfIncident" ' +
+                                            ' ng-disabled="\'' + target + '\' === \'PROFILE\'"' +
                                             ' d2-date ' +
-                                            ' max-date="' + inMaxDate + '"' + + '\'' +
-                                            ' ng-required="true"> ';
+                                            ' max-date="' + inMaxDate + '"> ';
                         }
                     }
                     
                     newInputField = //'<ng-form name="innerForm">' + 
                                         newInputField + 
-                                        ' <span ng-show="outerForm.submitted && outerForm.'+ fieldName +'.$invalid" class="required">{{required}}</span> ' + 
-                                        ' <span ng-show="invalidInputs.' + fieldName + '"" class="required">{{invalidInputLabel}}</span> ';
+                                        ' <span ng-show="outerForm.submitted && outerForm.'+ fieldName +'.$invalid" class="required">{{\'required\' | translate}}</span> ';
                                     //'</ng-form>';
                                     
                     htmlCode = htmlCode.replace(inputField, newInputField);                    

=== 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-02-02 13:42:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-02-03 15:59:38 +0000
@@ -397,10 +397,16 @@
                 TCStorageService.currentStore.get('trackedEntityForms', program.id).done(function(teForm){                    
                     $rootScope.$apply(function(){
                         var trackedEntityForm = teForm;
-                        trackedEntityForm.attributes = attributes;
-                        trackedEntityForm.selectIncidentDatesInFuture = program.selectIncidentDatesInFuture;
-                        trackedEntityForm.selectEnrollmentDatesInFuture = program.selectEnrollmentDatesInFuture;                        
-                        def.resolve(trackedEntityForm);
+                        if(angular.isObject(trackedEntityForm)){
+                            trackedEntityForm.attributes = attributes;
+                            trackedEntityForm.selectIncidentDatesInFuture = program.selectIncidentDatesInFuture;
+                            trackedEntityForm.selectEnrollmentDatesInFuture = program.selectEnrollmentDatesInFuture;
+                            trackedEntityForm.displayIncidentDate = program.displayIncidentDate;
+                            def.resolve(trackedEntityForm);
+                        }
+                        else{
+                            def.resolve(null);
+                        }
                     });
                 });
             });