=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js 2015-03-06 09:37:05 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js 2015-03-06 14:43:54 +0000 @@ -105,17 +105,7 @@ }); setWidgetsSize(); - - AttributesFactory.getAll().then(function(atts){ - $scope.attributes = []; - $scope.attributesById = []; - angular.forEach(atts, function(att){ - $scope.attributesById[att.id] = att; - }); - - CurrentSelection.setAttributesById($scope.attributesById); - $scope.broadCastSelections(); - }); + $scope.broadCastSelections(); }); }; @@ -136,57 +126,66 @@ //get option sets $scope.optionSets = []; - OptionSetService.getAll().then(function(optionSets){ - - angular.forEach(optionSets, function(optionSet){ + OptionSetService.getAll().then(function(optionSets){ + angular.forEach(optionSets, function(optionSet){ $scope.optionSets[optionSet.id] = optionSet; }); - - //Fetch the selected entity - TEIService.get($scope.selectedTeiId, $scope.optionSets).then(function(response){ - $scope.selectedTei = response.data; - - //get the entity type - TEService.get($scope.selectedTei.trackedEntity).then(function(te){ - $scope.trackedEntity = te; - - //get enrollments for the selected tei - EnrollmentService.getByEntity($scope.selectedTeiId).then(function(response){ - var enrollments = angular.isObject(response) && response.enrollments ? response.enrollments : []; - var selectedEnrollment = null; - if(enrollments.length === 1 && enrollments[0].status === 'ACTIVE'){ - selectedEnrollment = enrollments[0]; - } - - ProgramFactory.getAll().then(function(programs){ - $scope.programs = []; - - $scope.programNames = []; - $scope.programStageNames = []; - - //get programs valid for the selected ou and tei - angular.forEach(programs, function(program){ - $scope.programNames[program.id] = {id: program.id, name: program.name}; - angular.forEach(program.programStages, function(stage){ - $scope.programStageNames[stage.id] = {id: stage.id, name: stage.name}; + + AttributesFactory.getAll().then(function(atts){ + + $scope.attributesById = []; + angular.forEach(atts, function(att){ + $scope.attributesById[att.id] = att; + }); + + CurrentSelection.setAttributesById($scope.attributesById); + + //Fetch the selected entity + TEIService.get($scope.selectedTeiId, $scope.optionSets, $scope.attributesById).then(function(response){ + $scope.selectedTei = response.data; + + //get the entity type + TEService.get($scope.selectedTei.trackedEntity).then(function(te){ + $scope.trackedEntity = te; + + //get enrollments for the selected tei + EnrollmentService.getByEntity($scope.selectedTeiId).then(function(response){ + var enrollments = angular.isObject(response) && response.enrollments ? response.enrollments : []; + var selectedEnrollment = null; + if(enrollments.length === 1 && enrollments[0].status === 'ACTIVE'){ + selectedEnrollment = enrollments[0]; + } + + ProgramFactory.getAll().then(function(programs){ + $scope.programs = []; + + $scope.programNames = []; + $scope.programStageNames = []; + + //get programs valid for the selected ou and tei + angular.forEach(programs, function(program){ + $scope.programNames[program.id] = {id: program.id, name: program.name}; + angular.forEach(program.programStages, function(stage){ + $scope.programStageNames[stage.id] = {id: stage.id, name: stage.name}; + }); + if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id) && + program.trackedEntity.id === $scope.selectedTei.trackedEntity){ + $scope.programs.push(program); + + if($scope.selectedProgramId && program.id === $scope.selectedProgramId || selectedEnrollment && selectedEnrollment.program === program.id){ + $scope.selectedProgram = program; + } + } }); - if(program.organisationUnits.hasOwnProperty($scope.selectedOrgUnit.id) && - program.trackedEntity.id === $scope.selectedTei.trackedEntity){ - $scope.programs.push(program); - - if($scope.selectedProgramId && program.id === $scope.selectedProgramId || selectedEnrollment && selectedEnrollment.program === program.id){ - $scope.selectedProgram = program; - } - } + + //prepare selected items for broadcast + CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: enrollments, selectedEnrollment: selectedEnrollment, optionSets: $scope.optionSets}); + getDashboardLayout(); }); - - //prepare selected items for broadcast - CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: enrollments, selectedEnrollment: selectedEnrollment, optionSets: $scope.optionSets}); - getDashboardLayout(); }); - }); - }); - }); + }); + }); + }); }); } === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-02-27 09:37:56 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-03-06 14:43:54 +0000 @@ -17,7 +17,9 @@ DialogService) { $scope.today = DateUtils.getToday(); - $scope.selectedOrgUnit = storage.get('SELECTED_OU'); + $scope.selectedOrgUnit = storage.get('SELECTED_OU'); + + //listen for the selected items var selections = {}; @@ -43,6 +45,7 @@ $scope.programExists = args.programExists; $scope.programNames = selections.prNames; $scope.programStageNames = selections.prStNames; + $scope.attributesById = CurrentSelection.getAttributesById(); if($scope.selectedProgram){ @@ -171,7 +174,7 @@ dateOfIncident: $scope.selectedEnrollment.dateOfIncident ? $scope.selectedEnrollment.dateOfIncident : $scope.selectedEnrollment.dateOfEnrollment }; - TEIService.update(tei, $scope.optionSets).then(function(updateResponse){ + TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(updateResponse){ if(updateResponse.status === 'SUCCESS'){ //registration is successful, continue for enrollment @@ -220,7 +223,6 @@ }; var getProcessedForm = function(){ - $scope.attributesById = CurrentSelection.getAttributesById(); var tei = angular.copy(selections.tei); tei.attributes = []; var formEmpty = true; === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2015-02-27 09:37:56 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2015-03-06 14:43:54 +0000 @@ -13,7 +13,7 @@ //listen for the selected entity var selections = {}; - $scope.$on('dashboardWidgets', function(event, args) { + $scope.$on('dashboardWidgets', function(event, args) { selections = CurrentSelection.get(); $scope.selectedTei = angular.copy(selections.tei); $scope.trackedEntity = selections.te; @@ -82,7 +82,7 @@ return false; } - TEIService.update(tei, $scope.optionSets).then(function(updateResponse){ + TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(updateResponse){ if(updateResponse.status !== 'SUCCESS'){//update has failed var dialogOptions = { === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-02-27 09:37:56 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-03-06 14:43:54 +0000 @@ -19,16 +19,21 @@ $scope.today = DateUtils.getToday(); $scope.trackedEntityForm = null; - $scope.customForm = null; - $scope.optionSets = CurrentSelection.getOptionSets(); - $scope.attributesById = []; - $scope.selectedTei = {}; - AttributesFactory.getAll().then(function(atts){ - angular.forEach(atts, function(att){ - $scope.attributesById[att.id] = att; + $scope.customForm = null; + $scope.selectedTei = {}; + + $scope.attributesById = CurrentSelection.getAttributesById(); + if(!$scope.attributesById){ + AttributesFactory.getAll().then(function(atts){ + angular.forEach(atts, function(att){ + $scope.attributesById[att.id] = att; + }); + + CurrentSelection.setAttributesById($scope.attributesById); }); - }); - + } + + $scope.optionSets = CurrentSelection.getOptionSets(); if(!$scope.optionSets){ $scope.optionSets = []; OptionSetService.getAll().then(function(optionSets){ @@ -102,7 +107,7 @@ } var teiId = ''; - TEIService.register($scope.tei, $scope.optionSets).then(function(response){ + TEIService.register($scope.tei, $scope.optionSets, $scope.attributesById).then(function(response){ if(response.status === 'SUCCESS'){ === 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-02-24 16:15:59 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-03-06 14:43:54 +0000 @@ -3,8 +3,7 @@ $rootScope, $modal, $location, - DateUtils, - OptionSetService, + AttributesFactory, CurrentSelection, RelationshipFactory) { $rootScope.showAddRelationshipDiv = false; @@ -110,25 +109,8 @@ var attributes = {}; if(tei && tei.relative && tei.relative.attributes && !tei.relative.processed){ - angular.forEach(tei.relative.attributes, function(att){ - var val = att.value; - if(att.type === 'trueOnly'){ - val = val === 'true' ? true : ''; - } - else{ - if(val){ - if(att.type === 'date'){ - val = DateUtils.formatFromApiToUser(val); - } - if(att.type === 'optionSet' && - $scope.attributesById[att.attribute] && - $scope.attributesById[att.attribute].optionSet && - $scope.attributesById[att.attribute].optionSet.id && - $scope.optionSets[$scope.attributesById[att.attribute].optionSet.id]){ - val = OptionSetService.getName($scope.optionSets[$scope.attributesById[att.attribute].optionSet.id].options, val); - } - } - } + angular.forEach(tei.relative.attributes, function(att){ + var val = AttributesFactory.formatAttributeValue(att,$scope.attributesById, $scope.optionSets, 'USER'); attributes[att.attribute] = val; }); } @@ -438,7 +420,7 @@ }); tei.relationships.push(relationship); - TEIService.update(tei, $scope.optionSets).then(function(response){ + TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(response){ if(response.status !== 'SUCCESS'){//update has failed var dialogOptions = { headerText: 'relationship_error', === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js 2015-03-06 10:22:47 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js 2015-03-06 14:43:54 +0000 @@ -10,6 +10,9 @@ TEIGridService, AttributesFactory, ProgramFactory, + CurrentSelection, + OptionSetService, + TEIService, storage) { $scope.today = DateUtils.getToday(); @@ -18,6 +21,32 @@ $scope.displayMode = {}; $scope.printMode = false; + //get optionsets + $scope.optionSets = CurrentSelection.getOptionSets(); + if(!$scope.optionSets){ + $scope.optionSets = []; + OptionSetService.getAll().then(function(optionSets){ + angular.forEach(optionSets, function(optionSet){ + $scope.optionSets[optionSet.id] = optionSet; + }); + + CurrentSelection.setOptionSets($scope.optionSets); + }); + } + + //get attributes + $scope.attributesById = CurrentSelection.getAttributesById(); + if(!$scope.attributesById){ + AttributesFactory.getAll().then(function(atts){ + $scope.attributes = []; + $scope.attributesById = []; + angular.forEach(atts, function(att){ + $scope.attributesById[att.id] = att; + }); + CurrentSelection.setAttributesById($scope.attributesById); + }); + } + //Paging $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5}; @@ -43,19 +72,21 @@ $scope.programs.push(program); } }); - if($scope.programs.length === 1){ - $scope.selectedProgram = $scope.programs[0]; + if($scope.programs.length === 0){ + $scope.selectedProgram = null; } else{ - var continueLoop = true; - for(var i=0; i