← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15515: custom form for event capture

 

------------------------------------------------------------
revno: 15515
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Mon 2014-06-02 12:50:49 +0200
message:
  custom form for event capture
modified:
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/i18n/en.json
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/directives.js
  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/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/i18n/en.json	2014-05-24 08:58:21 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/i18n/en.json	2014-06-02 10:50:49 +0000
@@ -29,6 +29,8 @@
     "done": "Done",
     "remove": "Remove",
     "are_you_sure_to_remove": "Are you sure you want to remove the selected item?",
+    "use_custom_form": "Custom form",
+    "use_default_form": "Default form",
     "show_hide_columns": "Show/hide columns",
     "show_all": "Show all",
     "hide": "Hide",

=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html	2014-05-24 08:58:21 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html	2014-06-02 10:50:49 +0000
@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<html manifest="event-capture.appcache" ng-app="eventCapture"> 
+<html manifest="event-capture.appcache" ng-app="eventCapture">
     <head>
         <title>Event Capture</title>
 
@@ -18,7 +18,7 @@
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular-resource.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular-route.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular-cookies.js"></script>
-        <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular-animate.js"></script>        
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/angular-animate.js"></script>  
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/ui-bootstrap-tpls-0.10.0-draggable-modal.js"></script>
 
         <script type="text/javascript" src="../dhis-web-commons/javascripts/moment/moment-with-langs.min.js"></script>       
@@ -198,9 +198,9 @@
                                 <select id="programId" 
                                         class="fixed-width-select"
                                         name="programId" 
-                                        ng-model="pr" 
+                                        ng-model="selectedProgram" 
                                         ng-options="program as program.name for program in programs | orderBy: 'name'" 
-                                        ng-change="loadEvents(pr)"
+                                        ng-change="loadEvents()"
                                         ng-disabled="eventRegistration || editingEventInFull || editingEventInGrid">
                                     <option value="">{{'please_select'| translate}}</option>
                                 </select>      
@@ -212,16 +212,22 @@
                                         ng-disabled="eventRegistration || editingEventInFull || editingEventInGrid">
                                     {{'register_event'| translate}}
                                 </button>  
-                            </td>                               
+                            </td>
+                            <td ng-if="(editingEventInFull || eventRegistration) && customForm" style='padding-left: 10px;'>
+                                <button class="button button-std"
+                                        ng-click="switchDataEntryForm()">
+                                    {{displayCustomForm ? 'use_default_form' : 'use_custom_form'| translate}}
+                                </button>  
+                            </td>                            
                         </tr>                       
                     </table>
                 </div>
                 <!-- selection ends -->
 
                 <!-- event grid begins -->
-                <div ng-show="selectedProgramStage && !eventRegistration && !editingEventInFull">                    
+                <div ng-if="selectedProgramStage && !eventRegistration && !editingEventInFull">                    
                     <img src="../images/ajax-loader-bar.gif" ng-if="!eventFetched"/>
-                    <div ng-switch="eventLength">                        
+                    <div ng-switch="dhis2Events.length">                        
                         <div ng-switch-when="undefined">
                             <h4>
                                 {{'empty_event_list'| translate}}
@@ -306,18 +312,16 @@
                                                 </span>
                                                 <!-- filter input field ends -->
                                                 
-                                            </th>
-                                            <th style="width: 20px;"></th>
+                                            </th>                                            
                                         </tr>                        
                                     </thead>
                                     <tbody id="list">
-                                        <tr ng-repeat="dhis2Event in dhis2Events | orderBy:sortHeader:reverse | gridFilter:filterText:filterTypes"                                        
-                                            ng-click="showContextMenu(dhis2Event)">
+                                        <tr ng-repeat="dhis2Event in dhis2Events | orderBy:sortHeader:reverse | gridFilter:filterText:filterTypes">
 
                                             <!-- Visible when event is not under editing -->
                                             <td dhis-context-menu 
                                                 selected-item={{dhis2Event}} 
