← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18125: event-capture - disable ou selection when there is unsaved data. The only way out is cancel. Oncl...

 

------------------------------------------------------------
revno: 18125
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-01-26 18:47:09 +0100
message:
  event-capture - disable ou selection when there is unsaved data. The only way out is cancel. Onclick of cancel provide user notification dialog
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties
  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/views/defaultForm.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/ec-custom-form.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/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-event-capture/i18n/i18n_app.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties	2015-01-20 14:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties	2015-01-26 17:47:09 +0000
@@ -127,5 +127,8 @@
 loading_tree=Loading orgunit tree
 loading_metadata=Loading meta-data
 future_date_not_allowed=Future date is not allowed
+warning=Warning
+unsaved_data_exists_proceed=Unsaved data exists. Do you want to proceed?
+proceed=Proceed
 
 

=== 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-01-22 16:55:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-01-26 17:47:09 +0000
@@ -41,11 +41,14 @@
     $scope.editingEventInGrid = false;   
     $scope.updateSuccess = false;
     $scope.currentGridColumnId = '';  
-    $scope.currentEventOrginialValue = '';   
+    $scope.dhis2Events = [];
+    $scope.currentEvent = {};
+    $scope.currentEventOriginialValue = {}; 
     $scope.displayCustomForm = false;
     $scope.currentElement = {id: '', update: false};
-    $scope.selectedOrgUnit = '';
     $scope.optionSets = [];
+    $scope.proceedSelection = true;
+    $scope.formUnsaved = false;
     
     //notes
     $scope.note = {};
@@ -54,39 +57,44 @@
     var userAccount = storage.get('USER_PROFILE');
     var storedBy = userAccount ? userAccount.userName : '';    
     $scope.noteExists = false;
+    storage.remove('SELECTED_OU');   
         
     //watch for selection of org unit from tree
     $scope.$watch('selectedOrgUnit', function() {
-        $scope.dhis2Events = [];
-        $scope.currentEvent = {};
         
-        if( angular.isObject($scope.selectedOrgUnit)){
+        if(angular.isObject($scope.selectedOrgUnit)){
+            storage.set('SELECTED_OU', $scope.selectedOrgUnit);
             if($scope.optionSets.length < 1){
                 $scope.optionSets = [];
                 OptionSetService.getAll().then(function(optionSets){
-                    angular.forEach(optionSets, function(optionSet){                        
+                    angular.forEach(optionSets, function(optionSet){  
                         $scope.optionSets[optionSet.id] = optionSet;
                     });                    
+                    $scope.loadPrograms();
                 });
-            }            
-            $scope.loadPrograms();
-        }
+            }
+            else{
+                $scope.loadPrograms();
+            }
+        }        
     });
     
     //load programs associated with the selected org unit.
     $scope.loadPrograms = function() {
         
+        $scope.resetOu = false;
         $scope.selectedProgram = null;
         $scope.selectedProgramStage = null;
         $scope.dhis2Events = [];
+        $scope.currentEvent = {};
+        $scope.currentEventOriginialValue = {};
 
         $scope.eventRegistration = false;
         $scope.editGridColumns = false;
         $scope.editingEventInFull = false;
         $scope.editingEventInGrid = false;   
         $scope.updateSuccess = false;
-        $scope.currentGridColumnId = '';  
-        $scope.currentEventOrginialValue = ''; 
+        $scope.currentGridColumnId = '';           
         $scope.displayCustomForm = false;
         
         if (angular.isObject($scope.selectedOrgUnit)) {    
@@ -152,13 +160,14 @@
 
                     errorMessages[prStDe.dataElement.id] = "";
                     if(prStDe.compulsory){
-                        errorMessages[prStDe.dataElement.id] = $translate('required');
+                        var msg = $translate('required');
+                        if(prStDe.dataElement.type === 'int'){
+                            msg = $translate(prStDe.dataElement.numberType)+ ' ' + $translate('required');
+                        }
+                        errorMessages[prStDe.dataElement.id] = msg;
                     }
 
-                    $scope.newDhis2Event[prStDe.dataElement.id] = '';
-                    if($scope.selectedProgramStage.captureCoordinates){
-                        $scope.newDhis2Event.coordinate = {};
-                    }
+                    $scope.newDhis2Event[prStDe.dataElement.id] = '';                    
 
                     //generate grid headers using program stage data elements
                     //create a template for new event
@@ -176,6 +185,12 @@
                         $scope.filterText[prStDe.dataElement.id]= {};
                     }
                 });
