← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20413: event-capture: better detection of canceling event creation/updation

 

------------------------------------------------------------
revno: 20413
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-30 09:30:39 +0200
message:
  event-capture: better detection of canceling event creation/updation
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.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-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-09-25 14:43:20 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-09-30 07:30:39 +0000
@@ -872,12 +872,13 @@
     
     $scope.formIsChanged = function(){        
         var isChanged = false;
+        var emptyForm = $scope.formIsEmpty();
         for(var i=0; i<$scope.selectedProgramStage.programStageDataElements.length && !isChanged; i++){
             var deId = $scope.selectedProgramStage.programStageDataElements[i].dataElement.id;
-            if($scope.currentEventOriginialValue[deId] !== $scope.currentEvent[deId] && 
-                    !$scope.currentEvent[deId] && 
-                    $scope.currentEventOriginialValue[deId] !== ""){                                       
-                isChanged = true;                
+            if($scope.currentEventOriginialValue[deId] !== $scope.currentEvent[deId]){
+                if($scope.currentEvent[deId] || $scope.currentEventOriginialValue[deId] !== "" && !emptyForm){                    
+                    isChanged = true; 
+                }                               
             }
         }        
         if(!isChanged){
@@ -918,6 +919,15 @@
         return formIsInvalid;
     };
     
+    $scope.formIsEmpty = function(){
+        for(var dataElement in $scope.prStDes){
+            if($scope.currentEvent[dataElement]){
+                return false;
+            }
+        }
+        return true;
+    };
+    
     //watch for event editing
     $scope.$watchCollection('[editingEventInFull, eventRegistration]', function() {        
         if($scope.editingEventInFull || $scope.eventRegistration){

=== 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-07 12:18:28 +0000
+++ 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
@@ -111,7 +111,7 @@
     };
 })
 
-.directive("d2OptionValidator", function($translate) {
+.directive("d2OptionValidator", function($translate, DialogService) {
     return {
         restrict: "A",         
         require: "ngModel",         
@@ -124,7 +124,11 @@
                 var res = !value ? !isRequired : true;
                 
                 if(!res){
-                    alert($translate.instant('option_required'));
+                	var dialogOptions = {
+		                headerText: 'validation_error',
+		                bodyText: 'option_required'
+		            };		
+		            DialogService.showDialog({}, dialogOptions);
                 }
                 
                 return res;