=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties 2015-11-26 16:57:49 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/i18n_app.properties 2015-12-01 14:01:37 +0000 @@ -25,6 +25,7 @@ save_and_back=Save and go back upload=Upload delete=Delete +delete_file=Delete file cancel=Cancel close=Close discard=Discard === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js 2015-11-23 09:52:35 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js 2015-12-01 14:01:37 +0000 @@ -65,6 +65,7 @@ $scope.proceedSelection = true; $scope.formUnsaved = false; $scope.fileNames = []; + $scope.currentFileNames = []; //notes $scope.note = {}; @@ -139,6 +140,7 @@ $scope.currentEvent = {}; $scope.currentEventOriginialValue = {}; $scope.fileNames = []; + $scope.currentFileNames = []; $scope.eventRegistration = false; $scope.editGridColumns = false; @@ -354,13 +356,10 @@ if($scope.prStDes[dataValue.dataElement].dataElement.valueType === 'FILE_RESOURCE'){ FileService.get(val).then(function(response){ if(response && response.name){ - if($scope.fileNames[event.event]){ - $scope.fileNames[event.event][dataValue.dataElement] = response.name; + if(!$scope.fileNames[event.event]){ + $scope.fileNames[event.event] = []; } - else{ - $scope.fileNames[event.event] = []; - $scope.fileNames[event.event][dataValue.dataElement] = response.name; - } + $scope.fileNames[event.event][dataValue.dataElement] = response.name; } }); } @@ -673,7 +672,11 @@ else { //add the new event to the grid - newEvent.event = data.response.importSummaries[0].reference; + newEvent.event = data.response.importSummaries[0].reference; + $scope.currentEvent.event = newEvent.event; + + $scope.updateFileNames(); + if( !$scope.dhis2Events ){ $scope.dhis2Events = []; } @@ -758,9 +761,9 @@ } DHIS2EventFactory.update(updatedEvent).then(function(data){ - //reflect the change in the gird - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); + $scope.updateFileNames(); $scope.outerForm.submitted = false; $scope.editingEventInFull = false; $scope.currentEvent = {}; @@ -782,7 +785,7 @@ if (!rawDate || !convertedDate || rawDate !== convertedDate) { $scope.invalidDate = true; $scope.currentEvent.eventDate = $scope.currentEventOriginialValue.eventDate; - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); $scope.currentElement.updated = false; return; } @@ -793,7 +796,7 @@ if ($scope.currentEvent.eventDate === '') { $scope.currentEvent.eventDate = oldValue; - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); $scope.currentElement.updated = false; return; } @@ -808,7 +811,7 @@ DHIS2EventFactory.updateForEventDate(e, updatedFullValueEvent).then(function () { //reflect the new value in the grid - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); //update original value $scope.currentEventOriginialValue = angular.copy($scope.currentEvent); @@ -837,7 +840,7 @@ $scope.currentElement.updated = false; //reset value back to original $scope.currentEvent[dataElement] = oldValue; - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); return; } @@ -845,7 +848,7 @@ $scope.currentElement.updated = false; //reset value back to original $scope.currentEvent[dataElement] = oldValue; - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); return; } @@ -857,7 +860,7 @@ DHIS2EventFactory.updateForSingleValue(updatedSingleValueEvent, updatedFullValueEvent).then(function(data){ //reflect the new value in the grid - $scope.resetEventValue($scope.currentEvent); + $scope.dhis2Events = DHIS2EventService.refreshList($scope.dhis2Events, $scope.currentEvent); //update original value $scope.currentEventOriginialValue = angular.copy($scope.currentEvent); @@ -868,16 +871,6 @@ } }; - $scope.resetEventValue = function(){ - 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.removeEvent = function(){ var dhis2Event = ContextMenuSelectedItem.getSelectedItem(); @@ -893,6 +886,8 @@ DHIS2EventFactory.delete(dhis2Event).then(function(data){ + $scope.currentFileNames = []; + delete $scope.fileNames[$scope.currentEvent.event]; var continueLoop = true, index = -1; for(var i=0; i< $scope.dhis2Events.length && continueLoop; i++){ if($scope.dhis2Events[i].event === dhis2Event.event ){ @@ -1162,4 +1157,30 @@ e.preventDefault(); } }; + + $scope.deleteFile = function(dataElement){ + var modalOptions = { + closeButtonText: 'cancel', + actionButtonText: 'remove', + headerText: 'remove', + bodyText: 'are_you_sure_to_remove' + }; + + ModalService.showModal({}, modalOptions).then(function(result){ + $scope.fileNames[$scope.currentEvent.event][dataElement] = null; + $scope.currentEvent[dataElement] = null; + $scope.updateEventDataValue($scope.currentEvent, dataElement); + }); + }; + + $scope.updateFileNames = function(){ + for(var dataElement in $scope.currentFileNames){ + if($scope.currentFileNames[dataElement]){ + if(!$scope.fileNames[$scope.currentEvent.event]){ + $scope.fileNames[$scope.currentEvent.event] = []; + } + $scope.fileNames[$scope.currentEvent.event][dataElement] = $scope.currentFileNames[dataElement]; + } + } + }; }); \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js 2015-11-16 15:48:46 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js 2015-12-01 14:01:37 +0000 @@ -33,34 +33,43 @@ }; }) -.directive('d2FileInputField', function () { - - return { - restrict: 'E', - templateUrl: 'views/file-input.html', - link: function (scope, element, attrs) {} - }; -}) - -.directive('d2FileInput', function($parse, $timeout, FileService, DialogService){ +.directive('d2FileInput', function(DHIS2EventService, DHIS2EventFactory, FileService, DialogService){ return { restrict: "A", - link: function (scope, element, attrs) { - var modelGetter = $parse(attrs.d2FileInput); - var modelSetter = modelGetter.assign; - - var nameGetter = $parse(attrs.d2FileInputName); - var nameSetter = nameGetter.assign; - + scope: { + d2FileInputList: '=', + d2FileInput: '=', + d2FileInputName: '=', + d2FileInputCurrentName: '=', + d2FileInputPs: '=' + }, + link: function (scope, element, attrs) { + + var de = attrs.inputFieldId; + var updateModel = function () { + + var update = attrs.d2FileInputInstant; + FileService.upload(element[0].files[0]).then(function(data){ - if(data && data.status === 'OK' && data.response && data.response.fileResource && data.response.fileResource.id){ - $timeout(function(){ - modelSetter(scope, data.response.fileResource.id); - nameSetter(scope, element[0].files[0].name); - scope.$apply(); - }); + + if(data && data.status === 'OK' && data.response && data.response.fileResource && data.response.fileResource.id && data.response.fileResource.name){ + + scope.d2FileInput[de] = data.response.fileResource.id; + scope.d2FileInputCurrentName[de] = data.response.fileResource.name; + if( update === 'true' ){ + if(!scope.d2FileInputName[scope.d2FileInput.event]){ + scope.d2FileInputName[scope.d2FileInput.event] = []; + } + scope.d2FileInputName[scope.d2FileInput.event][de] = data.response.fileResource.name; + + var updatedSingleValueEvent = {event: scope.d2FileInput.event, dataValues: [{value: data.response.fileResource.id, dataElement: de}]}; + var updatedFullValueEvent = DHIS2EventService.reconstructEvent(scope.d2FileInput, scope.d2FileInputPs.programStageDataElements); + DHIS2EventFactory.updateForSingleValue(updatedSingleValueEvent, updatedFullValueEvent).then(function(data){ + scope.d2FileInputList = DHIS2EventService.refreshList(scope.d2FileInputList, scope.d2FileInput); + }); + } } else{ var dialogOptions = { @@ -77,18 +86,17 @@ }; }) -.directive('d2FileInputDelete', function($parse, $timeout, ModalService, FileService, DialogService){ +.directive('d2FileInputDelete', function($parse, $timeout, FileService, DialogService){ return { restrict: "A", link: function (scope, element, attrs) { - var modelGetter = $parse(attrs.d2FileInputDelete); - var modelSetter = modelGetter.assign; + var valueGetter = $parse(attrs.d2FileInputDelete); var nameGetter = $parse(attrs.d2FileInputName); var nameSetter = nameGetter.assign; - if(modelGetter(scope)) { - FileService.get(modelGetter(scope)).then(function(data){ + if(valueGetter(scope)) { + FileService.get(valueGetter(scope)).then(function(data){ if(data && data.name && data.id){ $timeout(function(){ nameSetter(scope, data.name); @@ -103,26 +111,7 @@ DialogService.showDialog({}, dialogOptions); } }); - } - - var deleteFile = function () { - var modalOptions = { - closeButtonText: 'cancel', - actionButtonText: 'remove', - headerText: 'remove', - bodyText: 'are_you_sure_to_remove' - }; - - ModalService.showModal({}, modalOptions).then(function(result){ - $timeout(function(){ - modelSetter(scope, ''); - nameSetter(scope, ''); - scope.$apply(); - }); - }); - }; - - element.bind('click', deleteFile); + } } }; }); === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js 2015-11-17 15:28:34 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js 2015-12-01 14:01:37 +0000 @@ -27,6 +27,12 @@ }); return promise; }, + delete: function (uid) { + var promise = $http.get('../api/fileResources/' + uid).then(function (response) { + return response.data; + }); + return promise; + }, download: function (fileName) { var promise = $http.get(fileName).then(function (response) { return response.data; @@ -595,6 +601,16 @@ } return e; - } + }, + refreshList: function(eventList, currentEvent){ + var continueLoop = true; + for(var i=0; i< eventList.length && continueLoop; i++){ + if(eventList[i].event === currentEvent.event ){ + eventList[i] = currentEvent; + continueLoop = false; + } + } + return eventList; + } }; }); === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html 2015-11-25 10:41:52 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html 2015-12-01 14:01:37 +0000 @@ -209,12 +209,15 @@
- - + + @@ -223,8 +226,10 @@ ng-disabled="assignedFields[eventGridColumn.id]" name="foo" input-field-id={{eventGridColumn.id}} - d2-file-input="currentEvent[eventGridColumn.id]" - d2-file-input-name="fileNames[eventGridColumn.id]"> + d2-file-input-instant="false" + d2-file-input="currentEvent" + d2-file-input-current-name="currentFileNames" + d2-file-input-name="fileNames"> @@ -247,12 +252,12 @@ - + +
-