+                
+                if($scope.selectedProgramStage.captureCoordinates){
+                    $scope.newDhis2Event.coordinate = {};
+                }
+                $scope.newDhis2Event.eventDate = '';
+                
 
                 ErrorMessageService.setErrorMessages(errorMessages);
                 
@@ -245,7 +260,7 @@
                                                 val = new Number(val);
                                             }                                
                                         }
-                                        if($scope.prStDes[dataValue.dataElement].dataElement.type === 'string'){
+                                        if($scope.prStDes[dataValue.dataElement].dataElement.type === 'string'){                                            
                                             if($scope.prStDes[dataValue.dataElement].dataElement.optionSet &&
                                                     $scope.prStDes[dataValue.dataElement].dataElement.optionSet.id &&
                                                     $scope.optionSets[$scope.prStDes[dataValue.dataElement].dataElement.optionSet.id] &&
@@ -384,23 +399,39 @@
         $scope.filterText[gridColumnId].end = undefined;
     };
     
+    $scope.cancel = function(){
+        
+        if($scope.formHasUnsavedData()){
+            var modalOptions = {
+                closeButtonText: 'cancel',
+                actionButtonText: 'proceed',
+                headerText: 'warning',
+                bodyText: 'unsaved_data_exists_proceed'
+            };
+
+            ModalService.showModal({}, modalOptions).then(function(result){            
+                $scope.showEventList();
+            });
+        }
+        else{
+            $scope.showEventList();
+        }
+    };
+    
     $scope.showEventList = function(){
         $scope.eventRegistration = false;
         $scope.editingEventInFull = false;
         $scope.editingEventInGrid = false;
-        $scope.currentElement.updated = false;
-        
-        //$scope.outerForm.$valid = true;
-        
+        $scope.currentElement.updated = false;        
         $scope.currentEvent = {};
+        $scope.currentEventOriginialValue = angular.copy($scope.currentEvent);
     };
     
     $scope.showEventRegistration = function(){        
         $scope.displayCustomForm = $scope.customForm ? true:false;        
         $scope.currentEvent = {};
         $scope.eventRegistration = !$scope.eventRegistration;          
-        $scope.currentEvent = angular.copy($scope.newDhis2Event);
-        $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);        
+        $scope.currentEvent = angular.copy($scope.newDhis2Event);        
         $scope.outerForm.submitted = false;
         $scope.note = {};
         
@@ -408,11 +439,12 @@
             $scope.eventUID = dhis2.util.uid();
             $scope.currentEvent['uid'] = $scope.eventUID;
         }        
+        $scope.currentEventOriginialValue = angular.copy($scope.currentEvent);        
     };    
     
     $scope.showEditEventInGrid = function(){
         $scope.currentEvent = ContextMenuSelectedItem.getSelectedItem();
-        $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);
+        $scope.currentEventOriginialValue = angular.copy($scope.currentEvent);
         $scope.editingEventInGrid = !$scope.editingEventInGrid;
         
         $scope.outerForm.$valid = true;
@@ -420,10 +452,9 @@
     
     $scope.showEditEventInFull = function(){       
         $scope.note = {};
-        $scope.displayCustomForm = $scope.customForm ? true:false;                
+        $scope.displayCustomForm = $scope.customForm ? true:false;
 
-        $scope.currentEvent = ContextMenuSelectedItem.getSelectedItem();  
-        $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);
+        $scope.currentEvent = ContextMenuSelectedItem.getSelectedItem();
         $scope.editingEventInFull = !$scope.editingEventInFull;   
         $scope.eventRegistration = false;
         
@@ -431,7 +462,9 @@
             if(!$scope.currentEvent.hasOwnProperty(prStDe.dataElement.id)){
                 $scope.currentEvent[prStDe.dataElement.id] = '';
             }
