=== 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 13:10:51 +0000 +++ 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 @@ -3,6 +3,8 @@ $rootScope, $modal, $location, + DateUtils, + OptionSetService, CurrentSelection, RelationshipFactory) { $rootScope.showAddRelationshipDiv = false; @@ -15,9 +17,16 @@ $scope.relatedTeis = []; $scope.selections = CurrentSelection.get(); $scope.optionSets = $scope.selections.optionSets; - $scope.selectedTei = angular.copy($scope.selections.tei); + $scope.selectedTei = angular.copy($scope.selections.tei); $scope.attributesById = CurrentSelection.getAttributesById(); + $scope.attributes = []; + for(var key in $scope.attributesById){ + if($scope.attributesById.hasOwnProperty(key)){ + $scope.attributes.push($scope.attributesById[key]); + } + } + $scope.trackedEntity = $scope.selections.te; $scope.selectedEnrollment = $scope.selections.selectedEnrollment; $scope.selectedProgram = $scope.selections.pr; @@ -84,24 +93,52 @@ var setRelationships = function(){ $scope.relatedTeis = []; - angular.forEach($scope.selectedTei.relationships, function(rel){ + angular.forEach($scope.selectedTei.relationships, function(rel){ var teiId = rel.trackedEntityInstanceA; var relName = $scope.relationships[rel.relationship].aIsToB; if($scope.selectedTei.trackedEntityInstance === rel.trackedEntityInstanceA){ teiId = rel.trackedEntityInstanceB; relName = $scope.relationships[rel.relationship].bIsToA; } - var relative = {trackedEntityInstance: teiId, relName: relName, relId: rel.relationship}; + var relative = {trackedEntityInstance: teiId, relName: relName, relId: rel.relationship, attributes: getRelativeAttributes(rel)}; $scope.relatedTeis.push(relative); - - /*TEIService.get(teiId, $scope.optionSets).then(function(tei){ - var relative = tei.data; - relative.relName = relName; - relative.relId = rel.relationship; - $scope.relatedTeis.push(relative); - });*/ }); }; + + var getRelativeAttributes = function(tei){ + + 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); + } + } + } + attributes[att.attribute] = val; + }); + } + + if(tei && tei.relative && tei.relative.processed){ + attributes = tei.relative.attributes; + } + + return attributes; + }; }) //Controller for adding new relationship @@ -384,23 +421,24 @@ }; $scope.addRelationship = function(){ - if($scope.selectedTei && $scope.teiForRelationship && $scope.relationship.selected){ - + if($scope.selectedTei && $scope.teiForRelationship && $scope.relationship.selected){ + var tei = angular.copy($scope.selectedTei); var relationship = {}; relationship.relationship = $scope.relationship.selected.id; relationship.displayName = $scope.relationship.selected.name; + relationship.relative = {}; + relationship.trackedEntityInstanceA = $scope.selectedRelationship.aIsToB === $scope.relationship.selected.aIsToB ? $scope.selectedTei.trackedEntityInstance : $scope.teiForRelationship.id; relationship.trackedEntityInstanceB = $scope.selectedRelationship.bIsToA === $scope.relationship.selected.bIsToA ? $scope.teiForRelationship.id : $scope.selectedTei.trackedEntityInstance; - - if($scope.selectedTei.relationships){ - $scope.selectedTei.relationships.push(relationship); - } - else{ - $scope.selectedTei.relationships = [relationship]; - } - - TEIService.update($scope.selectedTei, $scope.optionSets).then(function(response){ + + tei.relationships = []; + angular.forEach($scope.selectedTei.relationships, function(rel){ + tei.relationships.push({relationship: rel.relationship, displayName: rel.displayName, trackedEntityInstanceA: rel.trackedEntityInstanceA, trackedEntityInstanceB: rel.trackedEntityInstanceB}); + }); + tei.relationships.push(relationship); + + TEIService.update(tei, $scope.optionSets).then(function(response){ if(response.status !== 'SUCCESS'){//update has failed var dialogOptions = { headerText: 'relationship_error', @@ -410,6 +448,16 @@ return; } + relationship.relative.processed = true; + relationship.relative.attributes = $scope.teiForRelationship; + + if($scope.selectedTei.relationships){ + $scope.selectedTei.relationships.push(relationship); + } + else{ + $scope.selectedTei.relationships = [relationship]; + } + $modalInstance.close($scope.selectedTei.relationships); }); } === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html 2015-02-24 13:10:51 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html 2015-02-24 16:15:59 +0000 @@ -21,12 +21,23 @@
{{'no_relationship'| translate}}
{{'relationship_not_possible'| translate}}
-
- +
+
+ + + + + -
+ {{'relationship' | translate}} + + {{att.name}} +
{{rel.relName}} + {{rel.attributes[att.id]}} +
+
\ No newline at end of file