← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18027: event-capture - event exection date is now part of custom form

 

------------------------------------------------------------
revno: 18027
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 16:40:31 +0100
message:
  event-capture - event exection date is now part of custom form
modified:
  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-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/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-01-16 12:24:19 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-01-16 15:40:31 +0000
@@ -773,7 +773,6 @@
     };
     
     $scope.isFormInvalid = function(){
-        
         if($scope.outerForm.submitted){
             return $scope.outerForm.$invalid;
         }
@@ -801,7 +800,7 @@
         return formIsInvalid;
     };
     
-    $scope.getErrorMessage = function(deId){
-        return ErrorMessageService.get(deId);
+    $scope.getErrorMessage = function(id){
+        return ErrorMessageService.get(id);
     };
 });

=== 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-16 12:24:19 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-01-16 15:40:31 +0000
@@ -34,8 +34,7 @@
                            name="eventDate"
                            input-field-id="eventDate"
                            style="width:99%;"/>
-                    <span ng-show="outerForm.eventDate.$invalid && outerForm.eventDate.$dirty || currentEvent.eventDate && outerForm.eventDate.$invalid || outerForm.submitted && outerForm.eventDate.$invalid" class="required">{{getErrorMessage('eventDate')}}</span>
-                    <!--<span ng-show="outerForm.eventDate.$invalid && outerForm.eventDate.$dirty" class="required">{{'required' | translate}}</span>-->
+                    <span ng-show="outerForm.eventDate.$invalid && outerForm.eventDate.$dirty || currentEvent.eventDate && outerForm.eventDate.$invalid || outerForm.submitted && outerForm.eventDate.$invalid" class="required">{{getErrorMessage('eventDate')}}</span>                    
                 </td>
             </tr>
             <tr ng-if="selectedProgramStage.captureCoordinates">

=== 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-16 12:24:19 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/ec-custom-form.html	2015-01-16 15:40:31 +0000
@@ -7,7 +7,7 @@
             <input type="text" ng-disabled="true" ng-model="currentEvent['uid']" style="width:99%;">
         </td>
     </tr>
-    <tr>
+    <tr ng-if="!customForm.hasEventDate">
         <td>
             {{selectedProgramStage.reportDateDescription ? selectedProgramStage.reportDateDescription : 'incident_date'| translate }}
         </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-13 22:47:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/directives.js	2015-01-16 15:40:31 +0000
