~dhis2-devs-core/dhis2/greenstar

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js

  • Committer: Harsh Atal
  • Date: 2016-01-21 06:01:39 UTC
  • Revision ID: harsh.atal@gmail.com-20160121060139-s782eribqqj924wa
adding missing files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
trackerCapture.controller('ModalDefaultFormController', function($scope){
 
2
    
 
3
    var defaultRequestError = "Server error. Please try again later.";
 
4
    
 
5
    $scope.completeIncompleteEventModal = function(){  
 
6
           
 
7
        $scope.requestError = "";
 
8
        if ($scope.currentEvent.status === 'COMPLETED'){
 
9
            var dhis2Event = $scope.makeDhis2EventToUpdate();
 
10
            dhis2Event.status = 'ACTIVE';
 
11
        }
 
12
        else{
 
13
            $scope.modalForm.$setSubmitted();
 
14
            $scope.modalForm.outerForm.$setSubmitted();     
 
15
            
 
16
            if($scope.modalForm.$invalid){
 
17
                return;
 
18
            }     
 
19
            
 
20
            //check for errors!
 
21
            if(angular.isDefined($scope.errorMessages[$scope.currentEvent.event]) && $scope.errorMessages[$scope.currentEvent.event].length > 0) {
 
22
                //There is unresolved program rule errors - show error message.
 
23
                return;
 
24
            }
 
25
            
 
26
            var dhis2Event = $scope.makeDhis2EventToUpdate();
 
27
            dhis2Event.status = 'COMPLETED';
 
28
        }        
 
29
        
 
30
        $scope.executeCompleteIncompleteEvent(dhis2Event).then(function(){                                    
 
31
            if(dhis2Event.status === 'COMPLETED'){
 
32
                $scope.eventEditFormModalInstance.close();            
 
33
            }
 
34
        }, function(error){
 
35
            $scope.requestError = defaultRequestError;                                   
 
36
        });
 
37
    };
 
38
    
 
39
    $scope.deleteEventModal = function(){
 
40
        
 
41
        $scope.executeDeleteEvent().then(function(){
 
42
            
 
43
            $scope.eventEditFormModalInstance.close();
 
44
        }, function(){
 
45
            
 
46
            $scope.requestError = defaultRequestError; 
 
47
        });        
 
48
    };
 
49
    
 
50
    $scope.skipUnskipEventModal = function(){
 
51
                
 
52
        var dhis2Event = $scope.makeDhis2EventToUpdate();
 
53
        
 
54
        if ($scope.currentEvent.status === 'SKIPPED') {//unskip event
 
55
            dhis2Event.status = 'ACTIVE';
 
56
        }
 
57
        else {//skip event
 
58
            dhis2Event.status = 'SKIPPED';
 
59
        }
 
60
        
 
61
        
 
62
        $scope.executeSkipUnskipEvent(dhis2Event).then(function(){
 
63
            if(dhis2Event.status === 'SKIPPED'){
 
64
                $scope.eventEditFormModalInstance.close();
 
65
            }
 
66
        }, function(){
 
67
            $scope.requestError = defaultRequestError;
 
68
        });        
 
69
    };
 
70
    
 
71
    $scope.closeEventModal = function(){
 
72
        $scope.eventEditFormModalInstance.dismiss();
 
73
    };
 
74
});
 
 
b'\\ No newline at end of file'