-        });        
+        }); 
+        $scope.currentEventOriginialValue = angular.copy($scope.currentEvent);
+        
     };
     
     $scope.switchDataEntryForm = function(){
@@ -544,11 +577,11 @@
                 //reset form              
                 $scope.currentEvent = {};
                 $scope.currentEvent = angular.copy($scope.newDhis2Event); 
+                $scope.currentEventOriginialValue = angular.copy($scope.currentEvent);
                                
                 $scope.note = {};
                 $scope.outerForm.submitted = false;
                 $scope.outerForm.$setPristine();
-                $scope.outerForm.$setValidity();
                 $scope.disableSaveAndAddNew = false;
                 
                 //this is to hide typeAheadPopUps - shouldn't be an issue in 
@@ -625,12 +658,11 @@
         DHIS2EventFactory.update(updatedEvent).then(function(data){            
             
             //reflect the change in the gird            
-            $scope.resetEventValue($scope.currentEvent);
-                
-            $scope.currentEventOrginialValue = angular.copy($scope.currentEvent); 
+            $scope.resetEventValue($scope.currentEvent);            
             $scope.outerForm.submitted = false;            
             $scope.editingEventInFull = false;
             $scope.currentEvent = {};
+            $scope.currentEventOriginialValue = angular.copy($scope.currentEvent); 
         });       
     };
        
@@ -643,7 +675,7 @@
         
         //get new and old values
         var newValue = $scope.currentEvent[dataElement];        
-        var oldValue = $scope.currentEventOrginialValue[dataElement];
+        var oldValue = $scope.currentEventOriginialValue[dataElement];
         
         //check for form validity
         if( $scope.isFormInvalid() ){
@@ -682,7 +714,7 @@
                 $scope.resetEventValue($scope.currentEvent);
                 
                 //update original value
-                $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);      
+                $scope.currentEventOriginialValue = angular.copy($scope.currentEvent);      
                 
                 $scope.currentElement.updated = true;
                 $scope.updateSuccess = true;
@@ -776,12 +808,12 @@
         var isChanged = false;
         for(var i=0; i<$scope.selectedProgramStage.programStageDataElements.length && !isChanged; i++){
             var deId = $scope.selectedProgramStage.programStageDataElements[i].dataElement.id;
-            if($scope.currentEvent[deId] && $scope.currentEventOrginialValue[deId] !== $scope.currentEvent[deId]){
+            if($scope.currentEvent[deId] && $scope.currentEventOriginialValue[deId] !== $scope.currentEvent[deId]){
                 isChanged = true;
             }
         }        
         if(!isChanged){
-            if($scope.currentEvent.eventDate !== $scope.currentEventOrginialValue.eventDate){
+            if($scope.currentEvent.eventDate !== $scope.currentEventOriginialValue.eventDate){
                 isChanged = true;
             }
         }
@@ -820,4 +852,23 @@
     $scope.getErrorMessage = function(id){
         return ErrorMessageService.get(id);
     };
-});
+    
+    $scope.formHasUnsavedData = function(){        
+        if(angular.isObject($scope.currentEvent) && angular.isObject($scope.currentEventOriginialValue)){
+            return !angular.equals($scope.currentEvent, $scope.currentEventOriginialValue);
+        }
+        return false;
+    };
+    
+    //watch for event editing
+    $scope.$watchCollection('[editingEventInFull, eventRegistration]', function() {        
+        if($scope.editingEventInFull || $scope.eventRegistration){
+            //Disable ou selection while in editing mode
+            $( "#orgUnitTree" ).addClass( "disable-clicks" );
+        }
+        else{
+            //enable ou selection if not in editing mode
+            $( "#orgUnitTree" ).removeClass( "disable-clicks" );
+        }
+    });
+});
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-01-21 20:24:38 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-01-26 17:47:09 +0000
@@ -384,12 +384,12 @@
 <div style="clear: both;">                        
     <span ng-if="editingEventInFull">
         <button type="button" ng-click="updateEvent()" class="button not-printable">{{'update'| translate}}</button>
-        <button type="button" ng-click="showEventList()" class="button not-printable">{{'go_back'| translate}}</button>
+        <button type="button" ng-click="cancel()" class="button not-printable">{{'cancel'| translate}}</button>
     </span>
     <span ng-if="eventRegistration">
         <button type="button" ng-disabled="disableSaveAndAddNew" ng-click="addEvent(true)" class="button not-printable">{{'save_and_add_new'| translate}}</button>
         <button type="button" ng-click="addEvent()" class="button not-printable">{{'save_and_back'| translate}}</button>