-                                                
+                                                ng-click="showEventList()"
                                                 ng-hide="(currentEvent.event == dhis2Event.event) || !eventGridColumn.show" 
                                                 ng-repeat="eventGridColumn in eventGridColumns">                                                
                                                 {{dhis2Event[eventGridColumn.id]}}                                                
@@ -400,12 +404,7 @@
                                                         </div>
                                                     </div>
                                                 </ng-form>                                                
-                                            </td>
-                                            <td>                                
-                                                <span ng-show="currentEvent.event == dhis2Event.event">
-                                                    <a href ng-click="showEventList()" title="{{'done'| translate}}"><span class='black'><i class="fa fa-check-square fa-2x"></i></span></a>                                                    
-                                                </span>
-                                            </td>                           
+                                            </td>                                                                       
                                         </tr>
                                     </tbody>        
                                 </table>
@@ -417,13 +416,32 @@
                 </div> 
                 <!-- event grid ends -->
 
-                <!-- event update in full begins-->
-                <form name="outerFormUpdate" novalidate>
-                    <div ng-if="editingEventInFull">
+                <!-- event update in full / registration begins-->
+                <form name="outerForm" novalidate>
+                    <div ng-if="editingEventInFull || eventRegistration">
                         <h3>
-                            {{'update_event'| translate}}                                                 
-                        </h3>                                           
-                        <div class="bordered-div" style="width:50%;">
+                            <span ng-if="editingEventInFull">{{'update_event'| translate}}</span>                       
+                            <span ng-if="eventRegistration">{{'new_event'| translate}}</span>                            
+                        </h3>
+                        
+                        <!-- custom form begins -->
+                        <div class="bordered-div" ng-if="displayCustomForm">
+                            <label>{{selectedProgram.dateOfIncidentDescription}}</label>
+                            <input type="text"                                                   
+                                    placeholder="yyyy-mm-dd" 
+                                    ng-date 
+                                    ng-model="currentEvent.eventDate"
+                                    ng-disabled="editingEventInFull"    
+                                    ng-required="true" 
+                                    name="eventDate">
+                            <span ng-show="outerForm.submitted && outerForm.eventDate.$invalid" class="required">{{'required'| translate}}</span>
+                            <hr>
+                            <dhis-custom-form custom-form-type="PROGRAM_STAGE" custom-form-object="selectedProgramStage"></dhis-custom-form>
+                        </div>
+                        <!-- custom form ends -->
+                        
+                        <!-- default form begins -->
+                        <div class="bordered-div" style="width:50%;" ng-if="!displayCustomForm">
                             <table class="dhis2-list-table-striped">                    
                                 <thead>                        
                                     <tr>
@@ -436,12 +454,28 @@
                                     </tr>                        
                                 </thead>
                                 <tbody id="list">
+                                    <tr>
+                                        <td>
+                                             {{selectedProgram.dateOfIncidentDescription}}
+                                        </td>
+                                        <td>
+                                            <input type="text"                                                   
+                                                   placeholder="yyyy-mm-dd" 
+                                                   ng-date 
+                                                   ng-model="currentEvent.eventDate"
+                                                   ng-disabled="editingEventInFull"    
+                                                   ng-required="true" 
+                                                   name="eventDate" 
+                                                   style="width:99%;">
+                                            <span ng-show="outerForm.submitted && outerForm.eventDate.$invalid" class="required">{{'required'| translate}}</span>
+                                        </td>
+                                    </tr>
                                     <tr ng-repeat="eventGridColumn in eventGridColumns">
                                         <td >
                                             {{eventGridColumn.name}}                                              
                                         </td>
                                         <td >
-                                            <ng-form name="innerFormUpdate">
+                                            <ng-form name="innerForm">
                                                 <div ng-switch="eventGridColumn.type">
                                                     <div ng-switch-when="int">
                                                         <input type="number"
