← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20136: tracker-capture: relationship now uses main registration controller

 

------------------------------------------------------------
revno: 20136
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-09-14 17:40:35 +0200
message:
  tracker-capture: relationship now uses main registration controller
removed:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.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
=== removed file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html	2015-09-11 15:16:03 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html	1970-01-01 00:00:00 +0000
@@ -1,151 +0,0 @@
-<div ng-controller="RelativeRegistrationController">
-    
-    <form name="outerForm" novalidate>
-
-        <div ng-if='!selectedProgramForRelative'>
-            <h3>{{'category' | translate}}</h3>
-             <table class="table-borderless table-striped">
-                <tr>
-                    <td>
-                        {{'entity_type' | translate}}
-                    </td>
-                    <td>
-                        <select class="form-control" ng-model="trackedEntities.selected" ng-options="trackedEntity.name for trackedEntity in trackedEntities.available | orderBy: 'name'">                                
-                        </select>                            
-                    </td>
-                </tr>                   
-            </table>
-            <hr>
-        </div>
-
-        <h3>{{'profile' | translate}}</h3>
-        <table class="table-borderless table-striped">
-            <tr ng-repeat="attribute in attributes">
-                <td>
-                    {{attribute.name}}
-                </td>
-                <td>
-                    <ng-form name="innerForm">
-                        <div ng-if="attribute.optionSetValue">
-                            <div ng-if="!selectedProgramForRelative">
-                                <input type="text"
-                                   name="foo"
-                                   class="form-control"
-                                   ng-model="attribute.value"                                                 
-                                   typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options| filter:$viewValue | limitTo:20" 
-                                   typeahead-open-on-focus
-                                   ng-required="attribute.mandatory"/>
-                            </div>
-                            <div ng-if="selectedProgramForRelative">
-                                <div ng-if="!selectedProgramForRelative.dataEntryMethod || optionSets[attribute.optionSet.id].options.length >= 7">
-                                    <input type="text" 
-                                       name="foo"
-                                       class="form-control"
-                                       ng-model="attribute.value"                                                 
-                                       typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options| filter:$viewValue | limitTo:20" 
-                                       typeahead-open-on-focus
-                                       typeahead-editable=false
-                                       ng-required="attribute.mandatory"/>
-                                </div>
-                                <div ng-if="selectedProgramForRelative.dataEntryMethod && optionSets.optionSet[attribute.optionSet.id].options.length < 7">
-                                    <label>                                        
-                                        <input type="radio"
-                                            name={{attribute.id}}
-                                            ng-required="attribute.mandatory"
-                                            ng-model="attribute.value"
-                                            value=""> {{'no_value' | translate}}<br>                                       
-                                    </label><br>
-                                    <span ng-repeat="option in optionSets[attribute.optionSet.id].options">
-                                        <label>
-                                            <input type="radio"
-                                                name={{attribute.id}}
-                                                ng-required="attribute.mandatory"
-                                                ng-model="attribute.value" 
-                                                value={{option.name}}> {{option.name}}
-                                        </label><br>
-                                    </span>                                            
-                                </div>
-                            </div>                                
-                            <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                        </div>
-                        <div ng-if="!attribute.optionSetValue" ng-switch="attribute.valueType">
-                            <div ng-switch-when="date">
-                                <input type="text" placeholder="{{dhis2CalendarFormat.keyDateFormat}}" name="foo" class="form-control" d2-date ng-model="attribute.value" ng-required="attribute.mandatory" />
-                                <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                            </div>
-                            <div ng-switch-when="trueOnly">
-                                <input type="checkbox" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory" />
-                                <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                            </div>
-                            <div ng-switch-when="bool">
-                                <select name="foo" ng-model="attribute.value" class="form-control" ng-required="attribute.mandatory">
-                                    <option value="">{{'please_select'| translate}}</option>                        
-                                    <option value="false">{{'no'| translate}}</option>
-                                    <option value="true">{{'yes'| translate}}</option>
-                                </select>
-                                <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                            </div>
-                            <div ng-switch-when="number">
-                                <input type="number" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory"/>
-                                <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                            </div>
-                            <div ng-switch-when="email">
-                                <input type="email" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory"/>
-                                <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                            </div>
-                            <div ng-switch-default>
-                                <input type="text" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory"/>
-                                <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span>
-                            </div>
-                        </div>
-                    </ng-form>
-                </td>
-            </tr>                        
-        </table>
-
-        <div ng-if='selectedProgramForRelative'>
-            <hr>
-            <h3>{{'enrollment' | translate}}</h3>
-            <table class="dhis2-list-table-striped dhis2-table-hover">
-                <tr>
-                    <td>
-                        {{selectedProgramForRelative.enrollmentDateLabel}}
-                    </td>
-                    <td>
-                        <input type="text" 
-                               name="enrollmentDate" 
-                               class="form-control" 
-                               d2-date 
-                               max-date="selectedProgramForRelative.selectEnrollmentDatesInFuture ? '' : 0"
-                               min-date=""
-                               ng-model="enrollment.enrollmentDate" 
-                               ng-required="true"/>
-                        <span ng-show="outerForm.submitted && outerForm.enrollmentDate.$invalid" class="error">{{'required'| translate}}</span>
-                    </td>
-                </tr>     
-                <tr ng-if="selectedProgramForRelative.displayIncidentDate">
-                    <td>
-                        {{selectedProgramForRelative.incidentDateLabel}}
-                    </td>
-                    <td>
-                        <input type="text" 
-                               class="form-control" 
-                               d2-date 
-                               max-date="selectedProgramForRelative.selectIncidentDatesInFuture ? '' : 0"
-                               min-date=""
-                               ng-model="enrollment.incidentDate" />
-                    </td>
-                </tr>
-            </table>
-        </div>
-
-        <div ng-if="!valueExists  && outerForm.submitted">
-            <div class="alert alert-warning">{{'form_is_empty_fill_at_least_one'| translate}}</div> 
-        </div>
-
-        <div class="vertical-spacing">                
-            <button type="button" class="btn btn-primary" ng-click="registerEntity()">{{'register'| translate}}</button>
-            <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="showRegistration()">{{'cancel'| translate}}</button>
-        </div>
-    </form>
-</div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2015-09-14 15:16:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2015-09-14 15:40:35 +0000
@@ -552,177 +552,4 @@
             });
         }        
     };
