forked from elan-ev/studip-opencast-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.js
274 lines (226 loc) · 10.3 KB
/
application.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
OC = {
formData : {},
initAdmin : function(){
jQuery(document).ready(function(){
jQuery('#admin-accordion').accordion();
});
},
initIndexpage: function(){
jQuery( document ).ready(function() {
var cid = jQuery('#course_id').data('courseid');
if(STUDIP.hasperm) {
// Upload Dialog
jQuery("#upload_dialog").dialog({ autoOpen: false, width: 800, dialogClass: 'ocUpload'});
jQuery("#oc_upload_dialog").click(
function () {
jQuery("#upload_dialog").dialog('open');
return false;
}
);
// Config Dialog
jQuery("#config_dialog").dialog({ autoOpen: false, width: 800, dialogClass: 'ocConfig', height: 350});
jQuery("#oc_config_dialog").click(
function () {
jQuery("#config_dialog").dialog('open');
return false;
}
);
jQuery(".chosen-select").chosen({
disable_search_threshold: 10,
max_selected_options: 1,
no_results_text: "Oops, nothing found!",
width: "350px"
});
// toggle visibility
OC.toggleVis(cid);
} else {
jQuery('.hidden_ocvideodiv').remove();
}
if(OC.states && STUDIP.hasperm){
OC.getWorkflowProgressForCourse(cid, true, null);
}
// take care of episodelist
OC.searchEpisodeList();
});
},
initUpload : function(maxChunk){
jQuery(document).ready(function(){
$('#btn_accept').click(function() {
OC.formData.submit();
return false;
});
$('#video_upload').fileupload({
limitMultiFileUploads: 1,
autoupload: false,
maxChunkSize: maxChunk,
add: function(e, data) {
var file = data.files[0];
$('#total_file_size').attr('value', file.size);
$('#file_name').attr('value', file.name);
$('#upload_info').html('<p>Name: '
+ file.name
+ ' Größe: '
+ OC.getFileSize(file.size)
+ '</p>');
$('#upload_info').val(file.name);
OC.formData = data;
return false;
},
submit: function (e, data) {
$("#btn_accept").attr('disabled', true);
$("#progressbar").progressbar({
value: 0
}).addClass('oc_mediaupload_progressbar').show().css({'background': '#d0d7e4'});
},
progressall: function(e, data) {
if (data.bitrate / 8 > 1048576) {
var speed = parseInt(data.bitrate / 8 / 1024 / 1024) + " Mb/s";
} else {
var speed = parseInt(data.bitrate / 8 / 1024) + " kb/s";
}
var progress = parseInt(data.loaded / data.total * 100, 10);
jQuery( "#progressbar" ).progressbar( "value", progress);
jQuery("#progressbar-label").text(progress + " % / " + speed);
},
done: function(e, data) {
jQuery( "#progressbar" ).progressbar('destroy');
jQuery("#upload_dialog").dialog("close");
window.open(STUDIP.URLHelper.getURL("plugins.php/opencast/course/index/false/true"), '_self');
},
error: function(xhr, data) {
console.log('Fehler', data);
}
});
$('#recordDate').datepicker({
dateFormat: "yy-mm-dd"
});
})
},
getFileSize: function(input) {
if(input/1024 > 1) {
var inp_kb = Math.round((input/1024)*100)/100
if(inp_kb/1024 > 1) {
var inp_mb = Math.round((inp_kb/1024)*100)/100
if(inp_mb/1024 > 1) {
var inp_gb = Math.round((inp_mb/1024)*100)/100
return inp_gb + 'GB';
}
return inp_mb + 'MB';
}
return inp_kb + 'KB';
}
return input + 'Bytes'
},
getWorkflowProgressForCourse: function(course_id, animation, info) {
var reload = false;
if(info == null){
info = [];
info[0] = [0,0,0];
}
jQuery.get(STUDIP.ABSOLUTE_URI_STUDIP + "plugins.php/opencast/ajax/getWorkflowStatusforCourse/" + course_id).done(function(data) {
var response = jQuery.parseJSON(data);
if (!jQuery.isEmptyObject(response)) {
for (var job_id in response) {
var job = response[job_id];
if (job.state == 'RUNNING' || job.state == 'INSTANTIATED' ) {
var counter = 1;
var current_description = "";
for (var operation in job.operations.operation) {
counter++;
if (job.operations.operation[operation].state == 'RUNNING'
|| job.operations.operation[operation].state == 'INSTANTIATED'
){
current_description = job.operations.operation[operation].description;
break;
}
}
info[info.length] = [
(counter>job.operations.operation.length?job.operations.operation.length:counter),
job.operations.operation.length,
counter/job.operations.operation.length
];
jQuery('#'+job_id).attr('title',counter +'/'+ job.operations.operation.length +': '+ current_description);
jQuery('#'+job_id).attr('alt', counter +'/'+ job.operations.operation.length +': '+ current_description);
}
else if(jQuery('#'+job_id).length > 0){
reload = true;
}
}
} if((reload || response == "")){
window.open(STUDIP.ABSOLUTE_URI_STUDIP + "plugins.php/opencast/course/index/false", '_self');
} else {
window.setTimeout(function(){OC.getWorkflowProgressForCourse(course_id, false, info)}, 5000)
}
});
},
toggleVis: function(cid){
jQuery('#oc-togglevis').click(function(e) {
e.preventDefault();
var episode_id = jQuery('#oc-togglevis').data("episode-id");
jQuery.get(STUDIP.ABSOLUTE_URI_STUDIP + "plugins.php/opencast/course/toggle_visibility/"
+ episode_id + "?cid=" + cid);
if (jQuery('#oc-togglevis').hasClass('ocvisible')) {
jQuery('#oc-togglevis').removeClass('ocvisible').addClass('ocinvisible').text('Aufzeichnung unsichtbar');
} else {
jQuery('#oc-togglevis').removeClass('ocinvisible').addClass('ocvisible').text('Aufzeichnung sichtbar');
}
});
},
episodeListener: function(cid) {
// open episode item
jQuery('.oce_item').click(function(e){
e.preventDefault();
var episode_id = jQuery(this).attr('id');
//todo animation / progessindication
/*
jQuery('html, body').animate({
scrollTop: jQuery('#barTopFont').offset().top
}, 1000); */
jQuery('#oc_balls').show();
jQuery('.oce_playercontainer').addClass('oc_opaque');
jQuery.get(STUDIP.ABSOLUTE_URI_STUDIP + "plugins.php/opencast/course/get_player/" + episode_id + "/" + cid).done(function(data) {
var episode = data.episode_data;
var dozent = data.perm;
var player_template = _.template(jQuery('#playerTemplate').html());
var player_template_data = {
episode:episode,
theodul:data.theodul,
dozent:dozent,
engage_player_url:data.engage_player_url,
video:data.video
};
jQuery('.oce_playercontainer').empty();
jQuery('.oce_playercontainer').html(player_template(player_template_data));
jQuery('#oc-togglevis').attr('href', STUDIP.URLHelper.getURL('plugins.php/opencast/course/toggle_visibility/' + episode_id));
jQuery('.oce_playercontainer').removeClass('oc_opaque');
jQuery('#oc_balls').hide();
OC.toggleVis(cid);
});
});
},
searchEpisodeList: function(){
var options = {
valueNames: [ 'oce_list_title', 'oce_list_date' ]
};
var episodeList = new List('episodes', options);
},
// schedule setting
initScheduler: function() {
$('.wfselect').change(function(){
var workflow_id = $("option:selected", this).attr('value');
var termin_id = $("option:selected", this).data('terminid');
var resource_id = $("option:selected", this).data('resource');
jQuery.get(STUDIP.ABSOLUTE_URI_STUDIP + "plugins.php/opencast/course/setworkflowforscheduledepisode/" + termin_id + "/" + workflow_id + "/" + resource_id).done(function(data) {
if(!jQuery.isEmptyObject(data)){
console.log(data);
//todo trigger success message
if(data === 'true'){
//console.log('lööpt'); TODO STUD.IP Success Box triggern
} else {
alert('Der Workflow konnte für die geplante Aufzeichnung nicht gesetzt werden.')
}
}
});
})
}
};