@@ -449,7 +483,7 @@
                                                                ng-required={{eventGridColumn.compulsory}}
                                                                name="foo" 
                                                                style="width:99%;"/>
-                                                        <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                                     </div>
                                                     <div ng-switch-when="string">                                        
                                                         <div class="container-fluid">
@@ -460,7 +494,7 @@
                                                                    ng-required={{eventGridColumn.compulsory}}
                                                                    name="foo" 
                                                                    style="width:99%;"/>
-                                                        <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                                         </div>
                                                     </div>
                                                     <div ng-switch-when="bool">
@@ -472,7 +506,7 @@
                                                             <option value="0">{{'no'| translate}}</option>
                                                             <option value="1">{{'yes'| translate}}</option>
                                                         </select>
-                                                        <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                                     </div>
                                                     <div ng-switch-when="date">
                                                         <input type="text"                                                                
@@ -482,134 +516,43 @@
                                                                ng-required={{eventGridColumn.compulsory}}
                                                                name="foo" 
                                                                style="width:99%;"/>
-                                                        <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                                     </div>
                                                     <div ng-switch-when="trueOnly">
                                                         <input type="checkbox"                                                                      
                                                                ng-model="currentEvent[eventGridColumn.id]"                                                               
                                                                ng-required={{eventGridColumn.compulsory}}
                                                                name="foo"/>
-                                                        <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                                     </div>
                                                 </div>
                                             </ng-form>
-                                    </td>
-                                </tr>
+                                        </td>
+                                    </tr>
                                 </tbody>        
-                            </table>    
-                            <button ng-click="updateEvent()" class="button">{{'update'| translate}}</button>
-                            <button ng-click="showEventList()" class="button">{{'go_back'| translate}}</button> 
-                        </div>
+                            </table>                            
+                        </div>
+                        <!-- default form ends -->
+                        
+                        <!-- buttons for event registration / update begins -->
+                        <div style="clear: both;">                        
+                            <span ng-if="editingEventInFull">
+                                <button ng-click="updateEvent()" class="button">{{'update'| translate}}</button>
+                                <button ng-click="showEventList()" class="button">{{'go_back'| translate}}</button>
+                            </span>
+                            <span ng-if="eventRegistration">
+                                <button ng-click="addEvent(true)" class="button">{{'save_and_add_new'| translate}}</button>
+                                <button ng-click="addEvent()" class="button">{{'save_and_back'| translate}}</button>
+                                <button ng-click="showEventList(null)" class="button">{{'go_back'| translate}}</button>
+                            </span> 
+                        </div>
+                        <!-- buttons for event registration / update ends -->
+                        
                     </div>
                 </form>    