-})
-
-.controller('RelativeRegistrationController', 
-        function($rootScope,
-                $scope,
-                $timeout,
-                AttributesFactory,
-                TEService,
-                TEIService,
-                EnrollmentService,
-                DialogService,
-                CurrentSelection,
-                OptionSetService,
-                DateUtils,
-                SessionStorageService) {
-    $scope.selectedOrgUnit = SessionStorageService.get('SELECTED_OU');
-    $scope.enrollment = {enrollmentDate: '', incidentDate: ''};    
-    $scope.attributesById = CurrentSelection.getAttributesById();
-    
-    var selections = CurrentSelection.get();    
-    $scope.optionSets = selections.optionSets;
-    $scope.programs = selections.prs;
-    
-    var mainTei = angular.copy(selections.tei);    
-    angular.forEach(mainTei.attributes, function(att){
-        mainTei[att.attribute] = att.value;
-    });
-    var getProgramAttributes = function(program){
-        AttributesFactory.getByProgram(program).then(function(atts){
-            $scope.attributes = atts;            
-            angular.forEach($scope.attributes, function(att){
-                if(att.inherit && mainTei[att.id]){
-                    att.value = mainTei[att.id];
-                }
-            });
-        });
-    };
-  
-    if(angular.isObject($scope.programs) && $scope.programs.length === 1){
-        $scope.selectedProgramForRelative = $scope.programs[0];
-        getProgramAttributes($scope.selectedProgramForRelative);
-    }  
-    
-    //watch for selection of program
-    $scope.$watch('selectedProgramForRelative', function() {
-        getProgramAttributes($scope.selectedProgramForRelative);
-    }); 
-            
-    $scope.trackedEntities = {available: []};
-    TEService.getAll().then(function(entities){
-        $scope.trackedEntities.available = entities;   
-        $scope.trackedEntities.selected = $scope.trackedEntities.available[0];
-    });
-    
-    $scope.registerEntity = function(){
-        
-        //check for form validity
-        $scope.outerForm.submitted = true;        
-        if( $scope.outerForm.$invalid ){
-            return false;
-        }
-        
-        //form is valid, continue the registration
-        //get selected entity
-        var selectedTrackedEntity = $scope.trackedEntities.selected.id; 
-        if($scope.selectedProgramForRelative){
-            selectedTrackedEntity = $scope.selectedProgramForRelative.trackedEntity.id;
-        }
-        
-        //get tei attributes and their values
-        //but there could be a case where attributes are non-mandatory and
-        //registration form comes empty, in this case enforce at least one value
-        $scope.valueExists = false;
-        var registrationAttributes = [];    
-        angular.forEach($scope.attributes, function(attribute){
-            var val = attribute.value;
-            if(!angular.isUndefined(val)){                
-                if(attribute.valueType === 'date'){
-                    val = DateUtils.formatFromUserToApi(val);
-                }
-                if(attribute.optionSetValue &&
-                        attribute.optionSet &&
-                        attribute.optionSet.id &&                
-                        $scope.optionSets[attribute.optionSet.id] &&
-                        $scope.optionSets[attribute.optionSet.id].options ){  
-                    
-                    val = OptionSetService.getCode($scope.optionSets[attribute.optionSet.id].options, val);
-                }
-                registrationAttributes.push({attribute: attribute.id, value: val});
-                $scope.valueExists = true;
-            } 
-        });       
-        
-        if(!$scope.valueExists){
-            //registration form is empty
-            return false;
-        }
-        
-        //prepare tei model and do registration
-        $scope.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: registrationAttributes };   
-        var teiId = '';
-
-        TEIService.register($scope.tei, $scope.optionSets, $scope.attributesById).then(function(registrationResponse){            
-            var reg = registrationResponse.response && registrationResponse.response.importSummaries && registrationResponse.response.importSummaries[0] ? registrationResponse.response.importSummaries[0] : {};
-            if(reg.reference && reg.status === 'SUCCESS'){                
-                teiId = reg.reference;                
-                //registration is successful and check for enrollment
-                if($scope.selectedProgramForRelative){    
-                    //enroll TEI
-                    var enrollment = {trackedEntityInstance: teiId,
-                                program: $scope.selectedProgramForRelative.id,
-                                status: 'ACTIVE',
-                                enrollmentDate: DateUtils.formatFromUserToApi($scope.enrollment.enrollmentDate),
-                                incidentDate: $scope.enrollment.incidentDate === '' ? DateUtils.formatFromUserToApi($scope.enrollment.enrollmentDate) : DateUtils.formatFromUserToApi($scope.enrollment.incidentDate)
-                            };
-                    EnrollmentService.enroll(enrollment).then(function(enrollmentResponse){
-                        var en = enrollmentResponse.response && enrollmentResponse.response.importSummaries && enrollmentResponse.response.importSummaries[0] ? enrollmentResponse.response.importSummaries[0] : {};
-                        if(en.reference && en.status === 'SUCCESS'){
-                            //enrollment has failed
-                            var dialogOptions = {
-                                    headerText: 'enrollment_error',
-                                    bodyText: enrollmentResponse.message
-                                };
-                            DialogService.showDialog({}, dialogOptions);
-                            return;
-                        }
-                    });
-                }
-            }
-            else{
-                //registration has failed
-                var dialogOptions = {
-                        headerText: 'registration_error',
-                        bodyText: registrationResponse.message
-                    };
-                DialogService.showDialog({}, dialogOptions);
-                return;
-            }
-            
-            $timeout(function() { 
-                //reset form
-                angular.forEach($scope.attributes, function(attribute){
-                    delete attribute.value;                
-                });            
-
-                $scope.enrollment.enrollmentDate = '';
-                $scope.enrollment.incidentDate =  '';
-                $scope.outerForm.submitted = false; 
-                
-                $scope.tei.id = teiId;
-                $scope.broadCastSelections();
-                
-            }, 200);        
-            
-        });
-    };
-    
-    $scope.broadCastSelections = function(){
-        if($scope.tei){
-            angular.forEach($scope.tei.attributes, function(att){
-                $scope.tei[att.attribute] = att.value;
-            });
-
-            $scope.tei.orgUnitName = $scope.selectedOrgUnit.name;
-            $scope.tei.created = DateUtils.formatFromApiToUser(new Date());
-            
-            CurrentSelection.setRelationshipInfo({tei: $scope.tei});
-            
-            $timeout(function() { 
-                $rootScope.$broadcast('relationship', {});
-            }, 200);
-        }        
-    };
 });
\ No newline at end of file