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
|
var shows_currentid;
var shows_list = [];
var shows_current;
var shows_group_carts = {};
var shows_log_carts = [];
function shows_deleteCart(cart) {
data = { COMMAND: 13, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: cart };
$.post("/rd-bin/rdxport.cgi", data, null, "xml").done(function() { shows_updateGroupCartInfo(cart); });
}
function shows_importAddCut(cart, dz, file) {
data = { COMMAND: 10, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: cart };
$.post("/rd-bin/rdxport.cgi", data, null, "xml").done(function() { dz.processQueue(); })
.fail(function(xhr, status, err) { shows_importFileUploadError(cart, dz, file, err, xhr); });
}
function shows_importAddCart(cart, dz, file) {
data = { COMMAND: 12, LOGIN_NAME: auth_username, PASSWORD: auth_token,
GROUP_NAME: shows_current.group.name, TYPE: 'audio', CART_NUMBER: cart };
$.post("/rd-bin/rdxport.cgi", data, null, "xml").done(function() { shows_importAddCut(cart, dz, file); })
.fail(function(xhr, status, err) { shows_importFileUploadError(cart, dz, file, err, xhr); });
}
function shows_importCartCancel(cart, dz) {
shows_deleteCart(cart);
dz.off("error");
dz.disable();
}
function shows_importFileUploadError(cart, dz, file, msg, xhr) {
alertbox.error('app-shows', "Import Fehler", $('<div>').append($('<pre>').text(msg)).html());
shows_deleteCart(cart);
dz.disable();
}
function shows_importFileUploadSuccess(cart, dz, file) {
shows_updateGroupCartInfo(cart);
dz.disable();
}
function shows_importUpdateProgress(file, stats) {
var bytes_str = Number((file.upload.bytesSent/1024)/1024).toFixed(1) + " von " +
Number((file.upload.total/1024)/1024).toFixed(1) + " MB";
stats.find('.file-bytes').text(bytes_str);
stats.find('.progress .bar').css("width", file.upload.progress + "%");
}
function shows_importCartConfirm(cart, dz) {
$('#shows-upload').modal('hide');
var cart_row = $('#show-cart-' + cart)
cart_row.next().remove();
cart_row.find('.btn').attr('disabled','disabled');
var dz_stat = shows_getDzStat(false);
dz_stat.find('button').unbind('click').click(function() { shows_importCartCancel(cart, dz); });
cart_row.after(dz_stat);
dz.off("error");
files = dz.getAcceptedFiles();
dz_stat.find('.file-name').text(files[0].name);
shows_importUpdateProgress(files[0], dz_stat);
dz.on("uploadprogress", function(file) { shows_importUpdateProgress(file, dz_stat); });
dz.on("success", function(file) { shows_importFileUploadSuccess(cart, dz, file); });
dz.on("error", function(file, msg, xhr) { shows_importFileUploadError(cart, this, file, msg, xhr); });
shows_importAddCart(cart, dz, files[0]);
}
function shows_createImportForm(cart) {
return $('<form>').attr("action", "/rd-bin/rdxport.cgi").attr("method", "post").attr("enctype", "multipart/form-data")
.append($('<input>').attr("type", "hidden").attr("name", "COMMAND").attr("value", 2))
.append($('<input>').attr("type", "hidden").attr("name", "LOGIN_NAME").attr("value", auth_username))
.append($('<input>').attr("type", "hidden").attr("name", "PASSWORD").attr("value", auth_token))
.append($('<input>').attr("type", "hidden").attr("name", "CART_NUMBER").attr("value", cart))
.append($('<input>').attr("type", "hidden").attr("name", "CUT_NUMBER").attr("value", 1))
.append($('<input>').attr("type", "hidden").attr("name", "CHANNELS").attr("value", 2))
.append($('<input>').attr("type", "hidden").attr("name", "NORMALIZATION_LEVEL").attr("value", shows_current.normlevel))
.append($('<input>').attr("type", "hidden").attr("name", "AUTOTRIM_LEVEL").attr("value", shows_current.trimlevel))
.append($('<input>').attr("type", "hidden").attr("name", "USE_METADATA").attr("value", 1));
}
function shows_importFileAdded(dz, file, cart) {
$(dz.getAcceptedFiles()).each(function(idx, elem) { dz.removeFile(elem); });
$('#shows-upload div.modal-body').css("background-image", "url('/img/audio_file.png')")
$('#shows-upload div.modal-header h3').text(file.name)
$('#shows-upload-confirm').removeAttr('disabled').unbind('click').click(function() { shows_importCartConfirm(cart, dz); });
}
function shows_importFileSelectError(dz, file, msg) {
$('#shows-upload div.modal-header h3').text("Datei auswählen...")
$('#shows-upload div.modal-body').css("background-image", "url('/img/dz-backdrop.png')");
$('#shows-upload-confirm').attr('disabled','disabled').unbind('click');
dz.removeFile(file);
}
function shows_importCart(cart) {
var form = shows_createImportForm(cart);
$('#shows-upload div.modal-header h3').text("Datei auswählen...")
$('#shows-upload div.modal-body').empty().append(form).css("background-image", "url('/img/dz-backdrop.png')");
$('#shows-upload-confirm').attr('disabled','disabled').unbind('click');
var dz = form.dropzone({ url: "/rd-bin/rdxport.cgi", prallelUploads: 1, maxFilesize: 2048, paramName: 'FILENAME',
uploadMultiple: false, clickable: true, createImageThumbnails: false,
acceptedFiles: ".flac,.wav,.ogg,.mp3", autoProcessQueue: false, init: function() {
this.on("addedfile", function(file) { shows_importFileAdded(this, file, cart); });
this.on("error", function(file, msg) { shows_importFileSelectError(this, file, msg); });
}});
$('#shows-upload').modal({ keyboard: true });
}
// <td>
// <button class="btn btn-info btn-mini disabled"><i class="icon-arrow-up icon-white"></i></button>
// <button class="btn btn-info btn-mini disabled"><i class="icon-arrow-down icon-white"></i></button>
// <button class="btn btn-danger btn-mini"><i class="icon-trash icon-white"></i> Löschen</button>
// </td>
// <td>
// <button class="btn btn-info btn-mini"><i class="icon-arrow-up icon-white"></i></button>
// <button class="btn btn-info btn-mini disabled"><i class="icon-arrow-down icon-white"></i></button>
// <button class="btn btn-success btn-mini"><i class="icon-upload icon-white"></i> Importieren</button>
// </td>
function shows_getDzStat(empty) {
if(empty) {
return $('<tr>').append($('<td colspan=6>').css("border", 0)
.css("height", 0)
.css("margin", 0)
.css("padding", 0));
} else {
var progress_bar = '<div class="progress progress-striped"><div class="bar" style="width: 0%;"></div></div>';
var cancel_button = '<button class="btn btn-danger btn-mini">' +
'<i class="icon-remove icon-white"></i> Abbrechen</button>';
return $('<tr>').append($('<td>').addClass('file-name').text('-'))
.append($('<td>').addClass('file-bytes').text('??.? von ??.? MB'))
.append($('<td colspan=3>').append(progress_bar))
.append($('<td>').append(cancel_button));
}
}
function shows_updateGroupCartInfo(cart) {
data = { COMMAND: 7, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: cart, INCLUDE_CUTS: 1 };
var defer = $.post("/rd-bin/rdxport.cgi", data, shows_updateGroupCartList, "xml")
.fail(function() { delete shows_group_carts[cart]; shows_redrawCartEntry(cart); });
$.when(defer).done(function() { shows_redrawCartEntry(cart); });
}
function shows_redrawCartEntry(cart) {
$('#show-cart-' + cart).replaceWith(shows_newCartEntry(cart));
$('#show-cart-' + cart).next().replaceWith(shows_getDzStat(true));
}
function shows_newCartEntry(elem) {
var cart_exists = shows_group_carts[elem] ? 1 : 0;
var cart = {};
cart.title = cart_exists ? shows_group_carts[elem].title : '-';
cart.length = cart_exists ? shows_group_carts[elem].length : '-';
cart.imported = cart_exists ? format_datetime(shows_group_carts[elem].imported) : '-';
cart.playcnt = cart_exists ? shows_group_carts[elem].playcnt : '-';
cart.lastplayed = cart_exists ? format_datetime(shows_group_carts[elem].lastplayed) : '-';
var buttons = cart_exists ?
'<button class="btn btn-danger btn-mini" onclick="shows_deleteCart(' + elem + ');">' +
'<i class="icon-trash icon-white"></i> Löschen</button>' :
'<button class="btn btn-success btn-mini" onclick="shows_importCart(' + elem + ');">' +
'<i class="icon-upload icon-white"></i> Importieren</button>';
return $('<tr>').append($('<td rowspan=2>').text(elem))
.append($('<td>').text(cart.title))
.append($('<td>').text(msToTimeString(cart.length)))
.append($('<td>').text(cart.imported))
.append($('<td>').text(cart.playcnt))
.append($('<td>').text(cart.lastplayed))
.append($('<td>').append(buttons)).attr("id", "show-cart-" + elem);
}
function shows_udpateCartListing() {
$('#show-carts tbody').find('tr').remove();
shows_log_carts.forEach(function(elem) {
$('#show-carts > tbody:last').append(shows_newCartEntry(elem))
.append(shows_getDzStat(true));
});
}
function shows_updateGroupCartList(data, status, req) {
var cartlist = $(data).find("cartList");
var carts = cartlist.children();
carts.each(function() {
var cut = $(this).find("cutList").get(0);
number = $(this).find('number').text(),
cart = {
title: $(this).find('title').text(),
length: Number($(cut).find('length').text()),
imported: new Date($(cut).find('originDatetime').text()),
playcnt: $(cut).find('playCounter').text(),
lastplayed: new Date($(cut).find('lastPlayDatetime').text()),
};
cart.imported = isNaN(cart.imported) ? '-' : cart.imported;
cart.lastplayed = isNaN(cart.lastplayed) ? '-' : cart.lastplayed;
shows_group_carts[number] = cart;
}
);
}
function shows_updateLogCartList(data, status, req) {
var loglist = $(data).find("logList");
var loglines = loglist.children();
loglines.each(function() {
var number = $(this).find('cartNumber').text();
if(number >= shows_current.group.lowcart && number <= shows_current.group.highcart) {
shows_log_carts.push(number);
}
}
);
}
function shows_showSelected() {
shows_currentid = $('#show-selector option:selected').attr('value');
sessionStorage.setItem("shows_currentid", shows_currentid);
shows_current = $.grep(shows_list, function(elem) { return elem.id == shows_currentid; })[0];
if(shows_current) {
$('#show-title').text(shows_current.title);
$('#show-dow').text(weekday[shows_current.dow]);
$('#show-rhythm').text(shows_current.rhythm);
$('#show-starttime').text(shows_current.starttime);
$('#show-length').text(shows_current.length + ' Min.');
shows_log_carts = [];
data = { COMMAND: 22, LOGIN_NAME: auth_username, PASSWORD: auth_token, NAME: shows_current.log };
lcd = $.post("/rd-bin/rdxport.cgi", data, shows_updateLogCartList, "xml");
shows_group_carts = {};
data = { COMMAND: 6, LOGIN_NAME: auth_username, PASSWORD: auth_token, GROUP_NAME: shows_current.group.name, INCLUDE_CUTS: 1 };
gcd = $.post("/rd-bin/rdxport.cgi", data, shows_updateGroupCartList, "xml");
$.when(lcd, gcd).done(
function(lcres, gcres) {
if(lcres[1] == 'success' && gcres[1] == 'success') {
shows_udpateCartListing();
}
}
);
}
}
function shows_updateList(data, status, req) {
shows_list = [];
$('#show-selector').find('option').remove();
var dblist = $(data).find("dropboxList");
var dbs = dblist.children();
dbs.each(function() {
type = $(this).find('type').text();
if(type == 'show') {
var show = {
id: $(this).find('show-id').text(),
title: $(this).find('show-title').text(),
dow: $(this).find('show-dayofweek').text(),
rhythm: $(this).find('show-rhythm').text(),
starttime: $(this).find('show-starttime').text(),
length: $(this).find('show-length').text(),
log: $(this).find('show-log').text(),
group: {
name: $(this).find('group').text(),
lowcart: $(this).find('group-low-cart').text(),
highcart: $(this).find('group-high-cart').text(),
},
normlevel: $(this).find('normalization-level').text(),
trimlevel: $(this).find('autotrim-level').text(),
}
var name = show.title + ' (' + show.rhythm + ', ' + weekday[show.dow] + ', ' + show.starttime + ', ' + show.length + ' Min.)';
$('#show-selector').append($('<option>').attr('value',show.id).text(name));
shows_list.push(show);
}
}
);
$('#show-selector').val(shows_currentid);
shows_showSelected();
}
function shows_drawCurrentWeek() {
var weekspan = $('#current-week').removeClass().addClass('label');
switch(get_rd_week()) {
case 1:
weekspan.addClass('label-info').text('Woche 1');
break;
case 2:
weekspan.addClass('label-warning').text('Woche 2');
break;
case 3:
weekspan.addClass('label-success').text('Woche 3');
break;
case 4:
weekspan.addClass('label-important').text('Woche 4');
break;
default:
weekspan.addClass('label-inverse').text('Fehler');
}
}
function shows_init() {
shows_currentid = sessionStorage.getItem("shows_currentid");
shows_list = [];
data = { LOGIN_NAME: auth_username, PASSWORD: auth_token };
$.post("/rh-bin/listdropboxes.cgi", data, shows_updateList, "xml")
shows_drawCurrentWeek();
}
function shows_cleanup() {
sessionStorage.removeItem("shows_currentid");
delete shows_currentid;
shows_list = [];
shows_group_carts = {};
shows_log_carts = [];
}
|