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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
/*
* rhwebimport
*
* Copyright (C) 2014-2016 Christian Pointner <equinox@helsinki.at>
* Copyright (C) 2015-2016 Peter Grassberger <petertheone@gmail.com>
*
* This file is part of rhwebimport.
*
* rhwebimport is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* rhwebimport is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with rhwebimport. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
var Rdxport = Rdxport || {};
var showListView = null;
function shows_init(subpage) {
var showList = new Rdxport.GroupList();
showListView = new Rdxport.ShowListView(showList, subpage);
drawClock('Do, 1.1.1970', '00:00:00', 0);
clock_add_callback(drawClock);
}
function shows_cleanup() {
$('#show-carts tbody').find('tr').remove();
importer.closeAllUploads();
}
Rdxport.ShowListView = function(model, subpage) {
this.model = model;
this.showViews = [];
this.currentShowId = null;
this.setCurrentShowId(subpage);
var self = this;
$(this.model).off('update').on('update', function() {
$(self.model.groups).each(function(index, show) {
var showView = new Rdxport.ShowView(show);
self.showViews.push(showView);
});
self.updateSelector();
});
this.model.fetch('show');
};
Rdxport.ShowListView.prototype.setCurrentShowId = function(currentShowId) {
if (!currentShowId) {
return;
}
if (this.currentShowId !== currentShowId) {
if (this.currentShowId) {
history.pushState(null, null, '/shows/' + currentShowId + '/');
} else {
history.replaceState(null, null, '/shows/' + currentShowId + '/');
}
}
this.currentShowId = currentShowId;
sessionStorage.setItem('currentShowId', this.currentShowId);
};
Rdxport.ShowListView.prototype.getCurrentShowView = function() {
if (this.model.groups.length === 0) {
return null;
}
if (this.showViews.length === 0) {
return null;
}
var self = this;
var showViewFound = null;
$(this.showViews).each(function(index, showView) {
if (showView.model.id === parseInt(self.currentShowId)) {
showViewFound = showView;
return true;
}
});
return showViewFound;
};
Rdxport.ShowListView.prototype.updateSelector = function() {
var self = this;
var $showSelector = $('#show-selector');
$showSelector.off();
$('li', $showSelector).remove();
$(this.model.groups).sort(function(a, b) {
var atitle = a.title.toLowerCase();
var btitle = b.title.toLowerCase();
if(atitle == btitle) {
if(b.rhythm == a.rhythm) {
if(a.dayofweek == b.dayofweek) {
if(a.starttime == b.starttime) {
return a.showid - b.showid;
}
if(a.starttime > b.starttime) return 1;
return -1;
}
var adow = a.dayofweek == 0 ? 7 : a.dayofweek;
var bdow = b.dayofweek == 0 ? 7 : b.dayofweek;
return adow - bdow;
}
return parseInt(b.rhythm) - parseInt(a.rhythm);
}
if(atitle > btitle) return 1;
return -1;
}).each(function(index, show) {
var name = show.id + ' | <strong>' + show.title + '</strong> (' + show.rhythm + ', ' + weekday[show.dayofweek] + ', ' + show.starttime + ', ' + show.length + ' Min.)';
var link = $('<a>').attr('href', '#').html(name).click(function() {
self.setCurrentShowId(show.id);
self.getCurrentShowView().model.fetchCarts();
});
$showSelector.append($('<li>').append(link));
});
if($showSelector.children().length == 0) {
$showSelector.append($('<li>').append($('<a>').text('Keine Sendung gefunden!')));
}
// todo: maybe integrate this into setCurrentShowId?
if (!this.currentShowId) {
var currentShowId = sessionStorage.getItem('currentShowId');
if (currentShowId) {
this.setCurrentShowId(currentShowId);
} else {
this.setCurrentShowId(this.model.groups[0].id);
}
}
this.getCurrentShowView().model.fetchCarts();
};
Rdxport.Show = function(groupName, description, lowcart, highcart, normlevel, trimlevel,
id, title, log, rhythm, dayofweek, starttime, length) {
if (arguments.length = 1) {
Rdxport.Group.call(this, groupName);
this.id = parseInt($('show-id', this.xml).text());
this.title = $('show-title', this.xml).text();
this.log = $('show-log', this.xml).text();
this.rhythm = $('show-rhythm', this.xml).text();
this.dayofweek = parseInt($('show-dayofweek', this.xml).text());
this.starttime = $('show-starttime', this.xml).text();
this.length = parseInt($('show-length', this.xml).text());
} else {
Rdxport.Group.call(this, groupName, description, lowcart, highcart, normlevel, trimlevel);
this.id = id;
this.title = title;
this.log = log;
this.rhythm = rhythm;
this.dayofweek = dayofweek;
this.starttime = starttime;
this.length = length;
}
this.logs = [];
};
Rdxport.Show.prototype = Object.create(Rdxport.Group.prototype);
Rdxport.Show.prototype.constructor = Rdxport.Show;
Rdxport.Show.prototype.fetchCarts = function() {
var self = this;
var lcd = rdxport.listLog(this.log, function(logsXml, status, req) {
self.logs = [];
var loglines = $('logList', logsXml).children();
loglines.each(function(index, logXml) {
var log = Rdxport.Log.newFromXml(logXml, self);
if(log.cartNumber >= self.lowcart &&
log.cartNumber <= self.highcart) {
self.logs.push(log);
}
});
});
var gcd = rdxport.listCarts({GROUP_NAME: this.groupName, INCLUDE_CUTS: 1}, function(cartsXml, status, req) {
self.carts = [];
self.cartsByNumber = {};
var dbs = $('cartList', cartsXml).children();
dbs.each(function(index, cartXml) {
var cart = new Rdxport.Cart(cartXml, self);
var cuts = $('cutList', cartXml).children();
cuts.each(function(index, cut) {
cart.cuts.push(new Rdxport.Cut(cut, cart));
});
self.addCart(cart);
});
});
$.when(lcd, gcd).done(function(lcres, gcres) {
if(lcres[1] == 'success' && gcres[1] == 'success') {
self.$this.trigger('update');
}
});
};
Rdxport.ShowView = function(model) {
this.model = model;
this.cartViews = [];
this.$el = null;
var self = this;
this.model.$this.off('update').on('update', function() {
self.render();
});
};
Rdxport.ShowView.prototype.render = function() {
$('#show-title').text(this.model.title);
$('#show-dow').text(weekday[this.model.dayofweek]);
$('#show-starttime').text(this.model.starttime);
$('#show-length').text(this.model.length + ' Min.');
for(var w = 0; w < 4; w++) {
if(this.model.rhythm.charAt(w) == '1') {
var s = $('#show-rhythm-w' + (w+1)).attr('class', 'label');
switch(w+1) {
case 1: s.addClass('label-info'); break;
case 2: s.addClass('label-warning'); break;
case 3: s.addClass('label-success'); break;
case 4: s.addClass('label-danger'); break;
}
} else {
$('#show-rhythm-w' + (w+1)).attr('class', 'label label-disabled')
}
}
var $tableBody = $('#app-shows table tbody');
$('tr', $tableBody).remove();
this.cartViews = [];
var self = this;
$(this.model.logs).each(function(index, log) {
var cart = self.model.getCartByNumber(log.cartNumber);
var upload = importer.getUploadByCartNumber(log.cartNumber);
if (upload) {
$('#app-shows table > tbody').append(Rdxport.ShowCartView.renderUploading(upload));
if (upload.error) {
self.uploadError(upload);
}
} else if (cart) {
var cartView = new Rdxport.ShowCartView(cart, self);
self.cartViews.push(cartView);
cartView.render();
$('#app-shows table > tbody').append(cartView.$el);
} else {
$('#app-shows table > tbody').append(Rdxport.ShowCartView.renderEmpty(self.model, self, log.cartNumber));
}
});
};
Rdxport.ShowView.prototype.uploadProgress = function(upload) {
if (!upload.uploadId) {
return;
}
var $cart = $('tr[data-upload-id="' + upload.uploadId + '"]', this.$el).first();
if (!$cart.hasClass('uploading')) {
var $progressBar = $('.progressBarTemplate.shows').clone().removeClass('progressBarTemplate');
$cart.html($progressBar.html());
$('button', $cart).off('click').on('click', function() {
upload.cancel();
});
$cart.addClass('uploading');
}
if (upload.title) {
$('.file-name', $cart).text(upload.title);
}
if (upload.cartNumber) {
$('.cart-number', $cart).text(upload.cartNumber);
}
updateProgressBar($cart, upload);
};
Rdxport.ShowView.prototype.uploadError = function(upload) {
var reason = $('<span>').addClass('label').addClass('label-danger').text(upload.errorStatus).after($('<b>').text(' ' + upload.errorString));
var dismiss_button = '<button class="btn btn-info btn-xs">' +
'<span class="glyphicon glyphicon-remove"></span> Ok</button>';
var $errorRow = $('<tr>')
.attr('data-upload-id', upload.uploadId)
.append($('<td>').addClass('.cart-number').text('...'))
.append($('<td>').addClass('file-name'))
.append($('<td>').append($('<b>').text('Import Fehler')))
.append($('<td colspan="3">').append(reason))
.append($('<td>').css('text-align', 'center').append(dismiss_button));
if (upload.cartNumber) {
$('.cart-number', $errorRow).text(upload.cartNumber);
}
if (upload.title) {
$('.file-name', $errorRow).text(upload.title);
}
$('button', $errorRow).off('click').on('click', function() {
upload.close();
});
var $cart = $('tr[data-upload-id="' + upload.uploadId + '"]', this.$el).first();
console.log($('tr'));
$cart.replaceWith($errorRow);
};
Rdxport.ShowCartView = function(model, groupView) {
this.model = model;
this.groupView = groupView;
this.$spinner = null;
this.$el = $('<tr>');
};
Rdxport.ShowCartView.prototype.render = function() {
var $deleteButton = $('<button class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span> Löschen</button>');
var self = this;
$deleteButton.off('click').on('click', function() {
self.delete();
});
this.$spinner = $('#hiddenTemplates .spinnerTemplate').clone().removeClass('spinnerTemplate');
var cut = this.model.cuts[0];
var length = '-';
var originDatetime = '-';
var playCounter = '-';
var lastPlayDatetime = '-';
if (cut) {
length = msToTimeString(Number(cut.length));
originDatetime = format_datetime(cut.originDatetime);
playCounter = cut.playCounter;
lastPlayDatetime = format_datetime(cut.lastPlayDatetime);
}
this.$el = this.$el.empty()
.attr('id', 'show-cart-' + this.model.number)
.append($('<td>').text(this.model.number))
.append($('<td>').text(this.model.title))
.append($('<td>').text(length))
.append($('<td>').text(originDatetime))
.append($('<td>').text(playCounter))
.append($('<td>').text(lastPlayDatetime))
.append($('<td>').css('text-align', 'center').append($deleteButton));
};
Rdxport.ShowCartView.renderUploading = function(upload) {
var $progressBar = $('.progressBarTemplate.shows').clone().removeClass('progressBarTemplate');
$('.file-name', $progressBar).text(upload.title);
$('.cart-number', $progressBar).text(upload.cartNumber);
var $el = $('<tr>')
.html($progressBar.html())
.attr('id', 'show-cart-' + upload.cartNumber)
.addClass('uploading')
.attr('data-upload-id', upload.uploadId);
$('button', $el).off('click').on('click', function() {
upload.cancel();
});
updateProgressBar($el, upload);
return $el;
};
Rdxport.ShowCartView.renderEmpty = function(group, groupView, cartNumber) {
var $uploadButton = $('<button class="uploadButton btn btn-primary btn-xs"><span class="glyphicon glyphicon-upload"></span> Importieren</button>');
$uploadButton.off('click').on('click', function() {
importer.openModal(group, groupView, cartNumber, true, false);
});
return $('<tr>')
.attr('id', 'show-cart-' + cartNumber)
.append($('<td>').text(cartNumber))
.append($('<td>').text('-'))
.append($('<td>').text('-'))
.append($('<td>').text('-'))
.append($('<td>').text('-'))
.append($('<td>').text('-'))
.append($('<td>').css('text-align', 'center').append($uploadButton));
};
Rdxport.ShowCartView.prototype.delete = function() {
$('td:last', this.$el).html(this.$spinner);
var self = this;
rdxport.removeCart(this.model.number, function() {
self.model.group.removeCart(self.model);
var $empty = Rdxport.ShowCartView.renderEmpty(self.model.group, self.groupView, self.model.number);
self.$el.replaceWith($empty);
});
};
|