Update Attendance

Daily Wise Subject Wise
Instance URL:
Token:
Student Admission no:
Date:
Update value
Forenoon:
Afternoon:
Reason:
Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Fedena API</title>
        <script src="https://s3.amazonaws.com/api_play/src/js/jquery-2.1.1.min.js"></script>
        <script src="https://s3.amazonaws.com/api_play/src/js/vkbeautify.0.99.00.beta.js"></script>
        <script>
            $(function() {
                $("#update-attendance").click(function() {
                    var fedena_server = $("#fedena_server").val();
                    var token = $("#token").val();
                    var admission_no = $("#admission_no").val();
                    var date = $("#date").val();
                    var reason = $("#reason").val();
                    var result_div = $("#result");
                    var attendance_type = $("input:radio[name=attendance_type]:checked").val();
                    if (attendance_type=="daily")
                    {
                        var forenoon = $("#forenoon").val();
                        var afternoon = $("#afternoon").val();
                        update_day_attendance(fedena_server,token,admission_no,date,forenoon,afternoon,reason,result_div);
                    }
                    else
                    {
                        var subject_code = $("#subject_code").val();
                        var class_timing_name = $("#class_timing_name").val();
                        update_subject_attendance(fedena_server,token,admission_no,date,subject_code,class_timing_name,reason,result_div);
                    }
                });
            });
        </script>
        <script>
            function update_day_attendance(fedena_server,token,admission_no,date,forenoon,afternoon,reason,result_div){
                result_div.html("");
                try
                {
                    var xhr = new XMLHttpRequest();
                    xhr.onreadystatechange = function(evt)
                    {
                        if (xhr.readyState==4)
                        {
                            result_div.html(show_response(evt.target.responseText));
                        }
                    }

                    xhr.open('PUT', fedena_server+"/api/attendances/"+admission_no );
                    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                    xhr.setRequestHeader('Authorization', 'Token token="'+token+'"');
                    xhr.send("date="+date+"&forenoon="+forenoon+"&afternoon="+afternoon+"&reason="+reason);
                }
                catch(err)
                {
                    alert(err.message);
                }
            }

            function update_subject_attendance(fedena_server,token,admission_no,date,subject_code,class_timing_name,reason,result_div){
                result_div.html("");
                try
                {
                    var xhr = new XMLHttpRequest();
                    xhr.onreadystatechange = function(evt)
                    {
                        if (xhr.readyState==4)
                        {
                            result_div.html(show_response(evt.target.responseText));
                        }
                    }

                    xhr.open('PUT', fedena_server+"/api/attendances/"+admission_no);
                    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                    xhr.setRequestHeader('Authorization', 'Token token="'+token+'"');
                    xhr.send("date="+date+"&subject_code="+subject_code+"&class_timing_name="+class_timing_name+"&reason="+reason);
                }
                catch(err)
                {
                    alert(err.message);
                }
            }

            function attendance_type(th_is){
                if (th_is.value=="daily")
                {
                    $(".subject_wise").hide();
                    $(".day_wise").show();
                }
                else
                {
                    $(".day_wise").hide();
                    $(".subject_wise").show();
                }
            }
            function show_response(str){
                str = vkbeautify.xml(str,4); /* Optional, To format the XML output*/
                return str.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g,"<br />");
            }
        </script>
    </head>
    <body>
        <h3> Update Attendance </h3>
        <div>
            <table>
                <tr>
                    <td colspan="2">
                        <input type="radio" name="attendance_type" value="daily" checked="checked" onchange="attendance_type(this)" /> Daily Wise
                        <input type="radio" name="attendance_type" value="subject" onchange="attendance_type(this)" /> Subject Wise
                    </td>
                </tr>
                <tr>
                    <td>
                        Instance URL:
                    </td>
                    <td>
                        <input id="fedena_server" type="text" placeholder="ex: http://myschoolsis.com"  />
                    </td>
                </tr>
                <tr>
                    <td>
                        Token:
                    </td>
                    <td>
                        <input id="token" type="text"  />
                    </td>
                </tr>
                <tr>
                    <td>
                        Student Admission no:
                    </td>
                    <td>
                        <input id="admission_no" type="text" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Date:
                    </td>
                    <td>
                        <input id="date" type="text" placeholder="yyyy-mm-dd" />
                    </td>
                </tr>
                <tr class="subject_wise" style="display: none;">
                    <td>
                        Subject Code:
                    </td>
                    <td>
                        <input id="subject_code" type="text" />
                    </td>
                </tr>
                <tr class="subject_wise" style="display: none;">
                    <td>
                        Class Timing Name:
                    </td>
                    <td>
                        <input id="class_timing_name" type="text" />
                    </td>
                </tr>
                <tr><td colspan="2"><u>Update value</u></td></tr>
                <tr class="day_wise">
                    <td>
                        Forenoon:
                    </td>
                    <td>
                        <select id="forenoon">
                            <option value="1">Yes</option>
                            <option value="0">No</option>
                        </select>
                    </td>
                </tr>
                <tr class="day_wise">
                    <td>
                        Afternoon:
                    </td>
                    <td>
                        <select id="afternoon">
                            <option value="1">Yes</option>
                            <option value="0">No</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        Reason:
                    </td>
                    <td>
                        <input id="reason" type="text" />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button type="button" id="update-attendance" value="Update Attendance">Update Attendance</button>
                    </td>
                </tr>
            </table>
            <pre> <code id="result" style="text-align: left; float: left;"></code></pre>
        </div>
    </body>
</html>
loading..