← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21551: event-capture: file upload/download for custom forms

 

------------------------------------------------------------
revno: 21551
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-30 13:59:32 +0100
message:
  event-capture: file upload/download for custom forms
modified:
  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/directives.js
  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/views/defaultForm.html
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.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-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-12-21 16:42:10 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-12-30 12:59:32 +0000
@@ -135,6 +135,7 @@
         
         $scope.resetOu = false;
         $scope.selectedProgramStage = null;
+        $scope.currentStage = null;
         $scope.allProgramRules = [];
         $scope.dhis2Events = [];
         $scope.currentEvent = {};
@@ -181,8 +182,8 @@
             //because this is single event, take the first program stage
             
             $scope.selectedProgramStage = $scope.selectedProgram.programStages[0];   
+            $scope.currentStage = $scope.selectedProgramStage;
             
-
                 angular.forEach($scope.selectedProgramStage.programStageSections, function(section){
                     section.open = true;
                 });
@@ -515,7 +516,7 @@
     };
     
     $scope.showEventRegistration = function(){        
-        $scope.displayCustomForm = $scope.customForm ? true:false;
+        $scope.displayCustomForm = $scope.customForm ? true : false;
         $scope.currentEvent = {};
         $scope.eventRegistration = !$scope.eventRegistration;          
         $scope.currentEvent = angular.copy($scope.newDhis2Event);        
@@ -1145,7 +1146,19 @@
         return '';        
     };
     
-    $scope.downloadFile = function(eventUid, dataElementUid, e) {        
+    $scope.downloadFile = function(eventUid, dataElementUid, e) {
+        eventUid = eventUid ? eventUid : $scope.currentEvent.event ? $scope.currentEvent.event : null;        
+        if( !eventUid || !dataElementUid){
+            
+            var dialogOptions = {
+                headerText: 'error',
+                bodyText: 'missing_file_identifier'
+            };
+
+            DialogService.showDialog({}, dialogOptions);
+            return;
+        }
+        
         $window.open('../api/events/files?eventUid=' + eventUid +'&dataElementUid=' + dataElementUid, '_blank', '');
         if(e){
             e.stopPropagation();
@@ -1154,6 +1167,16 @@
     };
     
     $scope.deleteFile = function(dataElement){
+        
+        if( !dataElement ){            
+            var dialogOptions = {
+                headerText: 'error',
+                bodyText: 'missing_file_identifier'
+            };
+            DialogService.showDialog({}, dialogOptions);
+            return;
+        }
+        
         var modalOptions = {
             closeButtonText: 'cancel',
             actionButtonText: 'remove',

=== 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-12-03 11:30:42 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2015-12-30 12:59:32 +0000
@@ -23,7 +23,7 @@
             
             var updateModel = function () {
                 
-                var update = attrs.d2FileInputInstant;
+                var update = scope.d2FileInput.eventDate ? true : false;
                 
                 FileService.upload(element[0].files[0]).then(function(data){
                     
@@ -31,7 +31,7 @@
                                             
                         scope.d2FileInput[de] = data.response.fileResource.id;   
                         scope.d2FileInputCurrentName[de] = data.response.fileResource.name;
-                        if( update === 'true' ){                            
+                        if( update ){                            
                             if(!scope.d2FileInputName[scope.d2FileInput.event]){
                                 scope.d2FileInputName[scope.d2FileInput.event] = [];
                             }                            

=== 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-12-23 08:56:16 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2015-12-30 12:59:32 +0000
@@ -603,6 +603,9 @@
             return e;
         },
         refreshList: function(eventList, currentEvent){
+            if(!eventList || !eventList.length){
+                return;
+            }
             var continueLoop = true;
             for(var i=0; i< eventList.length && continueLoop; i++){
                 if(eventList[i].event === currentEvent.event ){

=== 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-12-14 10:14:55 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2015-12-30 12:59:32 +0000
@@ -226,7 +226,7 @@
                                                        ng-disabled="assignedFields[eventGridColumn.id]"
                                                        name="foo"
                                                        input-field-id={{eventGridColumn.id}}
-                                                       d2-file-input-instant="false"
+                                                       d2-file-input-ps="currentStage"
                                                        d2-file-input="currentEvent" 
                                                        d2-file-input-current-name="currentFileNames"
                                                        d2-file-input-name="fileNames">
@@ -498,7 +498,7 @@
                                                            ng-disabled="assignedFields[de.dataElement.id]"
                                                            name="foo"
                                                            input-field-id={{de.dataElement.id}}
-                                                           d2-file-input-instant="false"
+                                                           d2-file-input-ps="currentStage"
                                                            d2-file-input="currentEvent" 
                                                            d2-file-input-current-name="currentFileNames"
                                                            d2-file-input-name="fileNames">

=== 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-30 02:55:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-12-30 12:59:32 +0000
@@ -442,10 +442,34 @@
                                                 commonInputFieldProperty + ' ></span><span class="not-for-screen"><input type="checkbox" ng-checked={{currentEvent.' + fieldId + '}}></span>';
                                     }
                                     else if (prStDe.dataElement.valueType === "LONG_TEXT") {
-                                        newInputField = '<textarea row="3" ' +
+                                        newInputField = '<span class="hideInPrint"><textarea row="3" ' +
                                                 ' ng-class="{{getInputNotifcationClass(prStDes.' + fieldId + '.dataElement.id, true)}}" ' +
                                                 ' ng-blur="saveDatavalue(prStDes.' + fieldId + ', outerForm.' + fieldId + ')"' +
-                                                commonInputFieldProperty + '></textarea></span><span class="not-for-screen"><textarea row="3" value={{currentEvent.' + fieldId + '}}></span>';
+                                                commonInputFieldProperty + '></textarea></span><span class="not-for-screen"><textarea row="3" value={{currentEvent.' + fieldId + '}}></textarea></span>';
+                                    }
+                                    else if (prStDe.dataElement.valueType === "FILE_RESOURCE") {
+                                        newInputField = '<span class="input-group">\n\
+                                                            <span ng-if="currentEvent.' + fieldId + '">\n\
+                                                                <a href ng-click="downloadFile(null, \'' + fieldId + '\', null)">{{fileNames[currentEvent.event][' + fieldId + ']}}</a>\n\
+                                                            </span>\n\
+                                                            <span class="input-group-btn">\n\
+                                                                <span class="btn btn-primary btn-file">\n\
+                                                                    <span ng-if="currentEvent.' + fieldId + '" title="{{\'delete\' | translate}}" d2-file-input-name="fileNames[currentEvent.event][' + fieldId + ']" d2-file-input-delete="currentEvent.' + fieldId + '">\n\
+                                                                        <a href ng-click="deleteFile(\'' + fieldId + '\')"><i class="fa fa-trash alert-danger"></i></a>\n\
+                                                                    </span>\n\
+                                                                    <span ng-if="!currentEvent.' + fieldId + '" title="{{\'upload\' | translate}}" >\n\
+                                                                        <i class="fa fa-upload"></i>\n\
+                                                                        <input  type="file" \n\
+                                                                                ' + this.getAttributesAsString(attributes) + '\n\
+                                                                                input-field-id="' + fieldId + '"\n\
+                                                                                d2-file-input-ps="currentStage"\n\
+                                                                                d2-file-input="currentEvent"\n\
+                                                                                d2-file-input-current-name="currentFileNames"\n\
+                                                                                d2-file-input-name="fileNames">\n\
+                                                                    </span>\n\
+                                                                </span>\n\
+                                                            </span>\n\
+                                                        </span>';
                                     }
                                     else {
                                         newInputField = '<span class="hideInPrint"><input type="text" ' +