-                <!-- event update ends -->
-
-                <!-- event registration begins -->
-                <form name="outerForm" novalidate>
-                    <div ng-if="eventRegistration">
-                        <h3>
-                            {{'new_event'| translate}}                                                 
-                        </h3>   
-                        <div class="bordered-div" style="width:50%;">                            
-                            <table class="dhis2-list-table-striped">                    
-                                <thead>                        
-                                    <tr>
-                                        <th>
-                                            {{'data_element'| translate}}                    
-                                        </th>
-                                        <th>
-                                            {{'value'| translate}}                    
-                                        </th>         
-                                    </tr>                        
-                                </thead>
-                                <tbody id="list">
-                                    <tr>
-                                        <td>
-                                             {{selectedProgram.dateOfIncidentDescription}}
-                                        </td>
-                                        <td>
-                                            <input type="text"                                                   
-                                                   placeholder="yyyy-mm-dd" 
-                                                   ng-date 
-                                                   ng-model="currentEvent.eventDate" 
-                                                   ng-required="true" 
-                                                   name="eventDate" 
-                                                   style="width:99%;">
-                                            <span ng-show="outerForm.submitted && outerForm.eventDate.$invalid" class="required">{{'required'| translate}}</span>
-                                        </td>
-                                    </tr> 
-                                    <tr ng-repeat="eventGridColumn in eventGridColumns">
-                                        <td >
-                                            {{eventGridColumn.name}}                                              
-                                        </td>
-                                        <td>
-                                            <ng-form name="innerFormAdd">
-                                                <div ng-switch="eventGridColumn.type">
-                                                    <div ng-switch-when="int">
-                                                        <input type="number"                                                                
-                                                               ng-model="currentEvent[eventGridColumn.id]" 
-                                                               ng-required={{eventGridColumn.compulsory}}
-                                                               name="foo" 
-                                                               style="width:99%;"/>
-                                                        <span ng-show="outerForm.submitted && innerFormAdd.foo.$invalid" class="required">{{'required'| translate}}</span>
-                                                    </div>
-                                                    <div ng-switch-when="string">                                        
-                                                        <div class="container-fluid">
-                                                            <input type="text"                                                                    
-                                                                   ng-model="currentEvent[eventGridColumn.id]" 
-                                                                   typeahead="option for option in programStageDataElements[eventGridColumn.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
-                                                                   typeahead-open-on-focus
-                                                                   ng-required={{eventGridColumn.compulsory}} 
-                                                                   name="foo" 
-                                                                   style="width:99%;">                                            
-                                                            <span ng-show="outerForm.submitted && innerFormAdd.foo.$invalid" class="required">{{'required'| translate}}</span>
-                                                        </div>
-                                                    </div>
-                                                    <div ng-switch-when="bool">
-                                                        <select ng-model="currentEvent[eventGridColumn.id]" 
-                                                                ng-required={{eventGridColumn.compulsory}}                                                                
-                                                                name="foo" 
-                                                                style="width:99%;">
-                                                            <option value="">{{'please_select'| translate}}</option>                        
-                                                            <option value="0">{{'no'| translate}}</option>
-                                                            <option value="1">{{'yes'| translate}}</option>
-                                                        </select>
-                                                        <span ng-show="outerForm.submitted && innerFormAdd.foo.$invalid" class="required">{{'required'| translate}}</span>
-                                                    </div>
-                                                    <div ng-switch-when="date">
-                                                        <input type="text" 
-                                                               placeholder="yyyy-mm-dd" 
-                                                               ng-date 
-                                                               ng-model="currentEvent[eventGridColumn.id]" 
-                                                               ng-required={{eventGridColumn.compulsory}}
-                                                               name="foo" 
-                                                               style="width:99%;">
-                                                        <span ng-show="outerForm.submitted && innerFormAdd.foo.$invalid" class="required">{{'required'| translate}}</span>
-                                                    </div>
-                                                    <div ng-switch-when="trueOnly">
-                                                        <input type="checkbox"       
-                                                               ng-model="currentEvent[eventGridColumn.id]"
-                                                               ng-required={{eventGridColumn.compulsory}}
-                                                               name="foo"/>
-                                                        <span ng-show="outerForm.submitted && innerFormAdd.foo.$invalid" class="required">{{'required'| translate}}</span>
-                                                    </div>
-                                                </div>
-                                            </ng-form>
-                                        </td>
-                                    </tr>
-                                </tbody>        
-                            </table>
-                            <button ng-click="addEvent(true)" class="button">{{'save_and_add_new'| translate}}</button>
-                            <button ng-click="addEvent()" class="button">{{'save_and_back'| translate}}</button>
-                            <button ng-click="showEventList(null)" class="button">{{'go_back'| translate}}</button>                        
-                        </div>
-                    </div> 
-                </form>
-                <!-- event registration ends -->              
+                <!-- event update / registration ends -->
                 
-            </div>           
-            
+            </div>            
         </div>
-
     </body>
 </html>

=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-05-22 12:58:32 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-06-02 10:50:49 +0000
@@ -11,7 +11,8 @@
                 Paginator,
                 TranslationService,
                 storage,
