=== 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-12-28 14:53:48 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js 2015-12-30 02:55:18 +0000 @@ -42,7 +42,7 @@ $scope.eventPeriods = []; $scope.currentPeriod = []; $scope.filterEvents = true; - $scope.showEventsAsTables = true; + $scope.showEventsAsTables = false; //variable is set while looping through the program stages later. $scope.stagesCanBeShownAsTable = false; $scope.showHelpText = {}; @@ -51,7 +51,7 @@ $scope.errorMessages = {}; $scope.warningMessages = {}; $scope.hiddenSections = {}; - $scope.tableMaxNumberOfDataElements = 10; + $scope.tableMaxNumberOfDataElements = 7; $scope.xVisitScheduleDataElement = false; @@ -338,7 +338,7 @@ $scope.eventsByStage[stage.id] = []; //If one of the stages has less than $scope.tableMaxNumberOfDataElements data elements, allow sorting as table: - if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) { + if ($scope.stageCanBeShownAsTable(stage)) { $scope.stagesCanBeShownAsTable = true; } }); @@ -434,24 +434,29 @@ }; $scope.stageCanBeShownAsTable = function (stage) { - if (stage.programStageDataElements && stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) { + if (stage.programStageDataElements + && stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements + && !stage.repeatable) { return true; } return false; }; - $scope.toggleEventsTableDisplay = function () { - + $scope.toggleEventsTableDisplay = function () { $scope.showEventsAsTables = !$scope.showEventsAsTables; + + $scope.setDisplayTypeForStages(); + - angular.forEach($scope.programStages, function (stage) { - if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) { - stage.displayEventsInTable = $scope.showEventsAsTables; - if ($scope.currentStage === stage) { - $scope.getDataEntryForm(); - } + if ($scope.currentStage && $scope.stageCanBeShownAsTable($scope.currentStage)) { + //If the current event was deselected, select the first event in the current Stage before showing data entry: + if(!$scope.currentEvent.event + && $scope.eventsByStage[$scope.currentStage.id]) { + $scope.currentEvent = $scope.eventsByStage[$scope.currentStage.id][0]; } - }); + + $scope.getDataEntryForm(); + } }; $scope.setDisplayTypeForStages = function(){ @@ -461,7 +466,7 @@ }; $scope.setDisplayTypeForStage = function(stage){ - if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) { + if ($scope.stageCanBeShownAsTable(stage)) { stage.displayEventsInTable = $scope.showEventsAsTables; } }; @@ -597,15 +602,15 @@ $scope.addNewEvent(newEvent); $scope.currentEvent = null; - $scope.showDataEntry(newEvent, false); + $scope.showDataEntry(newEvent, true); } }, function () { }); }; - $scope.showDataEntry = function (event, rightAfterEnrollment) { + $scope.showDataEntry = function (event, suppressToggling) { if (event) { - if ($scope.currentEvent && !rightAfterEnrollment && $scope.currentEvent.event === event.event) { + if ($scope.currentEvent && !suppressToggling && $scope.currentEvent.event === event.event) { //clicked on the same stage, do toggling $scope.currentStage = null; $scope.currentEvent = null; @@ -713,14 +718,14 @@ $scope.switchToEventRowDeselected = function(event){ if($scope.currentEvent !== event) { - $scope.showDataEntry(event,false); + $scope.showDataEntry(event,true); } $scope.currentEvent = {}; }; $scope.switchToEventRow = function (event) { if($scope.currentEvent !== event) { - $scope.showDataEntry(event,false); + $scope.showDataEntry(event,true); } }; === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html 2015-12-28 14:53:48 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html 2015-12-30 02:55:18 +0000 @@ -8,6 +8,7 @@ + @@ -40,7 +41,7 @@
{{notEnrolledLabel}}
- +
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js 2015-12-21 13:28:07 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js 2015-12-30 02:55:18 +0000 @@ -5,7 +5,6 @@ $scope.completeIncompleteEventModal = function(){ $scope.requestError = ""; - debugger; if ($scope.currentEvent.status === 'COMPLETED'){ var dhis2Event = $scope.makeDhis2EventToUpdate(); dhis2Event.status = 'ACTIVE'; === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js 2015-12-28 14:53:48 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js 2015-12-30 02:55:18 +0000 @@ -1196,7 +1196,9 @@ {name:"d2:ceil",parameters:1}, {name:"d2:round",parameters:1}, {name:"d2:hasValue",parameters:1}, - {name:"d2:lastEventDate",parameters:1}]; + {name:"d2:lastEventDate",parameters:1}, + {name:"d2:addControlDigits",parameters:1}, + {name:"d2:checkControlDigits",parameters:1}]; var continueLooping = true; //Safety harness on 10 loops, in case of unanticipated syntax causing unintencontinued looping for(var i = 0; i < 10 && continueLooping; i++ ) { @@ -1468,6 +1470,70 @@ expression = expression.replace(callToThisFunction, valueFound); successfulExecution = true; } + else if(dhisFunction.name === "d2:addControlDigits") { + + var baseNumber = parameters[0]; + var baseDigits = baseNumber.split(''); + var error = false; + + + var firstDigit = 0; + var secondDigit = 0; + + if(baseDigits && baseDigits.length < 10 ) { + var firstSum = 0; + var baseNumberLength = baseDigits.length; + //weights support up to 9 base digits: + var firstWeights = [3,7,6,1,8,9,4,5,2]; + for(var i = 0; i < baseNumberLength && !error; i++) { + firstSum += parseInt(baseDigits[i]) * firstWeights[i]; + } + firstDigit = firstSum % 11; + + //Push the first digit to the array before continuing, as the second digit is a result of the + //base digits and the first control digit. + baseDigits.push(firstDigit); + //Weights support up to 9 base digits plus first control digit: + var secondWeights = [5,4,3,2,7,6,5,4,3,2]; + var secondSum = 0; + for(var i = 0; i < baseNumberLength + 1 && !error; i++) { + secondSum += parseInt(baseDigits[i]) * secondWeights[i]; + } + secondDigit = secondSum % 11; + + if(firstDigit === 10) { + $log.warn("First control digit became 10, replacing with 0"); + firstDigit = 0; + } + if(secondDigit === 10) { + $log.warn("Second control digit became 10, replacing with 0"); + secondDigit = 0; + } + } + else + { + $log.warn("Base nuber not well formed(" + baseNumberLength + " digits): " + baseNumber); + } + + if(!error) { + //Replace the end evaluation of the dhis function: + expression = expression.replace(callToThisFunction, baseNumber + firstDigit + secondDigit); + successfulExecution = true; + } + else + { + //Replace the end evaluation of the dhis function: + expression = expression.replace(callToThisFunction, baseNumber); + successfulExecution = false; + } + } + else if(dhisFunction.name === "d2:checkControlDigits") { + $log.warn("checkControlDigits not implemented yet"); + + //Replace the end evaluation of the dhis function: + expression = expression.replace(callToThisFunction, parameters[0]); + successfulExecution = false; + } }); });