@@ -324,10 +401,10 @@
- {{'data_element' | translate}}
+ {{'data_element'| translate}}
|
- {{'value' | translate}}
+ {{'value'| translate}}
|
@@ -337,22 +414,35 @@
{{eventGridColumn.name}}
-
+
-
+
{{'required'| translate}}
@@ -378,9 +477,11 @@
-
-
-
+
+
+
+
+
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/controllers.js 2014-02-18 12:33:44 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/controllers.js 2014-02-20 11:41:24 +0000
@@ -14,7 +14,9 @@
Paginator,
ContextMenuSelectedItem,
ModalService,
+ DialogService,
orderByFilter,
+ $filter,
$translate) {
//Get current locale
@@ -91,12 +93,18 @@
});
}
});
+
+ if($scope.programs.length === 1){
+ $scope.pr = $scope.programs[0];
+ $scope.loadEvents($scope.pr);
+ }
});
}
};
//fetch contents of selected program from server - with full details
$scope.loadEvents = function(program){
+
ProgramFactory.get(program.id).then(function(data){
$scope.selectedProgram = data;
@@ -128,13 +136,15 @@
}
$scope.dhis2Events[i][dataValue.dataElement] = dataValue.value;
}
- });
+ });
+
+ delete $scope.dhis2Events[i].dataValues;
}
else{//event is empty, remove from display list
var index = $scope.dhis2Events.indexOf($scope.dhis2Events[i]);
$scope.dhis2Events.splice(index,1);
i--;
- }
+ }
}
//generate grid headers using program stage data elements
@@ -183,13 +193,15 @@
$scope.outerForm.$valid = true;
- $scope.currentEvent = '';
+ $scope.currentEvent = {};
};
$scope.showEventRegistration = function(){
$scope.eventRegistration = !$scope.eventRegistration;
- $scope.currentEvent = $scope.newDhis2Event;
- $scope.outerForm.$valid = true;
+ $scope.currentEvent = $scope.newDhis2Event;
+ $scope.outerForm.submitted = false;
+
+ $scope.currentEvent = {};
};
$scope.showEditEventInGrid = function(){
@@ -200,10 +212,10 @@
};
$scope.showEditEventInFull = function(){
- $scope.currentEvent = ContextMenuSelectedItem.getSelectedItem();
+ $scope.currentEvent = ContextMenuSelectedItem.getSelectedItem();
+ $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);
$scope.editingEventInFull = !$scope.editingEventInFull;
$scope.eventRegistration = false;
- $scope.outerForm.$valid = true;
if($scope.currentEvent.dataValues.length !== $scope.selectedProgramStage.programStageDataElements.length){
angular.forEach($scope.selectedProgramStage.programStageDataElements, function(prStDe){
@@ -214,40 +226,84 @@
}
};
- $scope.addEvent = function(){
- $scope.eventRegistration = false;
- $scope.editingEventInFull = false;
- $scope.editingEventInGrid = false;
-
- $scope.outerForm.submitted = true;
-
- if($scope.outerForm.$invalid ){
+ $scope.addEvent = function(addingAnotherEvent){
+
+ //check for form validity
+ $scope.outerForm.submitted = true;
+ if( $scope.outerForm.$invalid ){
console.log('the form is invalid');
return false;
}
- console.log('the event to be added is: ', $scope.currentEvent);
- $scope.currentEvent = '';
- };
+ //the form is valid, get the values
+ var dataValues = [];
+ for(var dataElement in $scope.programStageDataElements){
+ dataValues.push({dataElement: dataElement, value: $scope.currentEvent[dataElement]});
+ }
+
+ var newEvent = angular.copy($scope.currentEvent);
+
+ //prepare the event to be created
+ var dhis2Event = {program: $scope.selectedProgram.id,
+ programStage: $scope.selectedProgramStage.id,
+ orgUnit: $scope.selectedOrgUnit.id,
+ status: 'ACTIVE',
+ eventDate: $filter('date')(new Date(), 'yyyy-MM-dd'),
+ dataValues: dataValues
+ };
+
+ //send the new event to server
+ DHIS2EventFactory.create(dhis2Event).then(function(data) {
+ if (data.importSummaries[0].status == 'ERROR') {
+ var dialogOptions = {
+ headerText: 'event_registration_error',
+ bodyText: data.importSummaries[0].description
+ };
+
+ DialogService.showDialog({}, dialogOptions);
+ }
+ else {
+
+ //add the new event to the grid
+ newEvent.event = data.importSummaries[0].reference;
+ $scope.dhis2Events.splice(0,0,newEvent);
+
+ //decide whether to stay in the current screen or not.
+ if(!addingAnotherEvent){
+ $scope.eventRegistration = false;
+ $scope.editingEventInFull = false;
+ $scope.editingEventInGrid = false;
+ }
+ $scope.currentEvent = {};
+ }
+ });
+ };
+
- $scope.updateEvent = function(){
-
- console.log('the form is: ', $scope.outerForm);
- //validate form
- $scope.outerForm.submitted = true;
-
- if($scope.outerForm.$invalid ){
- console.log('the form is invalid');
- return false;
+ $scope.updateEventDataValue = function(currentEvent, dataElement){
+
+ var newValue = currentEvent[dataElement];
+ var oldValue = $scope.currentEventOrginialValue[dataElement];
+
+ if( newValue !== oldValue ){
+
+ var dhis2Event = {event: currentEvent.event, dataValues: [{value: newValue, dataElement: dataElement}]};
+
+ DHIS2EventFactory.updateSingleValue(dhis2Event).then(function(data){
+
+ var continueLoop = true;
+ for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
+ if($scope.dhis2Events[i].event === currentEvent.event ){
+ $scope.dhis2Events[i] = currentEvent;
+ continueLoop = false;
+ }
+ }
+
+ //update original value
+ $scope.currentEventOrginialValue = angular.copy(currentEvent);
+ });
}
-
- $scope.eventRegistration = false;
- $scope.editingEventInFull = false;
- $scope.editingEventInGrid = false;
-
- console.log('the event to be updated is: ', $scope.currentEvent);
- $scope.currentEvent = '';
- };
+ };
$scope.removeEvent = function(){
var dhis2Event = ContextMenuSelectedItem.getSelectedItem();
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/directives.js 2014-02-17 10:22:59 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/directives.js 2014-02-20 11:41:24 +0000
@@ -4,6 +4,72 @@
var eventCaptureDirectives = angular.module('eventCaptureDirectives', [])
+.directive('inputValidator', function() {
+
+ return {
+ require: 'ngModel',
+ link: function (scope, element, attrs, ctrl) {
+
+ //console.log('the model is: ', attrs.programStageDataElement);
+ ctrl.$parsers.push(function (value) {
+ return parseFloat(value || '');
+ });
+ }
+ };
+})
+
+.directive('dhisContextMenu', function(ContextMenuSelectedItem) {
+
+ return {
+ restrict: 'A',
+ link: function(scope, element, attrs){
+ var contextMenu = $("#contextMenu");
+
+ element.click(function (e) {
+ var selectedItem = $.parseJSON(attrs.selectedItem);
+ ContextMenuSelectedItem.setSelectedItem(selectedItem);
+
+ var menuHeight = contextMenu.height();
+ var menuWidth = contextMenu.width();
+ var winHeight = $(window).height();
+ var winWidth = $(window).width();
+
+ var pageX = e.pageX;
+ var pageY = e.pageY;
+
+ contextMenu.show();
+
+ if( (menuWidth + pageX) > winWidth ) {
+ pageX -= menuWidth;
+ }
+
+ if( (menuHeight + pageY) > winHeight ) {
+ pageY -= menuHeight;
+
+ if( pageY < 0 ) {
+ pageY = e.pageY;
+ }
+ }
+
+ contextMenu.css({
+ left: pageX,
+ top: pageY
+ });
+
+ return false;
+ });
+
+ contextMenu.on("click", "a", function () {
+ contextMenu.hide();
+ });
+
+ $(document).click(function () {
+ contextMenu.hide();
+ });
+ }
+ };
+})
+
.directive('ngDate', function($filter) {
return {
restrict: 'A',
@@ -31,76 +97,41 @@
ctrl.$setViewValue(this.value);
scope.$apply();
ctrl.$setValidity('foo', false);
+ //console.log('it is invalid');
}
else{
scope.invalidDate = false;
ctrl.$setViewValue(this.value);
scope.$apply();
ctrl.$setValidity('foo', true);
+ //console.log('it is valid');
}
});
}
};
})
+.directive('blurOrChange', function() {
+
+ return function( scope, elem, attrs) {
+ elem.datepicker({
+ onSelect: function() {
+ scope.$apply(attrs.blurOrChange);
+ $(this).change();
+ }
+ }).change(function() {
+ scope.$apply(attrs.blurOrChange);
+ });
+ };
+})
+
.directive('paginator', function factory() {
return {
restrict: 'E',
controller: function ($scope, Paginator) {
$scope.paginator = Paginator;
},
- templateUrl: 'views/pagination.html'
- };
-})
-
-.directive('dhisContextMenu', ['ContextMenuSelectedItem', function(ContextMenuSelectedItem) {
-
- return {
- restrict: 'A',
- link: function(scope, element, attrs){
- var contextMenu = $("#contextMenu");
-
- element.click(function (e) {
- var selectedItem = $.parseJSON(attrs.selectedItem);
- ContextMenuSelectedItem.setSelectedItem(selectedItem);
-
- var menuHeight = contextMenu.height();
- var menuWidth = contextMenu.width();
- var winHeight = $(window).height();
- var winWidth = $(window).width();
-
- var pageX = e.pageX;
- var pageY = e.pageY;
-
- contextMenu.show();
-
- if( (menuWidth + pageX) > winWidth ) {
- pageX -= menuWidth;
- }
-
- if( (menuHeight + pageY) > winHeight ) {
- pageY -= menuHeight;
-
- if( pageY < 0 ) {
- pageY = e.pageY;
- }
- }
-
- contextMenu.css({
- left: pageX,
- top: pageY
- });
-
- return false;
- });
-
- contextMenu.on("click", "a", function () {
- contextMenu.hide();
- });
-
- $(document).click(function () {
- contextMenu.hide();
- });
- }
- };
-}]);
\ No newline at end of file
+ templateUrl: 'views/pagination.html'
+ };
+});
+
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/services.js 2014-02-17 10:22:59 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/scripts/services.js 2014-02-20 11:41:24 +0000
@@ -586,6 +586,13 @@
return response.data;
});
return promise;
+ },
+
+ updateSingleValue: function(dhis2Event){
+ var promise = $http.put(dhis2Url + '/api/events/' + dhis2Event.event + '/' + dhis2Event.dataValues[0].dataElement, dhis2Event ).then(function(response){
+ return response.data;
+ });
+ return promise;
}
};
})
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/styles/style.css'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/styles/style.css 2014-02-18 09:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/app/styles/style.css 2014-02-20 11:41:24 +0000
@@ -692,6 +692,14 @@
cursor: default;
}
+.input-error {
+ background-color: #ff6600;
+}
+
+.input-success {
+ background-color: #b9ffb9;
+}
+
.red {
color: red;
}
@@ -718,6 +726,15 @@
float: left;
}
+.bordered-div
+{
+ border: 1px solid #c2c2c2;
+ border-radius: 10px;
+ padding: 5px 10px;
+ margin-bottom: 20px;
+}
+
+
.nav, .pagination, .carousel, .panel-title a { cursor: pointer; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button {
|