1
+ angular . module ( 'discipline' )
2
+ . controller ( 'disciplinaryNoteController' , function ( $scope , moment , $q , $resource , $state , $stateParams , $mdDialog , toastService , globalService , DisciplineService ) {
3
+
4
+ var vm = this ;
5
+
6
+ // Param url passed to load an existing disciplinary note
7
+ vm . disciplinaryNoteId = $stateParams . disciplinaryNoteId ;
8
+
9
+ console . log ( 'disciplinaryNoteId' )
10
+ console . log ( vm . disciplinaryNoteId )
11
+
12
+ vm . action = null ;
13
+
14
+ if ( vm . associationId )
15
+ vm . action = 'new' ;
16
+ else
17
+ vm . action = 'loaded' ;
18
+ console . log ( vm . action ) ;
19
+
20
+ vm . defaultAvatar = globalService . defaultAvatar ;
21
+
22
+ // Functions:
23
+ vm . changeAssistanceForStudent = changeAssistanceForStudent ;
24
+ vm . changeUniformForStudent = changeUniformForStudent ;
25
+ vm . checkIfDelayIsEnabled = checkIfDelayIsEnabled ;
26
+ vm . checkIfJustifiedDelayIsEnabled = checkIfJustifiedDelayIsEnabled ;
27
+
28
+ // To control the loading spinner.
29
+ vm . dataIsReady = false ;
30
+
31
+ vm . delayList = [ '5' , '10' , '15' , '20' , '30' , '45' ] ;
32
+
33
+ activate ( ) ;
34
+
35
+
36
+ ///////////////////////////////////////////////////////////////////
37
+ function activate ( ) {
38
+ console . log ( 'Activating attendanceControlController controller.' ) ;
39
+
40
+ vm . dn = DisciplineService . get ( { id : vm . disciplinaryNoteId } ,
41
+ function ( ) {
42
+ console . log ( 'Disciplinary Note Data Block received:' ) ;
43
+ console . log ( vm . dn ) ;
44
+ vm . dataIsReady = true ;
45
+
46
+ } , function ( error ) {
47
+ console . log ( 'Get disciplinary note process fail.' ) ;
48
+ console . log ( error ) ;
49
+ toastService . showToast ( 'Error obteniendo el parte disciplinario.' )
50
+ } )
51
+ }
52
+
53
+
54
+ function checkIfDelayIsEnabled ( delayValue ) {
55
+ if ( delayValue == null )
56
+ return false ;
57
+ else
58
+ return true ;
59
+ }
60
+
61
+ function checkIfJustifiedDelayIsEnabled ( delayValue ) {
62
+ if ( delayValue == null )
63
+ return false ;
64
+ else
65
+ return true ;
66
+ }
67
+
68
+
69
+ vm . changeDelay = function changeDelay ( studentId , delay ) {
70
+
71
+ if ( delay == 'Sin retraso' ) {
72
+ delay = 0 ;
73
+ }
74
+ for ( var a = 0 ; a < vm . acBase . students . length ; a ++ ) {
75
+ if ( vm . acBase . students [ a ] . studentId == studentId ) {
76
+ vm . acBase . students [ a ] . control . delay = delay ;
77
+ console . log ( vm . acBase . students [ a ] . control . delay ) ;
78
+ if ( delay != 0 )
79
+ vm . acBase . students [ a ] . control . justifiedDelay = 0 ;
80
+ else
81
+ vm . acBase . students [ a ] . control . justifiedDelay = null ;
82
+ }
83
+ }
84
+ }
85
+
86
+ vm . changeJustifiedDelay = function changeJustifiedDelay ( studentId ) {
87
+ for ( var a = 0 ; a < vm . acBase . students . length ; a ++ ) {
88
+ if ( vm . acBase . students [ a ] . studentId == studentId ) {
89
+ if ( vm . acBase . students [ a ] . control . justifiedDelay == true ) {
90
+ vm . acBase . students [ a ] . control . justifiedDelay = false ;
91
+ } else {
92
+ vm . acBase . students [ a ] . control . justifiedDelay = true ;
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ function changeUniformForStudent ( studentId ) {
99
+ for ( var a = 0 ; a < vm . acBase . students . length ; a ++ ) {
100
+ if ( vm . acBase . students [ a ] . studentId == studentId ) {
101
+ if ( vm . acBase . students [ a ] . control . uniform == true ) {
102
+ vm . acBase . students [ a ] . control . uniform = false ;
103
+ } else {
104
+ vm . acBase . students [ a ] . control . uniform = true ;
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ function changeAssistanceForStudent ( studentId ) {
111
+
112
+ for ( var a = 0 ; a < vm . acBase . students . length ; a ++ ) {
113
+ if ( vm . acBase . students [ a ] . studentId == studentId ) {
114
+ if ( vm . acBase . students [ a ] . control . assistance == true ) {
115
+
116
+ // Set the student to fault.
117
+ vm . acBase . students [ a ] . control . assistance = false ;
118
+ // It changed to null the rest of values:
119
+ vm . acBase . students [ a ] . control . delay = null ;
120
+ vm . acBase . students [ a ] . control . justifiedDelay = false ;
121
+ vm . acBase . students [ a ] . control . uniform = null ;
122
+
123
+ console . log ( vm . acBase . students [ a ] . control ) ;
124
+
125
+
126
+ } else {
127
+ vm . acBase . students [ a ] . control . assistance = true ;
128
+ vm . acBase . students [ a ] . control . delay = 0 ;
129
+ vm . acBase . students [ a ] . control . justifiedDelay = null ;
130
+ vm . acBase . students [ a ] . control . uniform = true ;
131
+ }
132
+ }
133
+ }
134
+
135
+ }
136
+
137
+ vm . saveCA = function saveCA ( ) {
138
+
139
+ console . log ( 'Saving CA' ) ;
140
+ console . log ( vm . acBase ) ;
141
+
142
+ vm . acBase . $save (
143
+ function ( ) { // Success
144
+ console . log ( 'ac saved successfully' ) ;
145
+ $state . go ( 'attendanceControls' ) ;
146
+ toastService . showToast ( 'Control de asistencia realizado con éxito.' ) ;
147
+ } ,
148
+ function ( error ) { // Fail
149
+ toastService . showToast ( 'Error al enviar control de asistencia.' ) ;
150
+ console . log ( 'Error while ac was saved.' ) ;
151
+ console . log ( error ) ;
152
+ } ) ;
153
+ }
154
+
155
+ }
156
+ )
0 commit comments