-                DHIS2EventFactory,                
+                DHIS2EventFactory,       
+                DHIS2EventService,
                 ContextMenuSelectedItem,
                 ModalService,
                 DialogService) {   
@@ -30,6 +31,8 @@
     $scope.updateSuccess = false;
     $scope.currentGridColumnId = '';  
     $scope.currentEventOrginialValue = '';   
+    $scope.displayCustomForm = false;
+    $scope.currentElement = {id: '', update: false};
     
     //watch for selection of org unit from tree
     $scope.$watch('selectedOrgUnit', function(newObj, oldObj) {
@@ -52,6 +55,15 @@
         $scope.selectedOrgUnit = orgUnit;
         $scope.selectedProgram = null;
         $scope.selectedProgramStage = null;
+
+        $scope.eventRegistration = false;
+        $scope.editGridColumns = false;
+        $scope.editingEventInFull = false;
+        $scope.editingEventInGrid = false;   
+        $scope.updateSuccess = false;
+        $scope.currentGridColumnId = '';  
+        $scope.currentEventOrginialValue = ''; 
+        $scope.displayCustomForm = false;
         
         if (angular.isObject($scope.selectedOrgUnit)) {   
 
@@ -72,8 +84,7 @@
                 if( !angular.isUndefined($scope.programs)){                    
                     if($scope.programs.length === 1){
                         $scope.selectedProgram = $scope.programs[0];
-                        $scope.pr = $scope.selectedProgram;
-                        $scope.loadEvents($scope.pr);
+                        $scope.loadEvents();
                     }                    
                 }
             }
@@ -81,7 +92,7 @@
     };    
     
     //get events for the selected program (and org unit)
-    $scope.loadEvents = function(program){   
+    $scope.loadEvents = function(){   
         
         $scope.selectedProgramStage = null;
         
@@ -94,10 +105,13 @@
 
         $scope.eventFetched = false;
                
-        if( program ){
+        if( $scope.selectedProgram && $scope.selectedProgram.programStages[0].id){
             
             //because this is single event, take the first program stage
-            $scope.selectedProgramStage = storage.get(program.programStages[0].id);
+            $scope.selectedProgramStage = storage.get($scope.selectedProgram.programStages[0].id);   
+            
+            //$scope.customForm = CustomFormService.processCustomForm($scope.selectedProgramStage);
+            $scope.customForm = $scope.selectedProgramStage.dataEntryForm ? $scope.selectedProgramStage.dataEntryForm.htmlCode : null; 
 
             $scope.programStageDataElements = [];  
             $scope.eventGridColumns = [];
@@ -193,25 +207,24 @@
                             i--;                           
                         }
                     }                                  
-                }
-                
+                }                
                 $scope.eventFetched = true;
             });            
         }        
     };
     
     $scope.jumpToPage = function(){
-        $scope.loadEvents($scope.selectedProgram, $scope.pager);
+        $scope.loadEvents();
     };
     
     $scope.resetPageSize = function(){
         $scope.pager.page = 1;        
-        $scope.loadEvents($scope.selectedProgram, $scope.pager);
+        $scope.loadEvents();
     };
     
     $scope.getPage = function(page){    
         $scope.pager.page = page;
-        $scope.loadEvents($scope.selectedProgram, $scope.pager);
+        $scope.loadEvents();
     };
     
     $scope.sortEventGrid = function(gridHeader){
@@ -281,13 +294,16 @@
         $scope.eventRegistration = false;
         $scope.editingEventInFull = false;
         $scope.editingEventInGrid = false;
+        $scope.currentElement.updated = false;
         
         $scope.outerForm.$valid = true;
         
         $scope.currentEvent = {};
     };
     
