← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20604: tracker-capture: more control on attribute uniquenss validation

 

------------------------------------------------------------
revno: 20604
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-09 15:42:57 +0200
message:
  tracker-capture: more control on attribute uniquenss validation
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/default-registration-form.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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.validations.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/default-registration-form.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/default-registration-form.html	2015-10-08 07:53:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/default-registration-form.html	2015-10-09 13:42:57 +0000
@@ -32,7 +32,9 @@
                                ng-model="selectedTei[attribute.id]"
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                ng-disabled="editingDisabled" 
                                blur-or-change="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>
@@ -44,7 +46,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                ng-disabled="editingDisabled" 
                                ng-change="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>
@@ -54,7 +58,9 @@
                                 ng-model="selectedTei[attribute.id]" 
                                 ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                 d2-attribute-validator 
-                                attribute-data="attribute" selected-program="selectedProgram.id"  
+                                attribute-data="attribute" 
+                                selected-program-id="selectedProgram.id"  
+                                selected-tei-id="selectedTei.trackedEntityInstance"  
                                 class="form-control" 
                                 ng-disabled="editingDisabled" 
                                 ng-change="teiValueUpdated(selectedTei, attribute.id)"
@@ -71,7 +77,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                d2-number-validator 
                                number-type={{attribute.valueType}} 
                                ng-disabled="editingDisabled" 
@@ -85,7 +93,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                ng-disabled="editingDisabled" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>
@@ -97,7 +107,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                ng-disabled="editingDisabled" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique">                                   
@@ -110,7 +122,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                ng-disabled="true" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
@@ -130,7 +144,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               attribute-data="attribute" 
+                               selected-program-id="selectedProgram.id"  
+                               selected-tei-id="selectedTei.trackedEntityInstance"  
                                ng-disabled="editingDisabled" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>                                    

=== 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-10-09 09:07:58 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-10-09 13:42:57 +0000
@@ -132,7 +132,7 @@
             $location.path('/dashboard').search({tei: teiId,                                            
                                     program: $scope.selectedProgram ? $scope.selectedProgram.id: null});
         }
-        else{
+        else if (destination === 'SELF'){
             //notify user
             var dialogOptions = {
                     headerText: 'success',
@@ -161,7 +161,7 @@
             if(reg.reference && reg.status === 'SUCCESS'){                
                 $scope.tei.trackedEntityInstance = reg.reference;
                 
-                if( $scope.registrationMode === 'PROFILE' ){                    
+                if( $scope.registrationMode === 'PROFILE' ){
                     reloadProfileWidget();
                 }
                 else{

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.validations.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.validations.js	2015-10-08 07:53:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.validations.js	2015-10-09 13:42:57 +0000
@@ -143,12 +143,14 @@
         require: "ngModel", 
         scope: {
             'attributeData': '=',
-            'selectedProgram': '='
+            'selectedProgramId': '=',
+            'selectedTeiId': '=',
+            'ngDisabled': '='
         },
         link: function(scope, element, attrs, ngModel) {
             
-            if( scope.attributeData && scope.attributeData.unique ){                
- 
+            function uniqunessValidatior(){
+                
                 ngModel.$asyncValidators.uniqunessValidator = function (modelValue, viewValue) {
                     var pager = {pageSize: 1, page: 1, toolBarDisplay: 5};
                     var deferred = $q.defer(), currentValue = modelValue || viewValue, programUrl = null, ouMode = 'ALL';
@@ -167,14 +169,19 @@
                         if(scope.attributeData.orgUnitScope){
                             ouMode = 'SELECTED';
                         }                        
-                        
+
                         TEIService.search(ouId, ouMode, null, programUrl, attUrl.url, pager, true).then(function(data) {
-                            if (data.rows.length > 0) {    
-                                deferred.reject();
-                            }
-                            else {
-                                deferred.resolve();
-                            }
+                            if(scope.selectedTeiId){
+                                if(data.rows[0][0] !== scope.selectedTeiId){
+                                    deferred.reject();
+                                }
+                            }
+                            else{
+                                if (data.rows.length > 0) {    
+                                    deferred.reject();
+                                }
+                            }                            
+                            deferred.resolve();
                         });
                     }
                     else {
@@ -183,7 +190,15 @@
 
                     return deferred.promise;
                 };
-            }            
+            }
+                      
+            scope.$watch('ngDisabled', function(value){
+                if(!value){
+                    if( scope.attributeData && scope.attributeData.unique && !scope.ngDisabled ){                
+                        uniqunessValidatior();
+                    }
+                }              
+            });       
         }
     };
 });
\ No newline at end of file