-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload.js
243 lines (210 loc) · 10 KB
/
upload.js
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
var uploadFormData = new FormData();
var downloadStatus = null;
var loadingSvg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: #747; display: block;" width="40px" height="40px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"><g transform="translate(50 50)"><g><animateTransform attributeName="transform" type="rotate" values="0;45" keyTimes="0;1" dur="0.4081632653061225s" repeatCount="indefinite"></animateTransform><path d="M29.491524206117255 -5.5 L37.491524206117255 -5.5 L37.491524206117255 5.5 L29.491524206117255 5.5 A30 30 0 0 1 24.742744050198738 16.964569457146712 L24.742744050198738 16.964569457146712 L30.399598299691117 22.621423706639092 L22.621423706639096 30.399598299691114 L16.964569457146716 24.742744050198734 A30 30 0 0 1 5.5 29.491524206117255 L5.5 29.491524206117255 L5.5 37.491524206117255 L-5.499999999999997 37.491524206117255 L-5.499999999999997 29.491524206117255 A30 30 0 0 1 -16.964569457146705 24.742744050198738 L-16.964569457146705 24.742744050198738 L-22.621423706639085 30.399598299691117 L-30.399598299691117 22.621423706639092 L-24.742744050198738 16.964569457146712 A30 30 0 0 1 -29.491524206117255 5.500000000000009 L-29.491524206117255 5.500000000000009 L-37.491524206117255 5.50000000000001 L-37.491524206117255 -5.500000000000001 L-29.491524206117255 -5.500000000000002 A30 30 0 0 1 -24.742744050198738 -16.964569457146705 L-24.742744050198738 -16.964569457146705 L-30.399598299691117 -22.621423706639085 L-22.621423706639092 -30.399598299691117 L-16.964569457146712 -24.742744050198738 A30 30 0 0 1 -5.500000000000011 -29.491524206117255 L-5.500000000000011 -29.491524206117255 L-5.500000000000012 -37.491524206117255 L5.499999999999998 -37.491524206117255 L5.5 -29.491524206117255 A30 30 0 0 1 16.964569457146702 -24.74274405019874 L16.964569457146702 -24.74274405019874 L22.62142370663908 -30.39959829969112 L30.399598299691117 -22.6214237066391 L24.742744050198738 -16.964569457146716 A30 30 0 0 1 29.491524206117255 -5.500000000000013 M0 -19A19 19 0 1 0 0 19 A19 19 0 1 0 0 -19" fill="#d5cc1b"></path></g></g></svg>'
$(function() {
$("#vidmask").on("mouseover", function(e) {
e.preventDefault();
e.stopPropagation();
});
$("#vidmask").on("click", function(e) {
e.preventDefault();
e.stopPropagation();
});
// Upload form buttons
$("#uploadtype_first").click(function(){
$("#upload-question-type").hide();
$("#upload-question-details").show();
});
// Upload form buttons
$("#uploadtype_update").click(function(){
$("#upload-question-type").hide();
$("#upload-question-pin").show();
});
// preventing page from redirecting
$("html").on("dragover", function(e) {
e.preventDefault();
e.stopPropagation();
});
$("html").on("drop", function(e) { e.preventDefault(); e.stopPropagation(); });
// Drag enter
$('.upload-area').on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
$("h1").text("All right, drop it");
});
// Drag over
$('.upload-area').on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
$("h1").text("All right, drop it");
});
// Drop
$('.upload-area').on('drop', function (e) {
e.stopPropagation();
e.preventDefault();
var file = e.originalEvent.dataTransfer.files[0];
$("h1").text("Ready to upload " + file.name + "!");
uploadFormData = new FormData();
uploadFormData.set('file', file);
});
// Open file selector on div click
$("#uploadfile").click(function(){
$("#file").click();
});
// file selected
$("#file").change(function(){
uploadFormData = new FormData();
var file = $('#file')[0].files[0];
$("h1").text("Ready to upload " + file.name + "!");
uploadFormData.set('file',file);
});
$("#upload_wad").click(function(){
uploadFormData.set('mapname', $('#input_map_name').val());
uploadFormData.set('authorname', $('#input_author_name').val());
uploadFormData.set('musiccredit', $('#input_music_credit').val());
uploadFormData.set('pin', $('#input_pin_to_reupload').val());
uploadFormData.set('jumpcrouch', ($('#input_map_jumpcrouch')[0].checked ? 1 : 0));
uploadFormData.set('wip', ($('#input_map_wip')[0].checked ? 1 : 0));
uploadFormData.set('category', $('input[name="input_map_category"]:checked').val());
uploadFormData.set('difficulty', $('input[name="input_map_difficulty"]:checked').val());
uploadFormData.set('length', $('input[name="input_map_length"]:checked').val());
uploadFormData.set('monsters', $('#input_monster_count').val());
uploadData(uploadFormData);
});
$("#confirm_pin").click(function(){
uploadFormData = new FormData();
uploadFormData.set('pin', $('#input_pin_to_reupload').val());
submitPin(uploadFormData);
});
$("#download_button").click(function(){
$('#download_button').attr("disabled", true);
$('#download_button').addClass("waitingdisabled");
$('#download_button').html("Please wait, generating the project...<br/>" + loadingSvg);
downloadProject();
});
});
function readStatus() {
$.ajax({
url: './status.log?xcache=' + Math.random(),
type: 'get',
dataType: 'text',
success: function(response){
$('#download_status').text(response);
}
});
}
function downloadProject() {
downloadStatus = setInterval(readStatus, 800);
$.ajax({
url: './handle_pk3_update.php?xcache=' + Math.random(),
type: 'get',
dataType: 'json',
success: function(response){
$('#download_status').text("");
clearInterval(downloadStatus);
//Don't really re-enable the button!
$('#download_button').removeClass("waitingdisabled");
if (response.error) {
$('#download_button').text(response.error);
return;
}
$('#download_button').text("Project generated!");
window.location.href = './handle_download.php?xcache=' + Math.random();
}
});
}
var lastlogfiletime = null;
function getBuildLog() {
$.ajax({
url: './get_build_log.php',
type: 'get',
success: function(response){
$('#download_log').text(response.log);
if (response.filetime != lastlogfiletime) {
setTimeout(getBuildLog, 500);
}
else {
$('#download_button').text("Project generated!");
}
lastlogfiletime = response.filetime;
}
});
}
// Sending AJAX request and upload file
function uploadData(formdata){
$('#upload_wad').attr("disabled", true);
$('#upload_wad').addClass("waitingdisabled");
$('#upload_wad').text("Working...");
$.ajax({
url: './handle_upload.php',
type: 'post',
data: formdata,
contentType: false,
processData: false,
dataType: 'json',
success: function(response){
updateUploadArea(response);
}
});
}
function submitPin(formdata){
$('#confirm_pin').attr("disabled", true);
$('#confirm_pin').addClass("waitingdisabled");
$('#confirm_pin').text("Working...");
$.ajax({
url: './handle_pin.php',
type: 'post',
data: formdata,
contentType: false,
processData: false,
dataType: 'json',
success: function(response){
populateMapInfo(response);
}
});
}
function updateUploadArea(response) {
if (response.error) {
$('#upload_wad').attr("disabled", false);
$('#upload_wad').removeClass("waitingdisabled");
$('#upload_wad').text("Upload WAD!");
$("h1").text("Drag and drop here again");
$('#upload_status').removeClass('success');
$('#upload_status').addClass('fail');
$('#upload_status').text(response.error);
} else {
$("h1").text("OK!");
$('#upload_status').removeClass('fail');
$('#upload_status').addClass('success');
$("#upload_status").html(response.success);
$('#upload_form').remove();
}
}
function populateMapInfo(response) {
if (response.error) {
$('#confirm_pin').attr("disabled", false);
$('#confirm_pin').removeClass("waitingdisabled");
$('#confirm_pin').text("That's my PIN");
$('#pin_status').removeClass('success');
$('#pin_status').addClass('fail');
$('#pin_status').text(response.error);
$('#pin_status').show();
} else {
$("#upload-question-pin").hide();
$("#upload-question-details").show();
$("#input_map_name").val(response.mapname);
$("#input_author_name").val(response.author);
$("#input_music_credit").val(response.musiccredit);
$('#input_map_jumpcrouch')[0].checked = response.jumpcrouch == 0 ? false : true;
$('#input_map_wip')[0].checked = response.wip == 0 ? false : true;
$('[name="input_map_category"]').removeAttr('checked');
$('input[name="input_map_category"][value="' + response.category + '"]').prop('checked', true);
$('[name="input_map_difficulty"]').removeAttr('checked');
$('input[name="input_map_difficulty"][value="' + response.difficulty + '"]').prop('checked', true);
$('[name="input_map_length"]').removeAttr('checked');
$('input[name="input_map_length"][value="' + response.length + '"]').prop('checked', true);
$("#input_monster_count").val(response.monsters);
$("#upload_prompt").html('OK - alter your details and attach a new map here if you need to.');
$("#upload_wad").text('Submit changes');
}
}