-        <button type="button" ng-click="showEventList(null)" class="button not-printable">{{'go_back'| translate}}</button>        
+        <button type="button" ng-click="cancel()" class="button not-printable">{{'cancel'| translate}}</button>        
     </span>
     <span ng-if="isFormInvalid()" class="horizontal-spacing red">{{'form_invalid' | translate}}</span>
         

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/ec-custom-form.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/ec-custom-form.html	2015-01-21 20:24:38 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/ec-custom-form.html	2015-01-26 17:47:09 +0000
@@ -89,12 +89,12 @@
 <div style="clear: both;">                        
     <span ng-if="editingEventInFull">
         <button type="button" ng-click="updateEvent()" class="button not-printable">{{'update'| translate}}</button>
-        <button type="button" ng-click="showEventList()" class="button not-printable">{{'go_back'| translate}}</button>
+        <button type="button" ng-click="cancel()" class="button not-printable">{{'cancel'| translate}}</button>
     </span>
     <span ng-if="eventRegistration">
         <button type="button" ng-disabled="disableSaveAndAddNew" ng-click="addEvent(true)" class="button not-printable">{{'save_and_add_new'| translate}}</button>
         <button type="button" ng-click="addEvent()" class="button not-printable">{{'save_and_back'| translate}}</button>
-        <button type="button" ng-click="showEventList(null)" class="button not-printable">{{'go_back'| translate}}</button>
+        <button type="button" ng-click="cancel()" class="button not-printable">{{'cancel'| translate}}</button>
     </span>
     <span ng-if="isFormInvalid()" class="horizontal-spacing red">{{'form_invalid' | translate}}</span>
 </div>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html	2015-01-20 14:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/home.html	2015-01-26 17:47:09 +0000
@@ -28,7 +28,14 @@
         <table>
             <tr>
                 <td><label>{{'registering_unit'| translate}}</label></td>
-                <td><input type="text" class="fixed-width-text" selected-org-unit ng-model="selectedOrgUnit.name" value="{{selectedOrgUnit.name|| 'please_select'| translate}}" disabled="" style="height:14px"></td>                        	                            
+                <td><input type="text" 
+                           class="fixed-width-text" 
+                           selected-org-unit 
+                           ng-model="selectedOrgUnit.name"
+                           value="{{selectedOrgUnit.name|| 'please_select'| translate}}" 
+                           disabled="" 
+                           style="height:14px">
+                </td>                        	                            
             </tr>
             <tr>
                 <td><label>{{'program'| translate}}</label></td>

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js	2015-01-20 14:36:12 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js	2015-01-26 17:47:09 +0000
@@ -149,7 +149,8 @@
             var fieldName = attrs.inputFieldId;
             var numberType = attrs.numberType;
             var isRequired = attrs.ngRequired === 'true';
-            
+            var msg = $translate(numberType)+ ' ' + $translate('required');
+           
             ctrl.$parsers.unshift(function(value) {
             	if(value){
                     var isValid = checkValidity(numberType, value);                    
@@ -158,7 +159,7 @@
                     }
                     else{
                         if(isRequired){
-                            errorMessages[fieldName] = $translate('required');
+                            errorMessages[fieldName] = msg;
                         }
                         else{
                             errorMessages[fieldName] = "";
@@ -172,7 +173,7 @@
                 
                 if(value === ''){
                     if(isRequired){
-                        errorMessages[fieldName] = $translate('required');
+                        errorMessages[fieldName] = msg;
                     }
                     else{
                         ctrl.$setValidity(fieldName, true);

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js	2015-01-19 17:16:47 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js	2015-01-26 17:47:09 +0000
@@ -223,6 +223,7 @@
                                                 ' input-field-id="' + fieldId + '"' +
                                                 ' d2-date ' +
                                                 ' max-date="' + 0 + '"' + 
+                                                ' placeholder="{{dhis2CalendarFormat.keyDateFormat}}" ' +
                                                 ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
                                                 ' blur-or-change="saveDatavalue(prStDes.'+ fieldId + ')"' + 
                                                 ' ng-required="{{true}}">';
@@ -302,7 +303,8 @@
                                                 this.getAttributesAsString(attributes) +
                                                 ' d2-validation ' +
                                                 ' ng-model="currentEvent.' + fieldId + '"' +
-                                                ' input-field-id="' + fieldId + '"' +
+                                                ' input-field-id="' + fieldId + '"' +                                                
+                                                ' placeholder="{{dhis2CalendarFormat.keyDateFormat}}" ' +
                                                 ' d2-date ' +
                                                 ' max-date="' + maxDate + '"' +
                                                 ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +