← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20579: tracker-capture: values entered for attributes configured as unique are validated immediately bef...

 

------------------------------------------------------------
revno: 20579
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-08 09:53:00 +0200
message:
  tracker-capture: values entered for attributes configured as unique are validated immediately before the entire registration/enrollment data is sent to server. This helps for the user to get immediate feedback and make corrections.
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/i18n/i18n_app.properties
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/error-messages.html
  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-07 15:13:26 +0000
+++ 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
@@ -30,9 +30,9 @@
                                d2-date-validator 
                                max-date="attribute.allowFutureDate ? '' : 0"
                                ng-model="selectedTei[attribute.id]"
-                               ng-model-options="{ updateOn: 'blur' }"
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                d2-attribute-validator 
-                               attribute-data="attribute" 
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
                                ng-disabled="editingDisabled" 
                                blur-or-change="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>
@@ -42,9 +42,9 @@
                                name="foo" 
                                class="form-control" 
                                ng-model="selectedTei[attribute.id]" 
-                               ng-model-options="{ updateOn: 'blur' }"
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                d2-attribute-validator 
-                               attribute-data="attribute" 
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
                                ng-disabled="editingDisabled" 
                                ng-change="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>
@@ -52,9 +52,9 @@
                     <span ng-switch-when="BOOLEAN">
                         <select name="foo" 
                                 ng-model="selectedTei[attribute.id]" 
-                                ng-model-options="{ updateOn: 'blur' }" 
+                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                 d2-attribute-validator 
-                                attribute-data="attribute" 
+                                attribute-data="attribute" selected-program="selectedProgram.id"  
                                 class="form-control" 
                                 ng-disabled="editingDisabled" 
                                 ng-change="teiValueUpdated(selectedTei, attribute.id)"
@@ -69,9 +69,9 @@
                                name="foo" 
                                class="form-control" 
                                ng-model="selectedTei[attribute.id]" 
-                               ng-model-options="{ updateOn: 'blur' }" 
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
                                d2-number-validator 
                                number-type={{attribute.valueType}} 
                                ng-disabled="editingDisabled" 
@@ -83,9 +83,9 @@
                                name="foo" 
                                class="form-control" 
                                ng-model="selectedTei[attribute.id]" 
-                               ng-model-options="{ updateOn: 'blur' }" 
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
                                ng-disabled="editingDisabled" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique"/>
@@ -95,9 +95,9 @@
                                name="foo" 
                                class="form-control" 
                                ng-model="selectedTei[attribute.id]" 
-                               ng-model-options="{ updateOn: 'blur' }" 
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
                                ng-disabled="editingDisabled" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
                                ng-required="attribute.mandatory || attribute.unique">                                   
@@ -108,10 +108,10 @@
                                name="foo" 
                                class="form-control-trimmed" 
                                ng-model="selectedTei[attribute.id]" 
-                               ng-model-options="{ updateOn: 'blur' }" 
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               ng-model-options="{ updateOn: 'blur' }"
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                ng-disabled="true" 
                                ng-blur="teiValueUpdated(selectedTei, attribute.id)"
                                style="width:75%;"
@@ -128,9 +128,9 @@
                                name="foo" 
                                class="form-control" 
                                ng-model="selectedTei[attribute.id]" 
-                               ng-model-options="{ updateOn: 'blur' }" 
+                               ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
+                               attribute-data="attribute" selected-program="selectedProgram.id"  
                                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/i18n/i18n_app.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/i18n/i18n_app.properties	2015-10-06 10:52:09 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/i18n/i18n_app.properties	2015-10-08 07:53:00 +0000
@@ -367,4 +367,5 @@
 show_main_menu=Show main menu
 stick_right_widgets=Stick right side widgets
 unstick_right_widgets=Unstick right side widgets
-existing_associate=Existing associate
\ No newline at end of file
+existing_associate=Existing associate
+value_not_unique=Value not unique
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/error-messages.html'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/error-messages.html	2015-10-07 13:47:02 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/angular-forms/error-messages.html	2015-10-08 07:53:00 +0000
@@ -9,4 +9,4 @@
 <span ng-message="optionValidator">{{'option_required' | translate}}</span>
 <span ng-message="latitudeValidator">{{'latitude_required' | translate}}</span>
 <span ng-message="longitudeValidator">{{'longitude_required' | translate}}</span>
-<span ng-message="uniqunessValidator">{{'longitude_required' | translate}}</span>
+<span ng-message="uniqunessValidator">{{'value_not_unique' | translate}}</span>

=== 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-09-30 07:30:39 +0000
+++ 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
@@ -135,4 +135,55 @@
             };
         }
     };
+})
+
+.directive("d2AttributeValidator", function($q, TEIService, AttributesFactory, EntityQueryFactory, SessionStorageService) {
+    return {
+        restrict: "A",         
+        require: "ngModel", 
+        scope: {
+            'attributeData': '=',
+            'selectedProgram': '='
+        },
+        link: function(scope, element, attrs, ngModel) {
+            
+            if( scope.attributeData && scope.attributeData.unique ){                
+ 
+                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';
+                    
+                    if (currentValue) {
+                        
+                        scope.attributeData.value = currentValue;
+                        var atts = AttributesFactory.generateAttributeFilters([scope.attributeData]);
+                        var attUrl = EntityQueryFactory.getAttributesQuery(atts, null);                        
+                        var ouId = SessionStorageService.get('ouSelected');
+                        
+                        if(scope.selectedProgram && scope.attributeData.programScope){
+                            programUrl = 'program=' + scope.selectedProgram;
+                        }
+                        
+                        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();
+                            }
+                        });
+                    }
+                    else {
+                        deferred.resolve();
+                    }
+
+                    return deferred.promise;
+                };
+            }            
+        }
+    };
 });
\ No newline at end of file