-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUKMplayback.js
167 lines (148 loc) · 5.5 KB
/
UKMplayback.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
jQuery(document).ready(function() {
jQuery('#fileupload_playback').fileupload({
// Uncomment the following to send cross-domain cookies:
xhrFields: { withCredentials: true },
url: 'https://playback.' + UKM_HOSTNAME + '/upload/jQupload_recieve.php',
fileTypes: '^audio\/(.)+',
autoUpload: true,
formData: {
'season': jQuery('#season').val(),
'pl_id': jQuery('#pl_id').val()
},
progressall: function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
jQuery('#uploadprogress').attr('value', progress);
},
}).bind('fileuploaddone', function(e, data) {
if (!data.result.success) {
fileUploadError(data.result);
} else {
jQuery('#uploading').slideUp();
jQuery('#uploaded').slideDown();
jQuery('#filename').val(data.result.files[0].file_id);
jQuery('#submitbutton').attr('disabled', '').removeAttr('disabled');
}
}).bind('fileuploadstart', function() {
jQuery('#filechooser').slideUp();
jQuery('#uploading').slideDown();
jQuery('#fileupload_dropzone').fadeOut();
});
if (jQuery('#fileupload_playback').html() !== 'undefined' && jQuery('#fileupload_playback').html() !== undefined) {
if (jQuery.support.cors) {
jQuery.ajax({
url: 'https://playback.' + UKM_HOSTNAME + '/upload/jQupload_cors.php',
type: 'HEAD'
}).fail(function() {
var result = {
'success': false,
'message': 'Beklager, playbackserveren er ikke tilgjengelig akkurat nå'
};
fileUploadError(result);
});
}
}
});
jQuery(document).on('click', '.PBdel', function() {
return confirm('Er du sikker på at du vil slette denne?');
});
////////////////////////////////////////////////////////////////////////////////////////
// FILEUPLOAD: HJELPERE
////////////////////////////////////////////////////////////////////////////////////////
function fileUploadError(result) {
jQuery('#fileupload_container').slideUp();
jQuery('#fileupload_message').html(twigJS_lastopperror.render(result)).slideDown();
}
///// LAST NED ZIP
var workList = new UKMresources.workQueue(
'zipList', {
elementHandler: function(zip_id) {
var emitter = new UKMresources.emitter('zip_' + zip_id);
var selector = '#zip_' + zip_id;
var item = jQuery(selector);
var response = {
id: zip_id,
filecount: item.data('filecount')
};
// Har ingen filer
if (response.filecount == 0) {
setTimeout(
function() {
emitter.emit('success', response);
}, 100
);
} else {
UKMresources.Request({
url: 'https://playback.' + window.location.hostname + '/zipMePlease/',
containers: {
loading: selector + ' .loading',
success: selector + ' .success',
error: selector + ' .error',
fatalError: '#status',
main: '#formContainer'
},
handleSuccess: (response) => {
emitter.emit('success', response);
},
handleError: (response, message) => {
emitter.emit('error', response);
}
}).do({
data: item.data('package'),
id: zip_id
});
}
return emitter;
}
}
);
// Når alle filer er zip'et
workList.on('done', () => {
jQuery('#pleasewait').slideUp();
});
// En fil er ferdig
workList.on('success', (data) => {
// Ingen filer betyr at vi ikke får serverdata,
// men bare enkel ID-data tilbake
if (data.filecount == 0) {
jQuery('#zip_' + data.id)
//.append('Ingen innslag har mediefiler')
.appendTo('#cleanedEmptyList');
return true;
}
// Dobbeltsjekk at vi har serverdata
if (data.POST) {
var item = jQuery('#zip_' + data.POST.id);
item.find('.download').attr('href', data.url).fadeIn();
item.find('.navn.preLoad').slideUp();
item.find('.navn.postLoad').slideDown();
if (data.hasErrors) {
data.errors.forEach(function(value) {
if (value.type == 'fil') {
item.find('.warnings > ol').append(twigJS_lastnederror.render(value));
} else {
item.find('.warnings > ol').append(
jQuery('<li class="list-group-item alert-danger">')
.html('<b>Klarte ikke å lagre zip-filen: </b>' + value)
);
item.find('.download').hide();
}
});
item.find('.warnings').slideDown();
}
return true;
}
return false;
});
workList.on('error', (data) => {
var item = jQuery('#zip_' + data.id);
item.append('<br />' + data.message);
item
.addClass('alert-danger')
.appendTo('#cleanedList');
});
jQuery(document).ready(function() {
jQuery('#zipList li').each((index, zipfile) => {
workList.push(jQuery(zipfile).data('id'));
});
workList.start();
});