dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36538
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18684: tracker-capture: registration, enrollment and profile sharing a single controller
------------------------------------------------------------
revno: 18684
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-03-25 17:43:47 +0100
message:
tracker-capture: registration, enrollment and profile sharing a single controller
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
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.html
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.html
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.html
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/scripts/controllers.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.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
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2015-03-19 10:18:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2015-03-25 16:43:47 +0000
@@ -251,7 +251,7 @@
var val = dataValue.value;
var de = $scope.prStDes[dataValue.dataElement].dataElement;
- if(de){
+ if(de){
if(val && de.type === 'string' && de.optionSet && $scope.optionSets[de.optionSet.id].options ){
val = OptionSetService.getName($scope.optionSets[de.optionSet.id].options, val);
}
@@ -276,8 +276,7 @@
if(stage.captureCoordinates){
event.coordinate = {latitude: event.coordinate.latitude ? event.coordinate.latitude : '',
longitude: event.coordinate.longitude ? event.coordinate.longitude : ''};
- }
-
+ }
event.allowProvidedElsewhereExists = false;
angular.forEach(stage.programStageDataElements, function(prStDe){
=== 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-03-11 11:21:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment-controller.js 2015-03-25 16:43:47 +0000
@@ -1,20 +1,18 @@
+/* global trackerCapture, angular */
+
trackerCapture.controller('EnrollmentController',
function($rootScope,
$scope,
$location,
$timeout,
DateUtils,
- EventUtils,
storage,
- DHIS2EventFactory,
AttributesFactory,
CurrentSelection,
- TEIService,
TEFormService,
CustomFormService,
EnrollmentService,
- ModalService,
- DialogService) {
+ ModalService) {
$scope.today = DateUtils.getToday();
$scope.selectedOrgUnit = storage.get('SELECTED_OU');
@@ -97,11 +95,15 @@
$scope.trackedEntityForm = teForm;
$scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'ENROLLMENT');
}
+ if($scope.selectedEnrollment.enrollment){
+ $scope.broadCastSelections('dashboardWidgets');
+ }
+ });
+ }
+ else{
+ if($scope.selectedEnrollment.enrollment){
$scope.broadCastSelections('dashboardWidgets');
- });
- }
- else{
- $scope.broadCastSelections('dashboardWidgets');
+ }
}
});
};
@@ -110,12 +112,21 @@
$scope.showEnrollmentDiv = !$scope.showEnrollmentDiv;
- if($scope.showEnrollmentDiv){
+ $timeout(function() {
+ $rootScope.$broadcast('enrollmentEditing', {enrollmentEditing: $scope.showEnrollmentDiv});
+ }, 100);
+
+ if($scope.showEnrollmentDiv){
+
$scope.showEnrollmentHistoryDiv = false;
//load new enrollment details
$scope.selectedEnrollment = {};
$scope.loadEnrollmentDetails($scope.selectedEnrollment);
+
+ $timeout(function() {
+ $rootScope.$broadcast('registrationWidget', {registrationMode: 'ENROLLMENT', selectedTei: $scope.selectedTei});
+ }, 100);
}
else{
hideEnrollmentDiv();
@@ -134,77 +145,6 @@
}
};
- $scope.enroll = function(){
-
- //check for form validity
- $scope.outerForm.submitted = true;
- if( $scope.outerForm.$invalid ){
- return false;
- }
-
- //form is valid, continue with enrollment
- var result = getProcessedForm();
- $scope.formEmpty = result.formEmpty;
- var tei = result.tei;
-
- if($scope.formEmpty){//form is empty
- return false;
- }
-
- var enrollment = {trackedEntityInstance: tei.trackedEntityInstance,
- program: $scope.selectedProgram.id,
- status: 'ACTIVE',
- dateOfEnrollment: $scope.selectedEnrollment.dateOfEnrollment,
- dateOfIncident: $scope.selectedEnrollment.dateOfIncident ? $scope.selectedEnrollment.dateOfIncident : $scope.selectedEnrollment.dateOfEnrollment
- };
-
- TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(updateResponse){
-
- if(updateResponse.status === 'SUCCESS'){
- //registration is successful, continue for enrollment
- EnrollmentService.enroll(enrollment).then(function(enrollmentResponse){
- if(enrollmentResponse.status !== 'SUCCESS'){
- //enrollment has failed
- var dialogOptions = {
- headerText: 'enrollment_error',
- bodyText: enrollmentResponse
- };
- DialogService.showDialog({}, dialogOptions);
- return;
- }
-
- enrollment.enrollment = enrollmentResponse.reference;
- $scope.selectedEnrollment = enrollment;
- $scope.enrollments.push($scope.selectedEnrollment);
-
- var dhis2Events = EventUtils.autoGenerateEvents(tei.trackedEntityInstance, $scope.selectedProgram, $scope.selectedOrgUnit, $scope.selectedEnrollment);
-
- $scope.showEnrollmentDiv = false;
- $scope.outerForm.submitted = false;
-
- CurrentSelection.set({tei: tei, te: $scope.selectedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: $scope.enrollments, selectedEnrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets});
- if(dhis2Events.events.length > 0){
- DHIS2EventFactory.create(dhis2Events).then(function(data) {
- $scope.broadCastSelections('dashboardWidgets');
- });
- }
- else{
- $scope.broadCastSelections('dashboardWidgets');
- }
- });
- }
- else{
- //update has failed
- var dialogOptions = {
- headerText: 'registration_error',
- bodyText: updateResponse.description
- };
- DialogService.showDialog({}, dialogOptions);
- return;
- }
- });
- };
-
$scope.broadCastSelections = function(listeners){
var selections = CurrentSelection.get();
var tei = selections.tei;
@@ -213,24 +153,6 @@
$timeout(function() {
$rootScope.$broadcast(listeners, {});
}, 100);
-
- $timeout(function() {
- $rootScope.$broadcast('enrollmentEditing', {enrollmentEditing: $scope.showEnrollmentDiv});
- }, 100);
- };
-
- var getProcessedForm = function(){
- var tei = angular.copy(selections.tei);
- tei.attributes = [];
- var formEmpty = true;
- for(var k in $scope.attributesById){
- if( $scope.selectedTei[k] ){
- tei.attributes.push({attribute: $scope.attributesById[k].id, value: $scope.selectedTei[k], displayName: $scope.attributesById[k].name, type: $scope.attributesById[k].valueType});
- formEmpty = false;
- }
- }
-
- return {tei: tei, formEmpty: formEmpty};
};
var processSelectedTei = function(){
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html 2015-02-27 09:37:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/enrollment/enrollment.html 2015-03-25 16:43:47 +0000
@@ -82,70 +82,7 @@
<!-- operations on selected enrollment ends -->
<!-- new enrollment registration form begins -->
- <form name="outerForm" novalidate>
- <div ng-if="showEnrollmentDiv">
- <div class="row col-sm-12 vertical-spacing" ng-if="selectedProgram && customFormExists">
- <div ng-if="!customForm.hasProgramDate">
- <table class="dhis2-list-table-striped dhis2-table-hover">
- <tr>
- <td>
- {{selectedProgram.dateOfEnrollmentDescription}}
- </td>
- <td>
- <input type="text"
- placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
- name="dateOfEnrollment"
- class="form-control"
- d2-date
- ng-model="selectedEnrollment.dateOfEnrollment"
- max-date="selectedProgram.selectEnrollmentDatesInFuture ? '' : 0"
- min-date=""
- 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"
- placeholder="{{dhis2CalendarFormat.keyDateFormat}}"
- name="dateOfIncident"
- class="form-control"
- d2-date
- max-date="selectedProgram.selectIncidentDatesInFuture ? '' : 0"
- min-date=""
- ng-model="selectedEnrollment.dateOfIncident"/>
- </td>
- </tr>
- </table>
- </div>
- <div ng-include="'../dhis-web-commons/customform/custom-form.html'"></div>
- </div>
- <div class="row col-sm-12 vertical-spacing" ng-if="!customFormExists">
- <div ng-include="'views/enrollment-dates-form.html'"></div>
- <div ng-include="'views/default-registration-form.html'"></div>
- </div>
-
- <div ng-if="formEmpty && outerForm.submitted">
- <div class="alert alert-warning">{{'form_is_empty_fill_at_least_one'| translate}}</div>
- </div>
-
- <div class="vertical-spacing row col-sm-12">
- <button type="button"
- class="btn btn-primary"
- ng-click="enroll()">
- {{'enroll'| translate}}
- </button>
- <button type="button"
- class="btn btn-default"
- ng-click="showNewEnrollment()">
- {{'cancel'| translate}}
- </button>
- </div>
- </div>
- </form>
+ <div ng-if="showEnrollmentDiv" ng-include="'components/registration/registration.html'"></div>
<!-- new enrollment registration form ends -->
<!-- operations on historical enrollment begins -->
@@ -189,4 +126,4 @@
<!-- various alerts end -->
</div>
-</div>
\ No newline at end of file
+</div>
=== 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-03-09 16:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2015-03-25 16:43:47 +0000
@@ -1,11 +1,12 @@
+/* global trackerCapture, angular */
+
trackerCapture.controller('ProfileController',
function($rootScope,
- $scope,
+ $scope,
+ $timeout,
CurrentSelection,
CustomFormService,
TEFormService,
- TEIService,
- DialogService,
AttributesFactory) {
$scope.editingDisabled = true;
@@ -47,6 +48,9 @@
});
}
});
+ $timeout(function() {
+ $rootScope.$broadcast('registrationWidget', {registrationMode: 'PROFILE', selectedTei: $scope.selectedTei, enrollment: $scope.selectedEnrollment});
+ }, 100);
});
//listen for enrollment editing
@@ -60,50 +64,11 @@
$rootScope.profileWidget.expand = true;
};
- $scope.save = function(){
- //check for form validity
- $scope.outerForm.submitted = true;
- if( $scope.outerForm.$invalid ){
- return false;
- }
-
- //form is valid, continue the update process
- //get tei attributes and their values
- //but there could be a case where attributes are non-mandatory and
- //form comes empty, in this case enforce at least one value
- $scope.formEmpty = true;
- var tei = angular.copy(selections.tei);
- tei.attributes = [];
- for(var k in $scope.attributesById){
- if( $scope.selectedTei.hasOwnProperty(k) && $scope.selectedTei[k] ){
- tei.attributes.push({attribute: $scope.attributesById[k].id, value: $scope.selectedTei[k], type: $scope.attributesById[k].valueType});
- $scope.formEmpty = false;
- }
- }
-
- if($scope.formEmpty){//form is empty
- return false;
- }
-
- TEIService.update(tei, $scope.optionSets, $scope.attributesById).then(function(updateResponse){
-
- if(updateResponse.status !== 'SUCCESS'){//update has failed
- var dialogOptions = {
- headerText: 'update_error',
- bodyText: updateResponse.description
- };
- DialogService.showDialog({}, dialogOptions);
- return;
- }
-
- $scope.editingDisabled = !$scope.editingDisabled;
- CurrentSelection.set({tei: tei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: $scope.selectedEnrollment, optionSets: $scope.optionSets});
- $scope.outerForm.submitted = false;
- });
- };
-
$scope.cancel = function(){
$scope.selectedTei = $scope.teiOriginal;
$scope.editingDisabled = !$scope.editingDisabled;
+ $timeout(function() {
+ $rootScope.$broadcast('registrationWidget', {registrationMode: 'PROFILE', selectedTei: $scope.selectedTei, enrollment: $scope.selectedEnrollment});
+ }, 100);
};
});
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html 2015-02-27 09:37:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html 2015-03-25 16:43:47 +0000
@@ -1,6 +1,5 @@
<div class="panel panel-info" ng-controller="ProfileController">
<div class="panel-heading handle bold">
-
{{profileWidget.title| translate}}
<span class="nav-pills" ng-if="!enrollmentEditing">
| <a href ng-click="enableEdit()" title="{{'edit_profile'| translate}}"><span ng-class="{true: 'widget - link - active', false: 'widget - link'} [!editingDisabled]">{{'edit'| translate}}</span></a>
@@ -16,26 +15,8 @@
</div>
<div ng-show="profileWidget.expand" class="panel-body dashboard-widget-container">
<form name="outerForm" novalidate>
- <div ng-if="!enrollmentEditing">
- <div class="vertical-spacing" ng-if="customFormExists">
- <div ng-include="'../dhis-web-commons/customform/custom-form.html'"></div>
- </div>
- <div class="vertical-spacing" ng-if="!customFormExists">
- <div ng-include="'views/default-registration-form.html'"></div>
- </div>
-
- <div ng-if="!editingDisabled" class="vertical-spacing">
- <button type="button"
- class="btn btn-primary small-horizonal-spacing"
- ng-click="save()">
- {{'save'| translate}}
- </button>
- <button type="button"
- class="btn btn-default small-horizonal-spacing"
- ng-click="cancel()">
- {{'cancel'| translate}}
- </button>
- </div>
+ <div ng-if="!enrollmentEditing">
+ <div ng-include="'components/registration/registration.html'"></div>
</div>
</form>
</div>
=== 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-03-09 16:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js 2015-03-25 16:43:47 +0000
@@ -1,3 +1,5 @@
+/* global trackerCapture, angular */
+
trackerCapture.controller('RegistrationController',
function($rootScope,
$scope,
@@ -6,7 +8,6 @@
AttributesFactory,
DHIS2EventFactory,
TEService,
- TEIService,
TEFormService,
CustomFormService,
EnrollmentService,
@@ -14,13 +15,16 @@
CurrentSelection,
OptionSetService,
EventUtils,
+ RegistrationService,
DateUtils,
storage) {
$scope.today = DateUtils.getToday();
$scope.trackedEntityForm = null;
$scope.customForm = null;
- $scope.selectedTei = {};
+ $scope.selectedTei = {};
+ $scope.tei = {};
+ $scope.registrationMode = null;
$scope.attributesById = CurrentSelection.getAttributesById();
if(!$scope.attributesById){
@@ -59,10 +63,30 @@
$scope.$watch('selectedProgram', function() {
$scope.trackedEntityForm = null;
$scope.customForm = null;
- $scope.getAttributes();
- });
-
- $scope.getAttributes = function(){
+ if($scope.registrationMode === 'REGISTRATION'){
+ $scope.getAttributes($scope.registrationMode);
+ }
+ });
+
+ //listen to modes of registration
+ $scope.$on('registrationWidget', function(event, args){
+ $scope.selectedTei = {};
+ $scope.tei = {};
+ $scope.registrationMode = args.registrationMode;
+ $scope.getAttributes($scope.registrationMode);
+
+ if($scope.registrationMode !== 'REGISTRATION'){
+ $scope.selectedTei = args.selectedTei;
+ $scope.tei = angular.copy(args.selectedTei);
+ }
+
+ if($scope.registrationMode === 'PROFILE'){
+ $scope.selectedEnrollment = args.enrollment;
+ }
+ });
+
+ $scope.getAttributes = function(_mode){
+ var mode = _mode ? _mode : 'ENROLLMENT';
AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
$scope.attributes = atts;
$scope.customFormExists = false;
@@ -70,59 +94,55 @@
if(angular.isObject(teForm)){
$scope.customFormExists = true;
$scope.trackedEntityForm = teForm;
- $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, 'ENROLLMENT');
+ $scope.customForm = CustomFormService.getForTrackedEntity($scope.trackedEntityForm, mode);
}
});
});
};
$scope.registerEntity = function(destination){
+
//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.selectedProgram){
- selectedTrackedEntity = $scope.selectedProgram.trackedEntity.id;
+ //get selected entity
+ if(!$scope.selectedTei.trackedEntityInstance){
+ $scope.selectedTei.trackedEntity = $scope.tei.trackedEntity = $scope.selectedProgram && $scope.selectedProgram.trackedEntity && $scope.selectedProgram.trackedEntity.id ? $scope.selectedProgram.trackedEntity.id : $scope.trackedEntities.selected.id;
+ $scope.selectedTei.orgUnit = $scope.selectedTei.orgUnit = $scope.selectedOrgUnit.id;
+ $scope.selectedTei.attributes = $scope.selectedTei.attributes = [];
}
//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.formEmpty = true;
- $scope.tei = {trackedEntity: selectedTrackedEntity, orgUnit: $scope.selectedOrgUnit.id, attributes: [] };
- for(var k in $scope.attributesById){
- if( $scope.selectedTei.hasOwnProperty(k) && $scope.selectedTei[k] ){
- var val = $scope.selectedTei[k];
- $scope.tei.attributes.push({attribute: $scope.attributesById[k].id, value: val, type: $scope.attributesById[k].valueType});
- $scope.formEmpty = false;
- }
- }
+
+ var result = RegistrationService.processForm($scope.tei, $scope.selectedTei, $scope.attributesById);
+ $scope.formEmpty = result.formEmpty;
+ $scope.tei = result.tei;
if($scope.formEmpty){//registration form is empty
return false;
}
- var teiId = '';
- TEIService.register($scope.tei, $scope.optionSets, $scope.attributesById).then(function(response){
-
+ RegistrationService.registerOrUpdate($scope.tei, $scope.optionSets, $scope.attributesById).then(function(response){
if(response.status === 'SUCCESS'){
-
- teiId = response.reference;
-
- //registration is successful and check for enrollment
- if($scope.selectedProgram){
+ if( $scope.tei && !$scope.tei.trackedEntityInstance ){
+ $scope.tei.trackedEntityInstance = response.reference;
+ }
+
+ if($scope.selectedProgram && $scope.registrationMode !== 'PROFILE'){
//enroll TEI
- var enrollment = {trackedEntityInstance: teiId,
- program: $scope.selectedProgram.id,
- status: 'ACTIVE',
- dateOfEnrollment: $scope.selectedEnrollment.dateOfEnrollment,
- dateOfIncident: $scope.selectedEnrollment.dateOfIncident === '' ? $scope.selectedEnrollment.dateOfEnrollment : $scope.selectedEnrollment.dateOfIncident
- };
+ var enrollment = {};
+ enrollment.trackedEntityInstance = $scope.tei.trackedEntityInstance;
+ enrollment.program = $scope.selectedProgram.id;
+ enrollment.status = 'ACTIVE';
+ enrollment.dateOfEnrollment = $scope.selectedEnrollment.dateOfEnrollment;
+ enrollment.dateOfIncident = $scope.selectedEnrollment.dateOfIncident === '' ? $scope.selectedEnrollment.dateOfEnrollment : $scope.selectedEnrollment.dateOfIncident;
+
EnrollmentService.enroll(enrollment).then(function(data){
if(data.status !== 'SUCCESS'){
//enrollment has failed
@@ -135,35 +155,28 @@
}
else{
enrollment.enrollment = data.reference;
- var dhis2Events = EventUtils.autoGenerateEvents(teiId, $scope.selectedProgram, $scope.selectedOrgUnit, enrollment);
+ $scope.selectedEnrollment = enrollment;
+ var dhis2Events = EventUtils.autoGenerateEvents($scope.tei.trackedEntityInstance, $scope.selectedProgram, $scope.selectedOrgUnit, enrollment);
if(dhis2Events.events.length > 0){
DHIS2EventFactory.create(dhis2Events).then(function(data){
- goToDashboard(destination, teiId);
+ notifyRegistrtaionCompletion(destination, $scope.tei.trackedEntityInstance);
});
}else{
- goToDashboard(destination, teiId);
+ notifyRegistrtaionCompletion(destination, $scope.tei.trackedEntityInstance);
}
}
});
- }
- else{
- goToDashboard(destination, teiId);
- }
+ }
}
- else{
- //registration has failed
+ else{//update/registration has failed
var dialogOptions = {
- headerText: 'registration_error',
+ headerText: $scope.tei && $scope.tei.trackedEntityInstance ? 'update_error' : 'registration_error',
bodyText: response.description
};
DialogService.showDialog({}, dialogOptions);
return;
- }
- });
- };
-
- $scope.resetRelationshipSource = function(){
- $scope.selectedRelationshipSource = '';
+ }
+ });
};
$scope.broadCastSelections = function(){
@@ -194,4 +207,19 @@
$scope.broadCastSelections();
}
};
+
+ var notifyRegistrtaionCompletion = function(destination, teiId){
+ goToDashboard( destination ? destination : 'DASHBOARD', teiId );
+ /*if($scope.registrationMode === 'REGISTRATION'){
+ goToDashboard(destination, teiId);
+ }
+ else{
+
+ var selections = CurrentSelection.get();
+ CurrentSelection.set({tei: $scope.selectedTei, te: $scope.selectedTei.trackedEntity, prs: selections.prs, pr: $scope.selectedProgram, prNames: selections.prNames, prStNames: selections.prStNames, enrollments: selections.enrollments.push($scope.selectedEnrollment), selectedEnrollment: $scope.selectedEnrollment, optionSets: selections.optionSets});
+ $timeout(function() {
+ $rootScope.$broadcast('selectedItems', {programExists: selections.prs.length > 0});
+ }, 100);
+ }*/
+ };
});
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html 2015-02-27 09:37:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html 2015-03-25 16:43:47 +0000
@@ -1,10 +1,31 @@
-<div class="bordered-div col-md-12" ng-controller="RegistrationController">
+<div ng-class="{true: 'bordered-div'} [registrationMode === 'REGISTRATION']" ng-controller="RegistrationController">
<!--registration form starts -->
<form name="outerForm" novalidate>
+
+ <!-- Entity type begins -->
+ <div ng-if="!selectedProgram && registrationMode === 'REGISTRATION'">
+ <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>
+ <!-- Entity type ends -->
+
<!--custom registration form begins -->
<div class="row col-sm-12 vertical-spacing" ng-if="customFormExists">
- <div ng-if="selectedProgram && !customForm.hasProgramDate">
+
+ <!-- enrollment and incidence dates begin -->
+ <div ng-if="selectedProgram && !customForm.hasProgramDate && registrationMode !== 'PROFILE'">
<table class="dhis2-list-table-striped dhis2-table-hover">
<tr>
<td>
@@ -40,42 +61,16 @@
</tr>
</table>
</div>
- <div ng-if="!selectedProgram">
- <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>
+ <!-- enrollment and incidence dates begin -->
+
<div ng-include="'../dhis-web-commons/customform/custom-form.html'"></div>
+
</div>
<!-- custom registration form ends-->
<!-- default registration form begins -->
- <div class="row col-sm-12 vertical-spacing" ng-if="!customFormExists">
- <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>
- <div ng-if="selectedProgram" ng-include="'views/enrollment-dates-form.html'"></div>
+ <div class="row col-sm-12 vertical-spacing" ng-if="!customFormExists">
+ <div ng-if="selectedProgram && registrationMode !== 'PROFILE'" ng-include="'views/enrollment-dates-form.html'"></div>
<div ng-include="'views/default-registration-form.html'"></div>
</div>
<!-- default registration form ends -->
@@ -84,11 +79,22 @@
<div class="alert alert-warning">{{'form_is_empty_fill_at_least_one'| translate}}</div>
</div>
- <div class="vertical-spacing">
+ <div ng-if="!editingDisabled && registrationMode === 'PROFILE'" class="vertical-spacing">
+ <button type="button" class="btn btn-primary small-horizonal-spacing" ng-click="registerEntity(null)">{{'save'| translate}}</button>
+ <button type="button" class="btn btn-default small-horizonal-spacing" ng-click="cancel()">{{'cancel'| translate}}</button>
+ </div>
+
+ <div class="vertical-spacing" ng-if="registrationMode === 'ENROLLMENT'">
+ <button type="button" class="btn btn-primary" ng-click="registerEntity(null)">{{'enroll'| translate}}</button>
+ <button type="button" class="btn btn-default" ng-click="showNewEnrollment()">{{'cancel'| translate}}</button>
+ </div>
+
+ <div class="vertical-spacing" ng-if="registrationMode === 'REGISTRATION'">
<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>
<!--registration form ends -->
</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-03-10 08:57:34 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-03-25 16:43:47 +0000
@@ -1,3 +1,5 @@
+/* global trackerCapture, angular */
+
trackerCapture.controller('RelationshipController',
function($scope,
$rootScope,
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2015-03-19 10:18:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js 2015-03-25 16:43:47 +0000
@@ -7,11 +7,13 @@
//Controller for settings page
.controller('SelectionController',
- function($scope,
+ function($rootScope,
+ $scope,
$modal,
$location,
$translate,
$filter,
+ $timeout,
Paginator,
storage,
DateUtils,
@@ -305,10 +307,15 @@
$scope.showRegistration = function(){
$scope.showRegistrationDiv = !$scope.showRegistrationDiv;
- $scope.showTrackedEntityDiv = false;
- $scope.showSearchDiv = false;
- if(!$scope.showRegistrationDiv){
+ if($scope.showRegistrationDiv){
+ $scope.showTrackedEntityDiv = false;
+ $scope.showSearchDiv = false;
+ $timeout(function() {
+ $rootScope.$broadcast('registrationWidget', {registrationMode: 'REGISTRATION'});
+ }, 100);
+ }
+ else{
$scope.doSearch = true;
$scope.getProgramAttributes($scope.selectedProgram);
}
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-03-19 10:18:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2015-03-25 16:43:47 +0000
@@ -436,6 +436,42 @@
};
})
+/* service to deal with TEI registration and update */
+.service('RegistrationService', function(DialogService, TEIService, $q){
+ return {
+ registerOrUpdate: function(tei, optionSets, attributesById){
+ if(tei){
+ var def = $q.defer();
+ if(tei.trackedEntityInstance){
+ TEIService.update(tei, optionSets, attributesById).then(function(response){
+ def.resolve(response);
+ });
+ }
+ else{
+ TEIService.register(tei, optionSets, attributesById).then(function(response){
+ def.resolve(response);
+ });
+ }
+ return def.promise;
+ }
+ },
+ processForm: function(existingTei, formTei, attributesById){
+ var tei = angular.copy(existingTei);
+ tei.attributes = [];
+ var formEmpty = true;
+ for(var k in attributesById){
+ if( formTei[k] ){
+ var att = attributesById[k];
+ tei.attributes.push({attribute: att.id, value: formTei[k], displayName: att.name, type: att.valueType});
+ formEmpty = false;
+ }
+ delete tei[k];
+ }
+ return {tei: tei, formEmpty: formEmpty};
+ }
+ };
+})
+
/* Service to deal with enrollment */
.service('EnrollmentService', function($http, DateUtils) {
@@ -843,7 +879,7 @@
})
/* factory for handling events */
-.factory('DHIS2EventFactory', function($http, $q) {
+.factory('DHIS2EventFactory', function($http) {
return {
@@ -854,7 +890,12 @@
return promise;
},
getEventsByProgram: function(entity, program){
- var promise = $http.get( '../api/events.json?' + 'trackedEntityInstance=' + entity + '&program=' + program + '&paging=false').then(function(response){
+
+ var url = '../api/events.json?' + 'trackedEntityInstance=' + entity + '&paging=false';
+ if(program){
+ url = url + '&program=' + program;
+ }
+ var promise = $http.get( url ).then(function(response){
return response.data.events;
});
return promise;