← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15844: event capture custom form, input field attributes remain untouched. this is important especially ...

 

------------------------------------------------------------
revno: 15844
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-06-25 13:04:16 +0200
message:
  event capture custom form, input field attributes remain untouched. this is important especially when users develop added functionalities
modified:
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/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-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2014-06-22 07:04:04 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2014-06-25 11:04:16 +0000
@@ -240,7 +240,7 @@
 {
     return function() {
         return $.ajax( {
-            url: '../api/programs.json?filter=id:eq:' + id +'&fields=id,name,version,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,organisationUnits[id,name],programStages[id,name]',
+            url: '../api/programs.json?filter=id:eq:' + id +'&fields=id,name,version,dateOfEnrollmentDescription,dateOfIncidentDescription,displayIncidentDate,ignoreOverdueEvents,organisationUnits[id,name],programStages[id,name,version]',
             type: 'GET'
         }).done( function( response ){
             
@@ -317,7 +317,7 @@
 {
     return function() {
         return $.ajax( {
-            url: '../api/programStages.json?filter=id:eq:' + id +'&fields=id,name,description,reportDateDescription,captureCoordinates,dataEntryForm,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id]]]',
+            url: '../api/programStages.json?filter=id:eq:' + id +'&fields=id,name,version,description,reportDateDescription,captureCoordinates,dataEntryForm,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id]]]',
             type: 'GET'
         }).done( function( response ){            
             _.each( _.values( response.programStages ), function( programStage ) {                

=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-06-25 05:30:24 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-06-25 11:04:16 +0000
@@ -203,57 +203,65 @@
                 });
 
                 var inputRegex = /<input.*?\/>/g,
-                    styleRegex = /style="[^"]*"/,
-                    idRegex = /id="[^"]*"/,
                     match,
                     inputFields = [];                
 
                 while (match = inputRegex.exec(htmlCode)) {                
                     inputFields.push(match[0]);
                 }
-
-                for(var i=0; i<inputFields.length; i++){
-                    var inputField = inputFields[i];
-                    var deId = '', style = '', newInputField;                    
-                    if(match = idRegex.exec(inputFields[i])){     
-                        
-                        deId = match[0].substring(4, match[0].length-1).split("-")[1];                        
-                        
-                        if(match = styleRegex.exec(inputFields[i]) ){
-                            style = match[0];                          
+                
+                for(var i=0; i<inputFields.length; i++){                    
+                    var inputField = inputFields[i];                    
+                    var inputElement = $.parseHTML( inputField );
+                    var attributes = {};
+                                       
+                    $(inputElement[0].attributes).each(function() {
+                        attributes[this.nodeName] = this.nodeValue;                       
+                    });
+                    
+                    var deId = '', newInputField;     
+                    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="number" name="'+ deId +'" ' + 
-                                            style + 
+                            newInputField = '<input type="number" ' +
+                                            this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '"' +
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory">';
                         }
                         if(programStageDataElements[deId].dataElement.type == "string"){
-                            newInputField = '<input type="text" name="'+ deId +'" ' + 
-                                            style + 
+                            newInputField = '<input type="text" ' +
+                                            this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '" ' +
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory"' +
                                             ' typeahead="option for option in programStageDataElements.'+deId+'.dataElement.optionSet.options | filter:$viewValue | limitTo:20"' +
                                             ' typeahead-open-on-focus ng-required="programStageDataElements.'+deId+'.compulsory">';
                         }
                         if(programStageDataElements[deId].dataElement.type == "bool"){
-                            newInputField = '<select name="'+ deId +'" ' + 
-                                            style + ' ng-model="currentEvent.' + deId + '" ' +
+                            newInputField = '<select ' +
+                                            this.getAttributesAsString(attributes) +
+                                            ' ng-model="currentEvent.' + deId + '" ' +
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory">' + 
                                             'option value="">{{\'please_select\'| translate}}</option>' +
                                             '<option value="0">{{\'no\'| translate}}</option>' + 
                                             '<option value="1">{{\'yes\'| translate}}</option>';
                         }
                         if(programStageDataElements[deId].dataElement.type == "date"){
-                            newInputField = '<input type="text" name="'+ deId +'" ' + 
-                                            style + ' ng-model="currentEvent.' + deId + '"' +
+                            newInputField = '<input type="text" ' +
+                                            this.getAttributesAsString(attributes) +
+                                            ' ng-model="currentEvent.' + deId + '"' +
                                             ' ng-date' +
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory">';
                         }
                         if(programStageDataElements[deId].dataElement.type == "trueOnly"){
-                            newInputField = '<input type="checkbox" name="'+ deId +'" ' + 
-                                            style + 
+                            newInputField = '<input type="checkbox" ' +
+                                            this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '"' +
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory">';
                         }
@@ -264,7 +272,7 @@
                                         //'</ng-form>';                                    
 
                         htmlCode = htmlCode.replace(inputField, newInputField);
-                    }                
+                    }
                 }
                 
                 return htmlCode;
@@ -272,9 +280,20 @@
             }
             
             return null;
+        },
+        getAttributesAsString: function(attributes){
+            if(attributes){
+                var attributesAsString = '';                
+                for(var prop in attributes){
+                    if(prop != 'value'){
+                        attributesAsString += prop + '="' + attributes[prop] + '" ';
+                    }
+                }
+                return attributesAsString;
+            }
+            return null;
         }
-    };
-            
+    };            
 })
 
 /* Modal service for user interaction */