-    $scope.showEventRegistration = function(){
+    $scope.showEventRegistration = function(){        
+        $scope.displayCustomForm = $scope.customForm ? true:false;        
+        
         $scope.eventRegistration = !$scope.eventRegistration;  
         $scope.currentEvent = $scope.newDhis2Event;        
         $scope.outerForm.submitted = false;
@@ -302,13 +318,18 @@
         $scope.outerForm.$valid = true;
     };
     
-    $scope.showEditEventInFull = function(){
-        
+    $scope.showEditEventInFull = function(){        
+        $scope.displayCustomForm = $scope.customForm ? true:false;                
+
         $scope.currentEvent = ContextMenuSelectedItem.getSelectedItem();  
         $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);
         $scope.editingEventInFull = !$scope.editingEventInFull;   
         $scope.eventRegistration = false;
         
+        $scope.currentEvent.eventDate = moment($scope.currentEvent.eventDate, 'YYYY-MM-DD')._d;       
+        $scope.currentEvent.eventDate = Date.parse($scope.currentEvent.eventDate);
+        $scope.currentEvent.eventDate = $filter('date')($scope.currentEvent.eventDate, 'yyyy-MM-dd');
+        
         angular.forEach($scope.selectedProgramStage.programStageDataElements, function(prStDe){
             if(!$scope.currentEvent.hasOwnProperty(prStDe.dataElement.id)){
                 $scope.currentEvent[prStDe.dataElement.id] = '';
@@ -317,7 +338,11 @@
         
     };
     
-    $scope.addEvent = function(addingAnotherEvent){                
+    $scope.switchDataEntryForm = function(){
+        $scope.displayCustomForm = !$scope.displayCustomForm;
+    };
+    
+    $scope.addEvent = function(addingAnotherEvent){        
         
         //check for form validity
         $scope.outerForm.submitted = true;        
@@ -374,14 +399,14 @@
                 $scope.currentEvent = {};
                 $scope.outerForm.submitted = false;
             }
-        }); 
+        });
     }; 
     
     $scope.updateEvent = function(){
         
         //check for form validity
-        $scope.outerFormUpdate.submitted = true;        
-        if( $scope.outerFormUpdate.$invalid ){
+        $scope.outerForm.submitted = true;        
+        if( $scope.outerForm.$invalid ){
             return false;
         }
         
@@ -417,7 +442,7 @@
             }
                 
             $scope.currentEventOrginialValue = angular.copy($scope.currentEvent); 
-            $scope.outerFormUpdate.submitted = false;            
+            $scope.outerForm.submitted = false;            
             $scope.editingEventInFull = false;
             $scope.currentEvent = {};
         });       
@@ -451,7 +476,7 @@
         if( newValue != oldValue ){                     
             
             var updatedSingleValueEvent = {event: currentEvent.event, dataValues: [{value: newValue, dataElement: dataElement}]};
-            var updatedFullValueEvent = reconstructEvent(currentEvent, $scope.selectedProgramStage.programStageDataElements);
+            var updatedFullValueEvent = DHIS2EventService.reconstructEvent(currentEvent, $scope.selectedProgramStage.programStageDataElements);
             DHIS2EventFactory.updateForSingleValue(updatedSingleValueEvent, updatedFullValueEvent).then(function(data){
                 
                 var continueLoop = true;
@@ -502,33 +527,6 @@
     
     $scope.getHelpContent = function(){
     };
-    
-    //for simplicity of grid display, events were changed from
-    //event.datavalues = [{dataElement: dataElement, value: value}] to
-    //event[dataElement] = value
-    //now they are changed back for the purpose of storage.    
-    function reconstructEvent(event, programStageDataElements)
-    {
-        var e = {};
-        
-        e.event         = event.event;
-        e.status        = event.status;
-        e.program       = event.program;
-        e.programStage  = event.programStage;
-        e.orgUnit       = event.orgUnit;
-        e.eventDate     = event.eventDate;
-        
-        var dvs = [];
-        angular.forEach(programStageDataElements, function(prStDe){
-            if(event.hasOwnProperty(prStDe.dataElement.id)){
-                dvs.push({dataElement: prStDe.dataElement.id, value: event[prStDe.dataElement.id]});
-            }
-        });
-        
-        e.dataValues = dvs;
-        
-        return e;        
-    }
 })
 
 //Controller for the header section

=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2014-04-02 09:11:11 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2014-06-02 10:50:49 +0000
@@ -35,6 +35,23 @@
     };
 })
 
