dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29483
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14904: made event update holistic instead of individual data value
------------------------------------------------------------
revno: 14904
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Fri 2014-04-18 19:56:57 +0200
message:
made event update holistic instead of individual data value
modified:
dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html
dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js
dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-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-event-capture/src/main/webapp/dhis-web-event-capture/index.html'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html 2014-04-18 15:13:09 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html 2014-04-18 17:56:57 +0000
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html manifest="event-capture.appcache" ng-app="eventCapture">
+<html manifest="event-capture.appcache" ng-app="eventCapture">
<head>
<title>Event Capture</title>
@@ -402,7 +402,7 @@
<!-- event grid ends -->
<!-- event update in full begins-->
- <form name="outerForm" novalidate>
+ <form name="outerFormUpdate" novalidate>
<div ng-if="editingEventInFull">
<h2>
{{'update_event'| translate}}
@@ -429,79 +429,59 @@
<div ng-switch="eventGridColumn.type">
<div ng-switch-when="int">
<input type="number"
- ng-model="currentEvent[eventGridColumn.id]"
- ng-blur="updateEventDataValue(currentEvent, eventGridColumn.id)"
+ ng-model="currentEvent[eventGridColumn.id]"
ng-required={{eventGridColumn.compulsory}}
name="foo"
- style="width:99%;"
- ng-class="{true: 'update-success'} [currentElement.updated === true && (currentElement.id === eventGridColumn.id)]"
- ng-class="{true: 'update-error'} [currentElement.updated === false && (currentElement.id === eventGridColumn.id)]"
- />
- <span ng-show="currentElement.updated === false && (currentElement.id === eventGridColumn.id)" class="required">{{'required'| translate}}</span>
-
+ style="width:99%;"/>
+ <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
</div>
<div ng-switch-when="string">
<div class="container-fluid">
<input type="text"
- ng-model="currentEvent[eventGridColumn.id]"
- ng-blur="updateEventDataValue(currentEvent, eventGridColumn.id)"
+ ng-model="currentEvent[eventGridColumn.id]"
typeahead="option for option in programStageDataElements[eventGridColumn.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20"
typeahead-open-on-focus
ng-required={{eventGridColumn.compulsory}}
name="foo"
- style="width:99%;"
- ng-class="{true: 'update-success'} [currentElement.updated === true && (currentElement.id === eventGridColumn.id)]"
- ng-class="{true: 'update-error'} [currentElement.updated === false && (currentElement.id === eventGridColumn.id)]"
- />
- <span ng-show="currentElement.updated === false && (currentElement.id === eventGridColumn.id)" class="required">{{'required'| translate}}</span>
+ style="width:99%;"/>
+ <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
</div>
</div>
<div ng-switch-when="bool">
- <select ng-model="currentEvent[eventGridColumn.id]"
- ng-change="updateEventDataValue(currentEvent, eventGridColumn.id)"
+ <select ng-model="currentEvent[eventGridColumn.id]"
ng-required={{eventGridColumn.compulsory}}
name="foo"
- style="width:99%;"
- ng-class="{true: 'update-success'} [currentElement.updated === true && (currentElement.id === eventGridColumn.id)]"
- ng-class="{true: 'update-error'} [currentElement.updated === false && (currentElement.id === eventGridColumn.id)]"
- />
+ style="width:99%;"/>
<option value="">{{'please_select'| translate}}</option>
<option value="0">{{'no'| translate}}</option>
<option value="1">{{'yes'| translate}}</option>
</select>
- <span ng-show="currentElement.updated === false && (currentElement.id === eventGridColumn.id)" class="required">{{'required'| translate}}</span>
+ <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
</div>
<div ng-switch-when="date">
<input type="text"
placeholder="yyyy-mm-dd"
ng-date
- ng-model="currentEvent[eventGridColumn.id]"
- blur-or-change="updateEventDataValue(currentEvent, eventGridColumn.id)"
+ ng-model="currentEvent[eventGridColumn.id]"
ng-required={{eventGridColumn.compulsory}}
name="foo"
- style="width:99%;"
-
- ng-class="{true: 'update-error'} [currentElement.updated === false && (currentElement.id === eventGridColumn.id)]"
- />
- <span ng-show="currentElement.updated === false && (currentElement.id === eventGridColumn.id)" class="required">{{'required'| translate}}</span>
+ style="width:99%;"/>
+ <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
</div>
<div ng-switch-when="trueOnly">
<input type="checkbox"
- ng-model="currentEvent[eventGridColumn.id]"
- ng-change="updateEventDataValue(currentEvent, eventGridColumn.id)"
+ ng-model="currentEvent[eventGridColumn.id]"
ng-required={{eventGridColumn.compulsory}}
- name="foo"
- ng-class="{true: 'update-success'} [currentElement.updated === true && (currentElement.id === eventGridColumn.id)]"
- ng-class="{true: 'update-error'} [currentElement.updated === false && (currentElement.id === eventGridColumn.id)]"
- />
- <span ng-show="currentElement.updated === false && (currentElement.id === eventGridColumn.id)" class="required">{{'required'| translate}}</span>
+ name="foo"/>
+ <span ng-show="outerFormUpdate.submitted && innerFormUpdate.foo.$invalid" class="required">{{'required'| translate}}</span>
</div>
</div>
</ng-form>
</td>
</tr>
</tbody>
- </table>
+ </table>
+ <button ng-click="updateEvent()" class="button">{{'update'| translate}}</button>
<button ng-click="showEventList()" class="button">{{'go_back'| translate}}</button>
</div>
</div>
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js 2014-04-02 13:20:51 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js 2014-04-18 17:56:57 +0000
@@ -371,6 +371,52 @@
}
});
};
+
+ $scope.updateEvent = function(){
+
+ //check for form validity
+ $scope.outerFormUpdate.submitted = true;
+ if( $scope.outerFormUpdate.$invalid ){
+ return false;
+ }
+
+ //the form is valid, get the values
+ var dataValues = [];
+ for(var dataElement in $scope.programStageDataElements){
+ dataValues.push({dataElement: dataElement, value: $scope.currentEvent[dataElement]});
+ }
+
+ var updatedEvent = {
+ program: $scope.currentEvent.program,
+ programStage: $scope.currentEvent.programStage,
+ orgUnit: $scope.currentEvent.orgUnit,
+ status: 'ACTIVE',
+ eventDate: $scope.currentEvent.eventDate,
+ event: $scope.currentEvent.event,
+ dataValues: dataValues
+ };
+
+ updatedEvent.eventDate = moment(updatedEvent.eventDate, 'YYYY-MM-DD')._d;
+ updatedEvent.eventDate = Date.parse(updatedEvent.eventDate);
+ updatedEvent.eventDate = $filter('date')(updatedEvent.eventDate, 'yyyy-MM-dd');
+
+ DHIS2EventFactory.update(updatedEvent).then(function(data){
+
+ //update original value
+ var continueLoop = true;
+ for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){
+ if($scope.dhis2Events[i].event === $scope.currentEvent.event ){
+ $scope.dhis2Events[i] = $scope.currentEvent;
+ continueLoop = false;
+ }
+ }
+
+ $scope.currentEventOrginialValue = angular.copy($scope.currentEvent);
+ $scope.outerFormUpdate.submitted = false;
+ $scope.editingEventInFull = false;
+ $scope.currentEvent = {};
+ });
+ };
$scope.updateEventDataValue = function(currentEvent, dataElement){
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2014-03-26 10:34:25 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js 2014-04-18 17:56:57 +0000
@@ -282,16 +282,13 @@
_.each( _.values( events ), function( event ) {
- if( event.hasOwnProperty('src')){
- if( event.src == 'local'){
- delete event.event;
- }
-
- delete event.src;
- }
+ if( event.hasOwnProperty('src')){
+ delete event.src;
+ }
+ delete event.event;
});
- events = {eventList: events};
+ events = {events: events};
//jackson insists for valid json, where properties are bounded with ""
events = JSON.stringify(events);
@@ -470,7 +467,8 @@
}
}
- return match;
+ var pager = {pageSize: 50, page: 1, toolBarDisplay: 5, pageCount: 1};
+ return {events: match, pager: pager};
};
/**
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js 2014-03-26 22:33:08 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/services.js 2014-04-18 17:56:57 +0000
@@ -93,7 +93,7 @@
var promise = $http.get( url ).then(function(response){
return response.data;
- }, function(){
+ }, function(){
return dhis2.ec.storageManager.getEvents(orgUnit, programStage);
});
@@ -136,6 +136,7 @@
var promise = $http.put('../api/events/' + dhis2Event.event, dhis2Event).then(function(response){
dhis2.ec.storageManager.clearEvent(dhis2Event);
return response.data;
+ }, function(){
});
return promise;
},