@@ -189,7 +189,7 @@
         restrict: 'A',
         link: function (scope, element, attrs, ctrl) {
             element.bind('blur', function () {                
-                if(ctrl.$viewValue && !ctrl.$modelValue){
+                if(ctrl.$viewValue && !ctrl.$modelValue){                    
                     ctrl.$setViewValue();
                     ctrl.$render();
                 }                
@@ -412,7 +412,7 @@
         restrict: 'E',
         link: function(scope, elm, attrs){            
              scope.$watch('customForm', function(){
-                 elm.html(scope.customForm);
+                 elm.html(scope.customForm.htmlCode);
                  $compile(elm.contents())(scope);
              });
         }

=== 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-16 12:24:19 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/angular/plugins/dhis2/services.js	2015-01-16 15:40:31 +0000
@@ -203,103 +203,128 @@
                         attributes[this.nodeName] = this.value;                       
                     });
                     
-                    var deId = '', newInputField;     
+                    var fieldId = '', errorMessageId = '', newInputField, hasEventDate = false;     
                     if(attributes.hasOwnProperty('id')){
-                        deId = attributes['id'].substring(4, attributes['id'].length-1).split("-")[1]; 
-                        
-                        //name needs to be unique so that it can be used for validation in angularjs
-                        if(attributes.hasOwnProperty('name')){
-                            attributes['name'] = deId;
-                        }
-                        
-                        //check data element type and generate corresponding angular input field
-                        if(programStageDataElements[deId].dataElement.type == "int"){
-                            newInputField = '<input type="text" ' +
-                                            this.getAttributesAsString(attributes) +
-                                            ' d2-validation ' +
-                                            ' d2-number-validation ' +
-                                            ' number-type="' + programStageDataElements[deId].dataElement.numberType + '" ' +
-                                            ' ng-model="currentEvent.' + deId + '"' +
-                                            ' input-field-id=" ' + deId + '"' +
-                                            ' ng-class="getInputNotifcationClass(prStDes.' + deId + '.dataElement.id,true)"' +
-                                            ' ng-blur="saveDatavalue(prStDes.'+ deId + ')"' + 
-                                            ' ng-required="{{prStDes.' + deId + '.compulsory}}"> ';                                     
-                        }
-                        if(programStageDataElements[deId].dataElement.type == "string"){
-                            if(programStageDataElements[deId].dataElement.optionSet){
-                                var optionSetId = programStageDataElements[deId].dataElement.optionSet.id;
-                        		newInputField = '<input type="text" ' +
-                                            this.getAttributesAsString(attributes) +
-                                            ' d2-validation ' +
-                                            ' ng-model="currentEvent.' + deId + '" ' +
-                                            ' input-field-id=" ' + deId + '"' +
-                                            ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
-                                            ' ng-required="{{prStDes.' + deId + '.compulsory}}"' +
-                                            ' typeahead="option.name as option.name for option in optionSets.'+optionSetId+'.options | filter:$viewValue | limitTo:20"' +
-                                            ' typeahead-editable="false" ' +
-                                            ' d2-typeahead-validation ' +
-                                            ' class="typeahead" ' +
-                                            ' placeholder="&#xf0d7;&nbsp;&nbsp;" ' +
-                                            ' ng-class="getInputNotifcationClass(prStDes.' + deId + '.dataElement.id,true)"' +                                            
-                                            ' ng-blur="saveDatavalue(prStDes.'+ deId + ')"' +
-                                            ' typeahead-open-on-focus ng-required="prStDes.'+deId+'.compulsory"> ';
-                        	}
-                        	else{
-                        		newInputField = '<input type="text" ' +
-                                            this.getAttributesAsString(attributes) +
-                                            ' d2-validation ' +
-                                            ' ng-model="currentEvent.' + deId + '" ' +
-                                            ' input-field-id=" ' + deId + '"' +
-                                            ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
-                                            ' ng-class="getInputNotifcationClass(prStDes.' + deId + '.dataElement.id,true)"' +
-                                            ' ng-blur="saveDatavalue(prStDes.'+ deId + ')"' +
-                                            ' ng-required="prStDes.' + deId + '.compulsory"> ';                                     
-                        	}
-                        }
-                        if(programStageDataElements[deId].dataElement.type == "bool"){
-                            newInputField = '<select ' +
-                                            this.getAttributesAsString(attributes) +
-                                            ' d2-validation ' +
-                                            ' ng-model="currentEvent.' + deId + '" ' +
-                                            ' input-field-id=" ' + deId + '"' +
-                                            ' ng-class="getInputNotifcationClass(prStDes.' + deId + '.dataElement.id,true)"' +
-                                            ' ng-change="saveDatavalue(prStDes.'+ deId + ')"' + 
-                                            ' ng-required="{{prStDes.' + deId + '.compulsory}}">' + 
-                                            '<option value="">{{\'please_select\'| translate}}</option>' +
-                                            '<option value="false">{{\'no\'| translate}}</option>' + 
-                                            '<option value="true">{{\'yes\'| translate}}</option>' +
-                                            '</select> ';                                     
-                        }
-                        if(programStageDataElements[deId].dataElement.type == "date"){
-                        	var maxDate = programStageDataElements[deId].allowFutureDate ? '' : 0;
-                            newInputField = '<input type="text" ' +
-                                            this.getAttributesAsString(attributes) +
-                                            ' d2-validation ' +
-                                            ' ng-model="currentEvent.' + deId + '"' +
-                                            ' input-field-id=" ' + deId + '"' +
-                                            ' d2-date ' +
-                                            ' max-date="' + maxDate + '"' + '\'' +
-                                            ' ng-class="getInputNotifcationClass(prStDes.' + deId + '.dataElement.id,true)"' +
-                                            ' blur-or-change="saveDatavalue(prStDes.'+ deId + ')"' + 
-                                            ' ng-required="{{prStDes.' + deId + '.compulsory}}"> '; 
-                        }
-                        if(programStageDataElements[deId].dataElement.type == "trueOnly"){
-                            newInputField = '<input type="checkbox" ' +
-                                            this.getAttributesAsString(attributes) +
-                                            ' d2-validation ' +
-                                            ' ng-model="currentEvent.' + deId + '"' +
-                                            ' input-field-id=" ' + deId + '"' +
-                                            ' ng-class="getInputNotifcationClass(prStDes.' + deId + '.dataElement.id,true)"' +
-                                            ' ng-change="saveDatavalue(prStDes.'+ deId + ')"' +
-                                            ' ng-required="{{prStDes.' + deId + '.compulsory}}"> ';
-                        }
-						
-						newInputField = newInputField + ' <span ng-show="(outerForm.'+ deId +'.$dirty && outerForm.'+ deId +'.$invalid) || (outerForm.submitted && outerForm.'+ deId +'.$invalid) || (currentEvent.' + deId + ' && outerForm.' + deId + '.$invalid)" class="required">{{getErrorMessage(prStDes.' + deId + '.dataElement.id)}}</span> ';                                        
-						
+                        
+                        if(attributes['id'] === 'executionDate'){
+                            fieldId = 'eventDate';
+                            errorMessageId = '"' + 'eventDate' + '"';
+                            hasEventDate = true;
+                            
+                            //name needs to be unique so that it can be used for validation in angularjs
+                            if(attributes.hasOwnProperty('name')){
+                                attributes['name'] = fieldId;
+                            }
+                            
+                            newInputField = '<input type="text" ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' ng-model="currentEvent.' + fieldId + '"' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' d2-date ' +
+                                                ' max-date="' + 0 + '"' + 
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
+                                                ' blur-or-change="saveDatavalue(prStDes.'+ fieldId + ')"' + 
+                                                ' ng-required="{{true}}">';
+                        }
+                        else{
+                            fieldId = attributes['id'].substring(4, attributes['id'].length-1).split("-")[1]; 
+                            errorMessageId = 'prStDes.' + fieldId + '.dataElement.id';
+                            
+                            //name needs to be unique so that it can be used for validation in angularjs
+                            if(attributes.hasOwnProperty('name')){
+                                attributes['name'] = fieldId;
+                            }
+
+                            //check data element type and generate corresponding angular input field
+                            if(programStageDataElements[fieldId].dataElement.type === "int"){
+                                newInputField = '<input type="text" ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' d2-number-validation ' +
+                                                ' number-type="' + programStageDataElements[fieldId].dataElement.numberType + '" ' +
+                                                ' ng-model="currentEvent.' + fieldId + '"' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
+                                                ' ng-blur="saveDatavalue(prStDes.'+ fieldId + ')"' + 
+                                                ' ng-required="{{prStDes.' + fieldId + '.compulsory}}">';
+                            }
+                            if(programStageDataElements[fieldId].dataElement.type === "string"){
+                                if(programStageDataElements[fieldId].dataElement.optionSet){
+                                    var optionSetId = programStageDataElements[fieldId].dataElement.optionSet.id;
+                                    newInputField = '<input type="text" ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' ng-model="currentEvent.' + fieldId + '" ' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
+                                                ' ng-required="{{prStDes.' + fieldId + '.compulsory}}"' +
+                                                ' typeahead="option.name as option.name for option in optionSets.'+optionSetId+'.options | filter:$viewValue | limitTo:20"' +
+                                                ' typeahead-editable="false" ' +
+                                                ' d2-typeahead-validation ' +
+                                                ' class="typeahead" ' +
+                                                ' placeholder="&#xf0d7;&nbsp;&nbsp;" ' +
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +                                            
+                                                ' ng-blur="saveDatavalue(prStDes.'+ fieldId + ')"' +
+                                                ' typeahead-open-on-focus ng-required="prStDes.'+fieldId+'.compulsory"> ';
+                                }
+                                else{
+                                    newInputField = '<input type="text" ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' ng-model="currentEvent.' + fieldId + '" ' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
+                                                ' ng-blur="saveDatavalue(prStDes.'+ fieldId + ')"' +
+                                                ' ng-required="prStDes.' + fieldId + '.compulsory"> ';                                     
+                                }
+                            }
+                            if(programStageDataElements[fieldId].dataElement.type === "bool"){
+                                newInputField = '<select ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' ng-model="currentEvent.' + fieldId + '" ' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
+                                                ' ng-change="saveDatavalue(prStDes.'+ fieldId + ')"' + 
+                                                ' ng-required="{{prStDes.' + fieldId + '.compulsory}}">' + 
+                                                '<option value="">{{\'please_select\'| translate}}</option>' +
+                                                '<option value="false">{{\'no\'| translate}}</option>' + 
+                                                '<option value="true">{{\'yes\'| translate}}</option>' +
+                                                '</select> ';                                     
+                            }
+                            if(programStageDataElements[fieldId].dataElement.type === "date"){
+                                var maxDate = programStageDataElements[fieldId].allowFutureDate ? '' : 0;
+                                newInputField = '<input type="text" ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' ng-model="currentEvent.' + fieldId + '"' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' d2-date ' +
+                                                ' max-date="' + maxDate + '"' + '\'' +
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
+                                                ' blur-or-change="saveDatavalue(prStDes.'+ fieldId + ')"' + 
+                                                ' ng-required="{{prStDes.' + fieldId + '.compulsory}}"> '; 
+                            }
+                            if(programStageDataElements[fieldId].dataElement.type === "trueOnly"){
+                                newInputField = '<input type="checkbox" ' +
+                                                this.getAttributesAsString(attributes) +
+                                                ' d2-validation ' +
+                                                ' ng-model="currentEvent.' + fieldId + '"' +
+                                                ' input-field-id=" ' + fieldId + '"' +
+                                                ' ng-class="getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id,true)"' +
+                                                ' ng-change="saveDatavalue(prStDes.'+ fieldId + ')"' +
+                                                ' ng-required="{{prStDes.' + fieldId + '.compulsory}}"> ';
+                            }                            
+                        }
+						
+                        newInputField = newInputField + ' <span ng-show="(outerForm.'+ fieldId +'.$dirty && outerForm.'+ fieldId +'.$invalid) || (outerForm.submitted && outerForm.'+ fieldId +'.$invalid) || (currentEvent.' + fieldId + ' && outerForm.' + fieldId + '.$invalid)" class="required">{{getErrorMessage(' + errorMessageId + ')}}</span> ';
+                        
                         htmlCode = htmlCode.replace(inputField, newInputField);
                     }
                 }
-                return htmlCode;                
+                return {htmlCode: htmlCode, hasEventDate: hasEventDate};
             }
             return null;
         },
@@ -307,7 +332,7 @@
             if(attributes){
                 var attributesAsString = '';                
                 for(var prop in attributes){
-                    if(prop != 'value'){
+                    if(prop !== 'value'){
                         attributesAsString += prop + '="' + attributes[prop] + '" ';
                     }
                 }