+.directive('dhisCustomForm', function($compile, $parse, CustomFormService) {
+    return{ 
+        restrict: 'E',
+        link: function(scope, elm, attrs){   
+            
+            var customFormType = attrs.customFormType;
+            var customFormObject = $parse(attrs.customFormObject)(scope);
+            
+            if(customFormType === 'PROGRAM_STAGE'){                
+                var customForm = CustomFormService.getForProgramStage(customFormObject);                
+                elm.html(customForm ? customForm : '');
+                $compile(elm.contents())(scope);                
+            }
+        }
+    };
+})
+
 .directive('dhisContextMenu', function(ContextMenuSelectedItem) {
         
     return {        

=== 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-05-29 13:50:01 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2014-06-02 10:50:49 +0000
@@ -263,7 +263,7 @@
 {
     return function() {
         return $.ajax( {
-            url: '../api/programStages.json?filter=id:eq:' + id +'&include=id,name,description,minDaysFromStart,repeatable,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id,name,options]]]',
+            url: '../api/programStages.json?filter=id:eq:' + id +'&include=id,name,description,minDaysFromStart,repeatable,dataEntryForm,programStageDataElements[displayInReports,allowProvidedElsewhere,allowDateInFuture,compulsory,dataElement[id,name,type,optionSet[id,name,options]]]',
             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-05-22 12:58:32 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-06-02 10:50:49 +0000
@@ -4,69 +4,6 @@
 
 var eventCaptureServices = angular.module('eventCaptureServices', ['ngResource'])
 
-/* Factory to fetch programs */
-.factory('ProgramFactory', function($http) {
-    
-    var programUid, programPromise;
-    var programs, programsPromise;
-    var program;
-    return {
-        
-        get: function(uid){
-            if( programUid !== uid ){
-                programPromise = $http.get('../api/programs/' + uid + '.json?viewClass=detailed&paging=false').then(function(response){
-                    programUid = response.data.id; 
-                    program = response.data;                     
-                    return program;
-                });
-            }
-            return programPromise;
-        },       
-        
-        getMine: function(type){ 
-            if( !programsPromise ){
-                programsPromise = $http.get('../api/me/programs?includeDescendants=true&type='+type).then(function(response){
-                   programs = response.data;
-                   return programs;
-                });
-            }
-            return programsPromise;    
-        },
-        
-        getEventProgramsByOrgUnit: function(orgUnit, type){
-                       
-            var promise = $http.get( '../api/programs.json?orgUnit=' + orgUnit + '&type=' + type ).then(function(response){
-                programs = response.data;
-                return programs;
-            });            
-            return promise;
-        }
-    };
-})
-
-/* Factory to fetch programStages */
-.factory('ProgramStageFactory', function($http, storage) {  
-    
-    var programStage, promise;   
-    return {        
-        get: function(uid){
-            if( programStage !== uid ){
-                promise = $http.get( '../api/programStages/' + uid + '.json?viewClass=detailed&paging=false').then(function(response){
-                   programStage = response.data.id;
-
-                   //store locally - might need them for event data values
-                   angular.forEach(response.data.programStageDataElements, function(prStDe){      
-                       storage.set(prStDe.dataElement.id, prStDe);                       
-                   });
-                   
-                   return response.data;
-                });
-            }
-            return promise;
-        }
-    };    
-})
-
 /* factory for loading logged in user profiles from DHIS2 */
 .factory('CurrentUserProfile', function($http) { 
            
@@ -91,9 +28,9 @@
         getByStage: function(orgUnit, programStage, pager){
         	var pgSize = pager ? pager.pageSize : 50;
         	var pg = pager ? pager.page : 1;
-            var url = '../api/events.json?' + 'orgUnit=' + orgUnit + '&programStage=' + programStage + '&pageSize=' + pgSize + '&page=' + pg;            
-            
-            var promise = $http.get( url ).then(function(response){                        
+                var url = '../api/events.json?' + 'orgUnit=' + orgUnit + '&programStage=' + programStage + '&pageSize=' + pgSize + '&page=' + pg;            
+
+                var promise = $http.get( url ).then(function(response){                        
                 return response.data;        
             }, function(){     
                 return dhis2.ec.storageManager.getEvents(orgUnit, programStage);                
@@ -155,6 +92,120 @@
     };    
 })
 
+/* service for dealing with events */
+.service('DHIS2EventService', function(){
+    return {     
+        //for simplicity of grid display, events were changed from
+        //event.datavalues = [{dataElement: dataElement, value: value}] to
+        //event[dataElement] = value
+        //now they are changed back for the purpose of storage.   
+        reconstructEvent: function(event, programStageDataElements){
+            var e = {};
+        
+            e.event         = event.event;
+            e.status        = event.status;
+            e.program       = event.program;
+            e.programStage  = event.programStage;
+            e.orgUnit       = event.orgUnit;
+            e.eventDate     = event.eventDate;
+
+            var dvs = [];
+            angular.forEach(programStageDataElements, function(prStDe){
+                if(event.hasOwnProperty(prStDe.dataElement.id)){
+                    dvs.push({dataElement: prStDe.dataElement.id, value: event[prStDe.dataElement.id]});
+                }
+            });
+
+            e.dataValues = dvs;
+
+            return e;  
+        }        
+    };
+})
+
+/* service for dealing with custom form */
+.service('CustomFormService', function(){
+    
+    return {
+        getForProgramStage: function(programStage){
+            
+            var htmlCode = programStage.dataEntryForm ? programStage.dataEntryForm.htmlCode : null;  
+            
+            if(htmlCode){                
+            
+                var programStageDataElements = [];
+
+                angular.forEach(programStage.programStageDataElements, function(prStDe){
+                    programStageDataElements[prStDe.dataElement.id] = prStDe;
+                });
+
+                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];                          
+                        }
+
+                        if(programStageDataElements[deId].dataElement.type == "int"){
+                            newInputField = '<input type="number" name="'+ deId +'"' + style + 'ng-model="currentEvent.' + deId + '"' +
+                                            'ng-required="programStageDataElements.' + deId + '.compulsory">';
+                        }
+                        if(programStageDataElements[deId].dataElement.type == "string"){
+                            newInputField = '<input type="text" name="'+ deId +'"' + style + '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" name="foo" style="width:99%;">';
+                        }
+                        if(programStageDataElements[deId].dataElement.type == "bool"){
+                            newInputField = '<select name="'+ deId +'"' + style + '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 + '"' +
+                                            'ng-date' +
+                                            'ng-required="programStageDataElements.' + deId + '.compulsory">';
+                        }
+                        if(programStageDataElements[deId].dataElement.type == "trueOnly"){
+                            newInputField = '<input type="checkbox" name="'+ deId +'"' + style + 'ng-model="currentEvent.' + deId + '"' +
+                                            'ng-required="programStageDataElements.' + deId + '.compulsory">';
+                        }
+
+                        newInputField = //'<ng-form name="innerForm">' + 
+                                        newInputField + 
+                                        '<span ng-show="outerForm.submitted && outerForm.'+ deId +'.$invalid" class="required">{{\'required\'| translate}}</span>';                                     
+                                        //'</ng-form>';                                    
+
+                        htmlCode = htmlCode.replace(inputField, newInputField);
+                    }                
+                }
+                
+                return htmlCode;
+                
+            }
+            
+            return null;
+        }
+    };
+            
+})
+
 /* Modal service for user interaction */
 .service('ModalService', ['$modal', function($modal) {