=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json 2014-05-16 13:58:07 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json 2014-05-19 11:33:07 +0000 @@ -75,6 +75,9 @@ "add_new": "Add New", "register_new": "Register new", "registration": "Registration", + "registration_error": "Error in registration", + "category": "Category", + "entity_type": "Entity type", "save_and_add_new": "Save and add new", "save_and_go_back": "Save and go back", "save_and_continue": "Save and continue", === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-05-16 13:58:07 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2014-05-19 11:33:07 +0000 @@ -11,11 +11,10 @@ $modal, Paginator, TranslationService, - SelectedEntity, storage, AttributesFactory, EntityQueryFactory, - TrackedEntityInstanceService) { + TEIService) { //Selection $scope.selectedOrgUnit = ''; @@ -123,8 +122,8 @@ programUrl = 'program=' + $scope.selectedProgram.id; } - $scope.gridColumns = $scope.generateGridColumns($scope.attributes); - + $scope.gridColumns = $scope.generateGridColumns($scope.attributes); + if( mode === $scope.searchMode.freeText ){ if(!$scope.searchText){ $scope.emptySearchText = true; @@ -149,7 +148,7 @@ } //get events for the specified parameters - TrackedEntityInstanceService.search($scope.selectedOrgUnit.id, + TEIService.search($scope.selectedOrgUnit.id, $scope.ouMode, queryUrl, programUrl, @@ -159,7 +158,7 @@ }; $scope.generateGridColumns = function(attributes){ - var columns = attributes; + var columns = angular.copy(attributes); //also add extra columns - orgunit for example columns.push({id: 'orgUnitName', name: 'Organisation unit', type: 'string'}); @@ -266,9 +265,8 @@ }; $scope.showDashboard = function(currentEntity){ - SelectedEntity.setSelectedEntity(currentEntity); storage.set('SELECTED_OU', $scope.selectedOrgUnit); - $location.path('/dashboard').search({selectedEntityId: currentEntity.id}); + $location.path('/dashboard').search({selectedEntityId: currentEntity.id, selectedOrgUnitId: $scope.selectedOrgUnit.id}); }; $scope.getHelpContent = function(){ @@ -303,17 +301,26 @@ .controller('RegistrationController', function($scope, + $location, AttributesFactory, + TEIService, + EnrollmentService, + DialogService, + storage, TranslationService) { //do translation of the registration page TranslationService.translate(); + $scope.enrollment = {enrollmentDate: '', incidentDate: ''}; $scope.attributes = AttributesFactory.getWithoutProgram(); + $scope.trackedEntities = {available: storage.get('TRACKED_ENTITIES')}; + $scope.trackedEntities.selected = $scope.trackedEntities.available[0]; + //watch for selection of org unit from tree $scope.$watch('selectedProgram', function() { - if( angular.isObject($scope.selectedProgram)){ + if( angular.isObject($scope.selectedProgram)){ $scope.trackedEntityList = []; $scope.attributes = AttributesFactory.getByProgram($scope.selectedProgram); } @@ -323,7 +330,56 @@ $scope.registerEntity(); }; - $scope.registerEntity = function(){ + $scope.registerEntity = function(){ + + var selectedTrackedEntity = ''; + if($scope.selectedProgram){ + selectedTrackedEntity = $scope.selectedProgram.trackedEntity.id; + } + else{ + selectedTrackedEntity = $scope.trackedEntities.selected.id; + } + + 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.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: registrationAttributes }; + + //Register TEI + TEIService.register($scope.tei).then(function(tei){ + if(tei.status === 'SUCCESS'){ + //check for enrollment + if($scope.selectedProgram){ + //enroll TEI + var enrollment = {trackedEntityInstance: tei.reference, + program: $scope.selectedProgram.id, + status: 'ACTIVE', + dateOfEnrollment: $scope.enrollment.enrollmentDate, + dateOfIncident: $scope.enrollment.incidentDate + }; + EnrollmentService.enroll(enrollment).then(function(data){ + if(data.status === 'SUCCESS'){ + $location.path('/dashboard').search({selectedEntityId: tei.reference}); + } + }); + } + else{ + $location.path('/dashboard').search({selectedEntityId: tei.reference}); + } + } + else{ + var dialogOptions = { + headerText: 'registration_error', + bodyText: tei.description + }; + DialogService.showDialog({}, dialogOptions); + } + }); }; }) //Controller for dashboard @@ -333,8 +389,8 @@ $location, $modal, storage, - TrackedEntityInstanceService, - SelectedEntity, + TEIService, + CurrentSelection, TranslationService) { //do translation of the dashboard page @@ -363,12 +419,11 @@ if( $scope.selectedEntityId ){ //Fetch the selected entity - TrackedEntityInstanceService.get($scope.selectedEntityId).then(function(data){ - $scope.selectedEntity = data; - SelectedEntity.setSelectedEntity($scope.selectedEntity); + TEIService.get($scope.selectedEntityId).then(function(data){ + CurrentSelection.set({tei: data, ou: $scope.selectedOrgUnit}); + //broadcast selected entity for dashboard controllers - $rootScope.$broadcast('selectedEntity', {}); - + $rootScope.$broadcast('selectedEntity', {}); }); } @@ -401,7 +456,7 @@ .controller('ProfileController', function($scope, storage, - SelectedEntity, + CurrentSelection, TranslationService) { TranslationService.translate(); @@ -414,9 +469,11 @@ }); //listen for the selected entity - $scope.$on('selectedEntity', function(event, args) { + $scope.$on('selectedEntity', function(event, args) { - $scope.selectedEntity = SelectedEntity.getSelectedEntity(); + var selections = CurrentSelection.get(); + $scope.selectedEntity = selections.tei; + $scope.selectedOrgUnit = selections.ou; $scope.trackedEntity = storage.get($scope.selectedEntity.trackedEntity); }); @@ -428,23 +485,21 @@ $scope, $filter, storage, - SelectedEntity, + CurrentSelection, EnrollmentService, TranslationService) { TranslationService.translate(); - //selected org unit - $scope.selectedOrgUnit = storage.get('SELECTED_OU'); - //programs for enrollment $scope.enrollments = []; $scope.programs = []; //listen for the selected items $scope.$on('selectedEntity', function(event, args) { - - $scope.selectedEntity = SelectedEntity.getSelectedEntity(); + var selections = CurrentSelection.get(); + $scope.selectedEntity = selections.tei; + $scope.selectedOrgUnit = selections.ou; angular.forEach(storage.get('TRACKER_PROGRAMS'), function(program){ program = storage.get(program.id); @@ -482,6 +537,7 @@ } $rootScope.$broadcast('dataentry', {selectedEntity: $scope.selectedEntity, + selectedOrgUnit: $scope.selectedOrgUnit, selectedProgramId: $scope.selectedProgram.id, selectedEnrollment: $scope.selectedEnrollment}); }); @@ -505,11 +561,6 @@ TranslationService.translate(); - //$scope.attributes = storage.get('ATTRIBUTES'); - - //selected org unit - $scope.selectedOrgUnit = storage.get('SELECTED_OU'); - //listen for the selected items $scope.$on('dataentry', function(event, args) { @@ -518,6 +569,7 @@ $scope.dhis2Events = []; $scope.selectedEntity = args.selectedEntity; + $scope.selectedOrgUnit = args.selectedOrgUnit $scope.selectedProgramId = args.selectedProgramId; $scope.selectedEnrollment = args.selectedEnrollment; === 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-05-16 11:32:21 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-05-19 11:33:07 +0000 @@ -152,7 +152,7 @@ }) /* Service for getting tracked entity instances */ -.factory('TrackedEntityInstanceService', function($http, $filter, EntityService) { +.factory('TEIService', function($http, $filter, EntityService) { var promise; return { @@ -211,6 +211,24 @@ return EntityService.formatter(response.data); }); return promise; + }, + register: function(tei){ + + var url = '../api/trackedEntityInstances'; + + var promise = $http.post(url, tei).then(function(response){ + return response.data; + }); + return promise; + }, + update: function(tei){ + + var url = '../api/trackedEntityInstances'; + + var promise = $http.put( url + '/' + tei.trackedEntityInstance , tei).then(function(response){ + return response.data; + }); + return promise; } }; }) @@ -500,16 +518,16 @@ }]) -/* current item selected from grid */ -.service('SelectedEntity', function(){ - this.selectedEntity = ''; +/* current selections */ +.service('CurrentSelection', function(){ + this.selection = ''; - this.setSelectedEntity = function(selectedEntity){ - this.selectedEntity = selectedEntity; + this.set = function(selection){ + this.selection = selection; }; - this.getSelectedEntity = function(){ - return this.selectedEntity; + this.get = function(){ + return this.selection; }; }) === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js 2014-03-26 09:44:22 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js 2014-05-19 11:33:07 +0000 @@ -164,7 +164,6 @@ return def.promise(); } - function getMetaPrograms() { var def = $.Deferred(); @@ -293,9 +292,10 @@ type: 'GET', data:'viewClass=detailed&paging=false' }).done( function(response) { - _.each(_.values(response.trackedEntities), function(te){ + /*_.each(_.values(response.trackedEntities), function(te){ localStorage[te.id] = JSON.stringify(te);; - }); + }); */ + localStorage['TRACKED_ENTITIES'] = JSON.stringify(response.trackedEntities); def.resolve(); }); === modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/registration.html' --- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/registration.html 2014-05-16 13:58:07 +0000 +++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/registration.html 2014-05-19 11:33:07 +0000 @@ -2,9 +2,24 @@
+
+

{{'category' | translate}}

+ + + + + +
+ {{'entity_type' | translate}} + + +
+
+
+

{{'profile' | translate}}

-
{{attribute.name}} @@ -47,30 +62,25 @@

{{'enrollment' | translate}}

- + - +
- {{'program'| translate}} + {{selectedProgram.dateOfEnrollmentDescription}} - +
- {{'program'| translate}} + {{selectedProgram.dateOfIncidentDescription}} - +
-