This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobileupload.html
223 lines (196 loc) · 6.48 KB
/
mobileupload.html
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!doctype html>
<html lang = "en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>examcopedia - one stop, many exams</title>
<!-- JQ and BS delivered by CDN -->
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!--
<script src="/socket.io/socket.io.js"></script>
<script src = "include/jquery.sha256.min.js"></script>
<script src = "include/cropper.min.js"></script>
<link rel = "stylesheet" href = "include/cropper.min.css">
-->
<script>
function info_modal(i){
$('#id_mobileupload_modal_warning .modal-body').html(i);
$('#id_mobileupload_modal_warning').modal('show');
}
function sendImg(){
//var sendImg = $('#id_mobileupload_canvas_cropbody').cropper('getData');
var formData = new FormData();
formData.append('hashedid',$('#id_mobileupload_input_hashedid').val());
formData.append('photo',$('#id_mobileupload_input_file')[0].files[0]);
/*
if(i=='uncropped'){
formData.append('photo',$('#id_mobileupload_input_file')[0].files[0]);
}else if(i=='cropped'){
var imgsrc = $('#id_mobileupload_canvas_cropbody').cropper('getCroppedCanvas').toDataURL('image/jpeg');
var imgname = $('#id_mobileupload_input_file')[0].files[0].name;
formData.append('photo',imgsrc);
formData.append('name',imgname);
}
*/
$('.btn-success').off('click').on('click',function(){
location.reload();
$(this).addClass('disabled');
return false;
})
$('#id_mobileupload_screen_loading').css('display','block').animate({
'opacity':'0.7',
},400,function(){
$.ajax({
processData : false,
contentType : false,
type : 'POST',
url : '/uploadmobile2',
data : formData,
success : function(o){
if (o.message == 'success'){
$('#id_mobileupload_screen_loading').animate({
'opacity':'0.0'
},200,function(){
$(this).css('display','none');
info_modal('Upload successful. Check the PC screen for confirmation. Close this dialogue if you no longer need to upload, or "Upload One More".')
})
}else if (o.message=='noroom'){
info_modal('Login token expired. Please scan QR code again.')
}
},
error : function(e){
info_modal(e);
}
})
});
}
$(document).ready(function(){
/* populate the hashed id input field. this will be sent with the photo to the server to identify the question in question */
$('#id_mobileupload_input_hashedid').val(window.location.search.substring(1));
/* prevent accidental double clicks and itchy finger */
$('.btn').off('click').click(function(){
if($(this).hasClass('disabled')){
return false;
}
$(this).addClass('disabled');
var _this = $(this);
setTimeout(function(){
_this.removeClass('disabled');
},500);
if($(this).attr('id')=='id_mobileupload_btn_upload'){
//upload the uncropped image
sendImg('uncropped');
}else if($(this).attr('id')=='id_mobileupload_btn_cropupload'){
//upload the cropped image
sendImg('cropped');
}
});
$('input').off('change').change(function(e){
$('#id_mobileupload_div_cropbox').removeClass('hidden disabled');
$('#id_mobileupload_btn_upload').removeClass('hidden disabled');
$('#id_mobileupload_btn_cropupload').addClass('hidden');
$('#id_mobileupload_label_file').removeClass('disabled');
//$('#id_mobileupload_canvas_cropbody').cropper('destroy');
$('#id_mobileupload_canvas_cropbody').attr({'src': URL.createObjectURL(e.target.files[0]),'width':'100%'});
/*
$('#id_mobileupload_canvas_cropbody').cropper({
autoCrop : false,
viewMode : 1,
crop : function(e){
//cropped change btn
$('#id_mobileupload_btn_upload').addClass('hidden');
$('#id_mobileupload_btn_cropupload').removeClass('hidden');
}
});
*/
})
})
</script>
<style>
.btn
{
margin-top:5px;
}
input
{
height:0.1px;
width:0.1px;
opacity:0;
z-index:-1;
}
canvas
{
max-width:100%;
}
#id_mobileupload_screen_loading
{
display:none;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background-color:#000;
opacity:0.0;
z-index:100;
}
#id_mobileupload_screen_loading p
{
display:block;
font-size:24pt;
height:60%;
margin-top:40%;
text-align:center;
color:#fff;
}
</style>
</head>
<body>
<div id = "id_mobileupload_screen_loading">
<p>
uploading ...
</p>
</div>
<div id="id_mobileupload_modal_warning" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Info</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-dismiss="modal">Upload One More</button>
</div>
</div>
</div>
</div>
<div class = "container">
<div class = "row">
<div class = "col-xs-12">
<div class = "panel panel-primary">
<div class = "panel-heading">
<h4>examcopedia mobile uploader</h4>
</div>
<div class = "panel-body">
<input disabled id = "id_mobileupload_input_hashedid" class = "hidden">
<span>This is the mobile upload widget of examcopedia. If you arrived at this site via a QR code, the image uploaded here should automatically appear in the main window.</span>
<div class = " col-xs-12" id = "id_mobileupload_div_cropbox">
<img id = "id_mobileupload_canvas_cropbody">
</img>
</div>
</div>
<div class = "panel-footer">
<label id = "id_mobileupload_label_file" class = "btn btn-primary btn-block btn-lg" for = "id_mobileupload_input_file"><span class = "glyphicon glyphicon-picture"></span> Select</label><input name = "mobileuploadedphoto" id = "id_mobileupload_input_file" type = "file" accept = "image/*;capture=camera">
<div id = "id_mobileupload_btn_upload" class = "hidden btn btn-primary btn-block btn-lg"><span class = "glyphicon glyphicon-upload"></span> Upload</div>
<!--<div id = "id_mobileupload_btn_cropupload" class = "hidden btn btn-primary btn-block btn-lg"><span class = "glyphicon glyphicon-scissors"></span> Crop & <span class = "glyphicon glyphicon-upload"></span> Upload</div>-->
</div>
</div>
</div>
</div>
</div>
</body>
</html>