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(shows_showSelected); } function shows_importCartCancel(cart, dz) { var cart_row = $('#show-cart-' + cart) cart_row.next().remove(); cart_row.find('.btn').removeAttr('disabled'); cart_row.after(shows_getDzStat(true)); // TODO: cancel upload } 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); // call dz.processQueue() } function shows_createImportForm(cart) { return $('
').attr("action", "/rd-bin/rdxport.cgi").attr("method", "post").attr("enctype", "multipart/form-data") .append($('').attr("type", "hidden").attr("name", "COMMAND").attr("value", 2)) .append($('').attr("type", "hidden").attr("name", "LOGIN_NAME").attr("value", auth_username)) .append($('').attr("type", "hidden").attr("name", "PASSWORD").attr("value", auth_token)) .append($('').attr("type", "hidden").attr("name", "CART_NUMBER").attr("value", cart)) .append($('').attr("type", "hidden").attr("name", "CUT_NUMBER").attr("value", 1)) .append($('').attr("type", "hidden").attr("name", "CHANNELS").attr("value", 2)) .append($('').attr("type", "hidden").attr("name", "NORMALIZATION_LEVEL").attr("value", shows_current.normlevel)) .append($('').attr("type", "hidden").attr("name", "AUTOTRIM_LEVEL").attr("value", shows_current.trimlevel)) .append($('').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_importFileError(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_importFileError(this, file, msg); }); }}); $('#shows-upload').modal({ keyboard: true }); } // // // // // // // // // // function shows_getDzStat(empty) { if(empty) { return $('').append($('').css("border", 0) .css("height", 0) .css("margin", 0) .css("padding", 0)); } else { var progress_bar = '
'; var cancel_button = ''; return $('').append($('').text('filename.flac')) .append($('').text('xx of XX Bytes')) .append($('').append(progress_bar)) .append($('').append(cancel_button)); } } function shows_udpateCartListing() { $('#show-carts tbody').find('tr').remove(); shows_log_carts.forEach(function(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 ? '' : ''; $('#show-carts > tbody:last').append( $('').append($('').text(elem)) .append($('').text(cart.title)) .append($('').text(cart.length)) .append($('').text(cart.imported)) .append($('').text(cart.playcnt)) .append($('').text(cart.lastplayed)) .append($('').append(buttons)).attr("id", "show-cart-" + elem) ).append(shows_getDzStat(true)); }); } function shows_updateGroupCartList(data, status, req) { shows_group_carts = {}; 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: $(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) { shows_log_carts = []; 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($('