← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20606: tracker-capture: unique attribute value detection directive now uses attribute instead of isolate...

 

------------------------------------------------------------
revno: 20606
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-09 17:13:55 +0200
message:
  tracker-capture: unique attribute value detection directive now uses attribute instead of isolated scope as it created a conflict with ui-select.
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/scripts/services.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-09 13:42:57 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/default-registration-form.html	2015-10-09 15:13:55 +0000
@@ -9,9 +9,13 @@
                 <span ng-if="attribute.optionSetValue">
                     <ui-select  ng-model="selectedTei[attribute.id]" 
                                 theme="select2" 
-                                ng-required="attribute.mandatory || attribute.unique"
-                                ng-disabled="editingDisabled"
+                                ng-required="attribute.mandatory || attribute.unique"                                 
                                 name="foo" 
+                                d2-attribute-validator
+                                attribute-data={{attribute}}
+                                selected-program-id={{selectedProgram.id}}  
+                                selected-tei-id={{selectedTei.trackedEntityInstance}}  
+                                ng-disabled="editingDisabled" 
                                 on-select="teiValueUpdated(selectedTei, attribute.id)"
                                 style="width:100%;">
                         <ui-select-match allow-clear="true"  class="form-control-ui-select"  placeholder="{{'select_or_search' | translate}}">{{$select.selected.name  || $select.selected}}</ui-select-match>
@@ -32,9 +36,9 @@
                                ng-model="selectedTei[attribute.id]"
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               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"/>
@@ -46,9 +50,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }"
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               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"/>
@@ -58,9 +62,9 @@
                                 ng-model="selectedTei[attribute.id]" 
                                 ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                 d2-attribute-validator 
-                                attribute-data="attribute" 
-                                selected-program-id="selectedProgram.id"  
-                                selected-tei-id="selectedTei.trackedEntityInstance"  
+                                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)"
@@ -77,9 +81,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               attribute-data={{attribute}}
+                               selected-program-id={{selectedProgram.id}}  
+                               selected-tei-id={{selectedTei.trackedEntityInstance}}  
                                d2-number-validator 
                                number-type={{attribute.valueType}} 
                                ng-disabled="editingDisabled" 
@@ -93,9 +97,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               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"/>
@@ -107,9 +111,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               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">                                   
@@ -122,9 +126,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               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)"
@@ -144,9 +148,9 @@
                                ng-model="selectedTei[attribute.id]" 
                                ng-model-options="{ updateOn: 'blur', allowInvalid: true }" 
                                d2-attribute-validator 
-                               attribute-data="attribute" 
-                               selected-program-id="selectedProgram.id"  
-                               selected-tei-id="selectedTei.trackedEntityInstance"  
+                               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/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-10-09 14:20:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-10-09 15:13:55 +0000
@@ -886,7 +886,7 @@
         },
         generateAttributeFilters: function(attributes){
             angular.forEach(attributes, function(attribute){
-                if(attribute.type === 'number' || attribute.type === 'date'){
+                if(attribute.valueType === 'NUMBER' || attribute.valueType === 'DATE'){
                     attribute.operator = OperatorFactory.defaultOperators[0];
                 }
             });            

=== 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-09 13:42:57 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.validations.js	2015-10-09 15:13:55 +0000
@@ -140,16 +140,10 @@
 .directive("d2AttributeValidator", function($q, TEIService, AttributesFactory, EntityQueryFactory, SessionStorageService) {
     return {
         restrict: "A",         
-        require: "ngModel", 
-        scope: {
-            'attributeData': '=',
-            'selectedProgramId': '=',
-            'selectedTeiId': '=',
-            'ngDisabled': '='
-        },
-        link: function(scope, element, attrs, ngModel) {
+        require: "ngModel",
+        link: function(scope, element, attrs, ngModel) {            
             
-            function uniqunessValidatior(){
+            function uniqunessValidatior(attributeData){
                 
                 ngModel.$asyncValidators.uniqunessValidator = function (modelValue, viewValue) {
                     var pager = {pageSize: 1, page: 1, toolBarDisplay: 5};
@@ -157,22 +151,22 @@
                     
                     if (currentValue) {
                         
-                        scope.attributeData.value = currentValue;
-                        var atts = AttributesFactory.generateAttributeFilters([scope.attributeData]);
+                        attributeData.value = currentValue;
+                        var atts = AttributesFactory.generateAttributeFilters([attributeData]);
                         var attUrl = EntityQueryFactory.getAttributesQuery(atts, null);                        
                         var ouId = SessionStorageService.get('ouSelected');
                         
-                        if(scope.selectedProgram && scope.attributeData.programScope){
-                            programUrl = 'program=' + scope.selectedProgram;
+                        if(attrs.selectedProgram && attributeData.programScope){
+                            programUrl = 'program=' + attrs.selectedProgram;
                         }
                         
-                        if(scope.attributeData.orgUnitScope){
+                        if(attributeData.orgUnitScope){
                             ouMode = 'SELECTED';
                         }                        
 
                         TEIService.search(ouId, ouMode, null, programUrl, attUrl.url, pager, true).then(function(data) {
-                            if(scope.selectedTeiId){
-                                if(data.rows[0][0] !== scope.selectedTeiId){
+                            if(attrs.selectedTeiId){
+                                if(data.rows[0][0] !== attrs.selectedTeiId){
                                     deferred.reject();
                                 }
                             }
@@ -190,15 +184,16 @@
 
                     return deferred.promise;
                 };
-            }
-                      
-            scope.$watch('ngDisabled', function(value){
+            }                      
+            
+            scope.$watch(attrs.ngDisabled, function(value){
+                var attributeData = scope.$eval(attrs.attributeData);
                 if(!value){
-                    if( scope.attributeData && scope.attributeData.unique && !scope.ngDisabled ){                
-                        uniqunessValidatior();
+                    if( attributeData && attributeData.unique && !value ){
+                        uniqunessValidatior(attributeData);
                     }
                 }              
-            });       
+            });     
         }
     };
 });
\ No newline at end of file