------------------------------------------------------------ revno: 15966 committer: Abyot Asalefew Gizaw aby...@gmail.com branch nick: dhis2 timestamp: Fri 2014-07-04 16:36:11 +0200 message: tracker capture - relationship widget, WIP modified: dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/tei.html dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css
-- 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-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2014-07-04 14:36:11 +0000 @@ -1,18 +1,21 @@ trackerCapture.controller('RegistrationController', - function($scope, + function($rootScope, + $scope, $location, + $timeout, AttributesFactory, TEService, TEIService, EnrollmentService, DialogService, + CurrentSelection, + DateUtils, storage, TranslationService) { //do translation of the registration page TranslationService.translate(); - - $scope.valueExists = false; + $scope.selectedOrgUnit = storage.get('SELECTED_OU'); $scope.enrollment = {enrollmentDate: '', incidentDate: ''}; @@ -36,7 +39,7 @@ } }); - $scope.registerEntity = function(showDashboard){ + $scope.registerEntity = function(destination){ //check for form validity $scope.outerForm.submitted = true; @@ -89,7 +92,7 @@ dateOfIncident: $scope.enrollment.incidentDate }; EnrollmentService.enroll(enrollment).then(function(data){ - if(data.status != 'SUCCESS'){ + if(data.status !== 'SUCCESS'){ //enrollment has failed var dialogOptions = { headerText: 'enrollment_error', @@ -111,18 +114,44 @@ return; } - //reset form - angular.forEach($scope.attributes, function(attribute){ - attribute.value = ''; - }); - $scope.enrollment.enrollmentDate = ''; - $scope.enrollment.incidentDate = ''; - $scope.outerForm.submitted = false; + $timeout(function() { + //reset form + angular.forEach($scope.attributes, function(attribute){ + delete attribute.value; + }); + + $scope.enrollment.enrollmentDate = ''; + $scope.enrollment.incidentDate = ''; + $scope.outerForm.submitted = false; + + + if(destination === 'DASHBOARD') { + $location.path('/dashboard').search({tei: teiId, + program: $scope.selectedProgram ? $scope.selectedProgram.id: null}); + } + else if(destination === 'RELATIONSHIP' ){ + $scope.tei.trackedEntityInstance = teiId; + $scope.broadCastSelections(); + } + }, 100); - if(showDashboard){ - $location.path('/dashboard').search({tei: teiId, - program: $scope.selectedProgram ? $scope.selectedProgram.id: null}); - } - }); + }); + }; + + $scope.resetRelationshipSource = function(){ + $scope.selectedRelationshipSource = ''; + }; + + $scope.broadCastSelections = function(){ + angular.forEach($scope.tei.attributes, function(att){ + $scope.tei[att.attribute] = att.value; + }); + + $scope.tei.orgUnitName = $scope.selectedOrgUnit.name; + $scope.tei.created = DateUtils.format(new Date()); + CurrentSelection.setRelationshipInfo({tei: $scope.tei, src: $scope.selectedRelationshipSource}); + $timeout(function() { + $rootScope.$broadcast('relationship', {}); + }, 100); }; }); \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html 2014-07-04 14:36:11 +0000 @@ -92,14 +92,13 @@ </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(true)">{{'save_and_continue'| translate}}</button> - <button type="button" class="btn btn-success small-horizonal-spacing" ng-click="registerEntity(false)">{{'save_and_add_new'| translate}}</button> + <button type="button" class="btn btn-primary" ng-click="registerEntity('DASHBOARD')">{{'save_and_continue'| translate}}</button> + <button type="button" class="btn btn-success small-horizonal-spacing" ng-click="registerEntity('SELF')">{{'save_and_add_new'| translate}}</button> <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="showRegistration()">{{'cancel'| translate}}</button> </div> </form> === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html 2014-07-04 14:36:11 +0000 @@ -16,7 +16,7 @@ <hr> <div class="row col-md-12"> <div class="col-md-5"> - <div class='align-center bold'>A ({{selectedRelationshipType.aIsToB}})</div> + <div class='align-center bold'>{{selectedRelationshipType.aIsToB}}</div> <div class='relationship-container'> <table class="table table-striped table-compact table-borderless"> <tr ng-repeat="attribute in selectedTei.attributes"> @@ -31,7 +31,7 @@ </div> </div> <div class="col-md-7"> - <div class='align-center bold'>B ({{selectedRelationshipType.bIsToA}})</div> + <div class='align-center bold'>{{selectedRelationshipType.bIsToA}}</div> <div class='relationship-container' ng-show="teiForRelationship"> <table class="table table-striped table-compact table-borderless"> <tr ng-repeat="gridColumn in gridColumns"> @@ -45,21 +45,19 @@ </table> </div> <div class='relationship-container' ng-show="!teiForRelationship"> - <select ng-model="selectedRelationshipSource" + <select ng-model="selectedRelationshipSource.value" class="form-control" ng-options="relationshipSource | translate for relationshipSource in relationshipSources"> <option value="">{{'please_select_source'| translate}}</option> </select> - <div class="input-group vertical-spacing" ng-if="selectedRelationshipSource === 'search_from_existing'"> + <div class="input-group vertical-spacing" ng-if="selectedRelationshipSource.value === 'search_from_existing'"> <input type="text" placeholder="{{'type_here_for_simple_search'| translate}}" ng-model="searchText.value" class="form-control expanded" ng-class="{true: 'invalid - input'} [!searchText && emptySearchText]" ng-focus="showHideSearch(true)"> <div class="input-group-btn"> <button class="btn btn-default without-border-radius trim" type="button" title="{{'advanced_search'| translate}}" ng-click="showHideSearch(false)"><i class="fa fa-caret-down"></i></button> <button class="btn btn-primary trim" type="button" title="{{'search'| translate}}" ng-click="search(searchMode.freeText)"><i class="fa fa-search"></i></button> </div> </div> - <div ng-if="showSearchDiv && selectedRelationshipSource === 'search_from_existing'"> - <!--<form ng-include="'components/relationship/search.html'"> - </form> --> + <div ng-if="showSearchDiv && selectedRelationshipSource.value === 'search_from_existing'"> <div ng-include="'components/relationship/search.html'"></div> <span> </span> </div> @@ -77,9 +75,11 @@ </div> </div> <!--- Error display for search ends --> - - <div ng-if="selectedRelationshipSource === 'register_new'"> + + <pre>source - {{selectedRelationshipSource.value}}</pre> + <div ng-show="selectedRelationshipSource.value === 'register_new'"> <div ng-include="'components/relationship/registration.html'"></div> + <span> </span> </div> </div> </div> === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html 2014-07-04 14:36:11 +0000 @@ -1,102 +1,110 @@ -<div ng-controller="RegistrationController"> - - <form name="outerForm" novalidate> - - <div ng-if='!selectedProgram'> - <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-switch="attribute.valueType"> - <div ng-switch-when="date"> - <input type="text" name="foo" class="form-control" ng-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="0">{{'no'| translate}}</option> - <option value="1">{{'yes'| translate}}</option> - </select> - <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span> - </div> - <div ng-switch-when="optionSet"> - <input type="text" - name="foo" - class="form-control" - ng-model="attribute.value" - typeahead="option for option in attribute.optionSet.options | filter:$viewValue | limitTo:20" - typeahead-open-on-focus - ng-required="attribute.mandatory" - /> - <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-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='selectedProgram'> - <hr> - <h3>{{'enrollment' | translate}}</h3> - <table class="dhis2-list-table-striped dhis2-table-hover"> - <tr> - <td> - {{selectedProgram.dateOfEnrollmentDescription}} - </td> - <td> - <input type="text" name="dateOfEnrollment" class="form-control" ng-date ng-model="enrollment.incidentDate" ng-required="true"/> - <span ng-show="outerForm.submitted && outerForm.dateOfEnrollment.$invalid" class="error">{{'required'| translate}}</span> - </td> - </tr> - <tr ng-if="selectedProgram.displayIncidentDate"> - <td> - {{selectedProgram.dateOfIncidentDescription}} - </td> - <td> - <input type="text" class="form-control" ng-date ng-model="enrollment.enrollmentDate" /> - </td> - </tr> - </table> - </div> - - <div class="vertical-spacing"> - <button type="button" class="btn btn-primary" ng-click="registerEntity(true)">{{'save_and_continue'| translate}}</button> - <button type="button" class="btn btn-success small-horizonal-spacing" ng-click="registerEntity(false)">{{'save_and_add_new'| translate}}</button> - <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="closeRegistration()">{{'cancel'| translate}}</button> - </div> - </form> - +<div ng-controller="RelativeRegistrationController"> + <hr> + <form name="outerForm" novalidate> + + <select ng-model="selectedProgramForRelative" + class="form-control" + ng-options="program as program.name for program in programs | orderBy: 'name'"> + <option value="">{{'please_select_a_program'| translate}}</option> + </select> + + <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-switch="attribute.valueType"> + <div ng-switch-when="date"> + <input type="text" name="foo" class="form-control" ng-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="0">{{'no'| translate}}</option> + <option value="1">{{'yes'| translate}}</option> + </select> + <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}}</span> + </div> + <div ng-switch-when="optionSet"> + <input type="text" + name="foo" + class="form-control" + ng-model="attribute.value" + typeahead="option for option in attribute.optionSet.options | filter:$viewValue | limitTo:20" + typeahead-open-on-focus + ng-required="attribute.mandatory" + /> + <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-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.dateOfEnrollmentDescription}} + </td> + <td> + <input type="text" name="dateOfEnrollment" class="form-control" ng-date ng-model="enrollment.incidentDate" ng-required="true"/> + <span ng-show="outerForm.submitted && outerForm.dateOfEnrollment.$invalid" class="error">{{'required'| translate}}</span> + </td> + </tr> + <tr ng-if="selectedProgramForRelative.displayIncidentDate"> + <td> + {{selectedProgramForRelative.dateOfIncidentDescription}} + </td> + <td> + <input type="text" class="form-control" ng-date ng-model="enrollment.enrollmentDate" /> + </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="resetRelationshipSource()">{{'cancel'| translate}}</button> + </div> + </form> </div> \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2014-07-04 14:36:11 +0000 @@ -11,21 +11,17 @@ RelationshipFactory.getAll().then(function(rels){ $scope.relationshipTypes = rels; - }); - + }); //listen for the selected entity $scope.$on('dashboard', function(event, args) { $scope.selections = CurrentSelection.get(); $scope.selectedTei = angular.copy($scope.selections.tei); $scope.trackedEntity = $scope.selections.te; - $scope.selectedProgram = $scope.selections.pr; - $scope.selectedEnrollment = $scope.selections.enrollment; - + $scope.selectedEnrollment = $scope.selections.enrollment; }); - $scope.showAddRelationship = function() { - + $scope.showAddRelationship = function() { var modalInstance = $modal.open({ templateUrl: 'components/relationship/add-relationship.html', controller: 'AddRelationshipController', @@ -45,16 +41,17 @@ modalInstance.result.then(function (relationships) { $scope.selectedTei.relationships = relationships; }); - }; - + }; }) //Controller for adding new relationship .controller('AddRelationshipController', function($scope, + CurrentSelection, OperatorFactory, AttributesFactory, EntityQueryFactory, + ProgramFactory, TEIService, TEIGridService, Paginator, @@ -67,12 +64,55 @@ $scope.relationshipTypes = relationshipTypes; $scope.selectedTei = selectedTei; $scope.relationshipSources = ['search_from_existing','register_new']; + $scope.selectedRelationshipSource = {}; //Selection $scope.selectedOrgUnit = storage.get('SELECTED_OU'); - $scope.selectedProgram = selections.pr; $scope.selectedTei = selections.tei; + ProgramFactory.getAll().then(function(programs){ + $scope.programs = []; + angular.forEach(programs, function(program){ + if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id)){ + $scope.programs.push(program); + } + }); + + if(angular.isObject($scope.programs) && $scope.programs.length === 1){ + $scope.selectedProgramForRelative = $scope.programs[0]; + AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){ + $scope.attributes = atts; + $scope.attributes = $scope.generateAttributeFilters($scope.attributes); + $scope.gridColumns = $scope.generateGridColumns($scope.attributes); + }); + } + else{ + AttributesFactory.getWithoutProgram().then(function(atts){ + $scope.attributes = atts; + $scope.attributes = $scope.generateAttributeFilters($scope.attributes); + $scope.gridColumns = $scope.generateGridColumns($scope.attributes); + }); + } + }); + + //set attributes as per selected program + $scope.setAttributesForSearch = function(program){ + $scope.selectedProgramForRelative = program; + if( angular.isObject($scope.selectedProgramForRelative)){ + AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){ + $scope.attributes = atts; + $scope.attributes = $scope.generateAttributeFilters($scope.attributes); + $scope.gridColumns = $scope.generateGridColumns($scope.attributes); + }); + } + else{ + AttributesFactory.getWithoutProgram().then(function(atts){ + $scope.attributes = atts; + $scope.attributes = $scope.generateAttributeFilters($scope.attributes); + $scope.gridColumns = $scope.generateGridColumns($scope.attributes); + }); + } + }; $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, @@ -98,27 +138,14 @@ $scope.trackedEntityList = null; $scope.enrollment = {programStartDate: '', programEndDate: '', operator: $scope.defaultOperators[0]}; - $scope.searchMode = { - listAll: 'LIST_ALL', - freeText: 'FREE_TEXT', - attributeBased: 'ATTRIBUTE_BASED' - }; + $scope.searchMode = {listAll: 'LIST_ALL', freeText: 'FREE_TEXT', attributeBased: 'ATTRIBUTE_BASED'}; - if($scope.selectedProgram){ - AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){ - $scope.attributes = atts; - $scope.attributes = $scope.generateAttributeFilters($scope.attributes); - $scope.gridColumns = $scope.generateGridColumns($scope.attributes); - }); - } - else{ - AttributesFactory.getWithoutProgram().then(function(atts){ - $scope.attributes = atts; - $scope.attributes = $scope.generateAttributeFilters($scope.attributes); - $scope.gridColumns = $scope.generateGridColumns($scope.attributes); - }); - } - + //listen for selections + $scope.$on('relationship', function(event, args) { + var relationshipInfo = CurrentSelection.getRelationshipInfo(); + $scope.teiForRelationship = relationshipInfo.tei; + }); + $scope.search = function(mode){ $scope.teiForRelationship = null; @@ -135,12 +162,10 @@ $scope.programUrl = null; $scope.attributeUrl = {url: null, hasValue: false}; - $scope.selectedSearchMode = mode; - $scope.attributes = $scope.generateAttributeFilters($scope.attributes); - $scope.gridColumns = $scope.generateGridColumns($scope.attributes); + $scope.selectedSearchMode = mode; - if($scope.selectedProgram){ - $scope.programUrl = 'program=' + $scope.selectedProgram.id; + if($scope.selectedProgramForRelative){ + $scope.programUrl = 'program=' + $scope.selectedProgramForRelative.id; } //check search mode @@ -160,7 +185,7 @@ $scope.searchText.value = null; $scope.attributeUrl = EntityQueryFactory.getAttributesQuery($scope.attributes, $scope.enrollment); - if(!$scope.attributeUrl.hasValue && !$scope.selectedProgram){ + if(!$scope.attributeUrl.hasValue && !$scope.selectedProgramForRelative){ $scope.emptySearchAttribute = true; $scope.teiFetched = false; $scope.teiCount = null; @@ -266,17 +291,183 @@ $modalInstance.close(''); }; - $scope.closeRegistration = function(){ - console.log('registration close'); - $scope.selectedRelationshipSource = ''; - }; - $scope.assignRelationship = function(selectedTei){ - $scope.teiForRelationship = selectedTei; - console.log('selected is: ', $scope.teiForRelationship); + $scope.teiForRelationship = selectedTei; }; $scope.add = function(){ console.log('I will add new relationship'); - }; + }; +}) + +.controller('RelativeRegistrationController', + function($rootScope, + $scope, + $timeout, + AttributesFactory, + ProgramFactory, + TEService, + TEIService, + EnrollmentService, + DialogService, + CurrentSelection, + DateUtils, + storage, + TranslationService) { + + //do translation of the registration page + TranslationService.translate(); + + $scope.selectedOrgUnit = storage.get('SELECTED_OU'); + $scope.enrollment = {enrollmentDate: '', incidentDate: ''}; + + ProgramFactory.getAll().then(function(programs){ + $scope.programs = []; + angular.forEach(programs, function(program){ + if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id)){ + $scope.programs.push(program); + } + }); + + if(angular.isObject($scope.programs) && $scope.programs.length === 1){ + $scope.selectedProgramForRelative = $scope.programs[0]; + AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){ + $scope.attributes = atts; + }); + } + }); + + //watch for selection of program + $scope.$watch('selectedProgramForRelative', function() { + if( angular.isObject($scope.selectedProgramForRelative)){ + AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){ + $scope.attributes = atts; + }); + } + else{ + AttributesFactory.getWithoutProgram().then(function(atts){ + $scope.attributes = atts; + }); + } + }); + + $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){ + if(!angular.isUndefined(attribute.value)){ + var att = {attribute: attribute.id, value: attribute.value}; + registrationAttributes.push(att); + $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).then(function(tei){ + + if(tei.status === 'SUCCESS'){ + + teiId = tei.reference; + + //registration is successful and check for enrollment + if($scope.selectedProgramForRelative){ + //enroll TEI + var enrollment = {trackedEntityInstance: teiId, + program: $scope.selectedProgramForRelative.id, + status: 'ACTIVE', + dateOfEnrollment: $scope.enrollment.enrollmentDate, + dateOfIncident: $scope.enrollment.incidentDate + }; + EnrollmentService.enroll(enrollment).then(function(data){ + if(data.status !== 'SUCCESS'){ + //enrollment has failed + var dialogOptions = { + headerText: 'enrollment_error', + bodyText: data.description + }; + DialogService.showDialog({}, dialogOptions); + return; + } + }); + } + } + else{ + //registration has failed + var dialogOptions = { + headerText: 'registration_error', + bodyText: tei.description + }; + 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.trackedEntityInstance = teiId; + $scope.broadCastSelections(); + + }, 100); + + }); + }; + + $scope.resetRelationshipSource = function(){ + $scope.selectedRelationshipSource.value = ''; + }; + + $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.format(new Date()); + + CurrentSelection.setRelationshipInfo({tei: $scope.tei, src: $scope.selectedRelationshipSource}); + + $timeout(function() { + $rootScope.$broadcast('relationship', {}); + }, 100); + } + }; }); \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html 2014-07-04 14:36:11 +0000 @@ -10,7 +10,20 @@ <label><input type="radio" ng-model="selectedOuMode.name" name="accessible" value="ACCESSIBLE"> {{'ACCESSIBLE'| translate}}</label> </td> </tr> - <tr ng-if="selectedProgram"> + <tr> + <td> + {{'program' | translate}} + </td> + <td> + <select ng-model="selectedProgramForRelative" + class="form-control" + ng-change='setAttributesForSearch(selectedProgramForRelative)' + ng-options="program as program.name for program in programs | orderBy: 'name'"> + <option value="">{{'please_select_a_program'| translate}}</option> + </select> + </td> + </tr> + <tr ng-if="selectedProgramForRelative"> <td>{{'enrollment_date'| translate}}</td> <td> <div class="dataelement-filter"> === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/tei.html' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/tei.html 2014-07-04 10:10:13 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/relationship/tei.html 2014-07-04 14:36:11 +0000 @@ -23,7 +23,8 @@ </thead> <tbody id="list"> <tr ng-repeat="trackedEntity in trackedEntityList.rows" - ng-click="assignRelationship(trackedEntity)"> + ng-click="assignRelationship(trackedEntity)" + ng-show="trackedEntity.id !== selectedTei.trackedEntityInstance"> <td ng-show="gridColumn.show" ng-repeat="gridColumn in gridColumns"> {{trackedEntity[gridColumn.id]}} === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-07-03 11:30:22 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-07-04 14:36:11 +0000 @@ -506,7 +506,7 @@ .service('EntityQueryFactory', function(OperatorFactory){ - this.getQueryForAttributes = function(attributes, enrollment){ + this.getAttributesQuery = function(attributes, enrollment){ var query = {url: null, hasValue: false}; @@ -716,6 +716,7 @@ /* current selections */ .service('CurrentSelection', function(){ this.currentSelection = ''; + this.relationshipInfo = ''; this.set = function(currentSelection){ this.currentSelection = currentSelection; @@ -724,6 +725,14 @@ this.get = function(){ return this.currentSelection; }; + + this.setRelationshipInfo = function(relationshipInfo){ + this.relationshipInfo = relationshipInfo; + }; + + this.getRelationshipInfo = function(){ + return this.relationshipInfo; + }; }) /* Translation service - gets logged in user profile for the server, === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css 2014-07-03 12:40:31 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css 2014-07-04 14:36:11 +0000 @@ -752,7 +752,8 @@ } @media screen and (min-width: 768px) { .modal-dialog { - width: 75%; + width: 100%; + height: 100%; padding-top: 30px; padding-bottom: 30px; }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp