/* * rhwebimport * * Copyright (C) 2014-2016 Christian Pointner * Copyright (C) 2015-2016 Peter Grassberger * * 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 . */ 'use strict'; var Rivendell = Rivendell || {}; Rivendell.Importer = function() { this.$el = $('#uploadModal'); }; Rivendell.Importer.prototype.showUploadModal = function(group) { $('div.modal-header h3', this.$el).text("Datei auswählen..."); var form = $('
'); $('.modal-body', uploadModal).empty().append(form).css("background-image", "url('/img/dz-backdrop.png')"); var self = this; var dropzone = form.dropzone({ url: '/rd-bin/rdxport.cgi', parallelUploads: 1, maxFilesize: 2048, paramName: 'FILENAME', uploadMultiple: false, // todo: maybe enable this? clickable: true, createImageThumbnails: false, acceptedFiles: '.flac,.wav,.ogg,.mp3', autoProcessQueue: false, init: function() { this.on("addedfile", function(file) { self.importFileAdded(this, file, group); }); this.on("error", function(file, msg) { self.importFileSelectError(this, file, msg); }); } }); this.$el.modal({keyboard: true}); }; Rivendell.Importer.prototype.importFileAdded = function(dropzone, file, group) { $(dropzone.getAcceptedFiles()).each(function(idx, elem) { dropzone.removeFile(elem); }); $('div.modal-body', this.$el).css("background-image", "url('/img/audio_file.png')"); $('div.modal-header h3', this.$el).text(file.name); var self = this; $('#uploadModal-confirm', this.$el).unbind('click').click(function() { self.importCartConfirm(dropzone, group); }).removeAttr('disabled'); }; Rivendell.Importer.prototype.importFileSelectError = function(dropzone, file, msg) { $('div.modal-header h3', this.$el).text("Datei auswählen..."); $('div.modal-body', this.$el).css("background-image", "url('/img/dz-backdrop.png')"); $('#uploadModal-confirm', this.$el).attr('disabled','disabled').unbind('click'); dropzone.removeFile(file); }; Rivendell.Importer.prototype.importCartConfirm = function(dz, group) { this.$el.modal('hide'); //var progressBar = group.addUpload(); //var cart_row = $('#show-cart-' + cart); //cart_row.find('.btn').attr('disabled','disabled'); //var importing_row = jingles_newImportingEntry(cart); //importing_row.find('button').unbind('click').click(function() { jingles_importCartCancel(cart, dz); }); //cart_row.replaceWith(importing_row); dz.off("error"); var files = dz.getAcceptedFiles(); //importing_row.find('.file-name').text(files[0].name); //jingles_importUpdateProgress(files[0], importing_row); var self = this; dz.on('uploadprogress', function(file) { self.uploadProgress(file); }); dz.on('success', function(file) { self.importFileUploadSuccess(dz, file, group); }); dz.on('error', function(file, msg, xhr) { self.importFileUploadError(this, file, msg, xhr); }); /*$(files).each(function(index, file) { self.importAddCut(dz, group, file); });*/ self.importAddCut(dz, group, files[0]); }; Rivendell.Importer.prototype.uploadProgress = function(file) { if (!file.cartNumber || !file.cutNumber) { return; } var $cut = $('#jingle-' + file.cartNumber + '-' + file.cutNumber).first(); if (!$cut.hasClass('uploading')) { var $progressBar = $('.progressBarTemplate').clone().removeClass('progressBarTemplate'); $cut.html($progressBar.html()); $cut.addClass('uploading'); } if(file.upload.progress < 99) { var bytes_str = Number((file.upload.bytesSent/1024)/1024).toFixed(1) + " von " + Number((file.upload.total/1024)/1024).toFixed(1) + " MB"; $cut.find('.file-bytes').text(bytes_str); $cut.find('.progress .bar').css("width", file.upload.progress + "%"); } else { $cut.find('.file-bytes').text('importiere...'); $cut.find('.progress .bar').css('width', '100%'); $cut.find('.progress').addClass('progress-striped').addClass('active'); } }; Rivendell.Importer.prototype.importFileUploadSuccess = function(dz, file, group) { //var command = { LOGIN_NAME: auth_username, PASSWORD: auth_token, DESCRIPTION: file. }; //jingles_updateGroupCartInfo(cart); dz.disable(); //progressBar.remove(); group.fetchCarts(); //$(this.currentGroup.mainCart).trigger('add'); }; Rivendell.Importer.prototype.importFileUploadError = function(dz, file, msg, xhr) { //var error_row = jingles_newImportErrorEntry(cart, msg); //error_row.find('button').unbind('click').click(function() { //jingles_deleteCart(cart); //}); //$('#show-cart-' + cart).replaceWith(error_row); //error_row.find('.file-name').text(file.name); dz.disable(); }; Rivendell.Importer.prototype.importAddCut = function(dz, group, file) { var cart = group.mainCart; rivendell.addAndEditCut(cart.number, {DESCRIPTION: file.name}, function(cutXml) { group.fetchCarts(); dz.on('sending', function(file, xhr, formData) { var cutNumber = $(cutXml).find('cutNumber').text(); var cutNumberLeading = cutNumber; switch (cutNumber.toString().length) { case 0: cutNumberLeading = '000' + cutNumber; break; case 1: cutNumberLeading = '00' + cutNumber; break; case 2: cutNumberLeading = '0' + cutNumber; break; case 3: default: cutNumberLeading = cutNumber; break; } file.cartNumber = cart.number; file.cutNumber = cutNumberLeading; formData.append('COMMAND', 2); formData.append('LOGIN_NAME', auth_username); formData.append('PASSWORD', auth_token); formData.append('CART_NUMBER', cart.number); formData.append('CUT_NUMBER', cutNumber); formData.append('CHANNELS', 2); formData.append('NORMALIZATION_LEVEL', cart.normlevel); formData.append('AUTOTRIM_LEVEL', cart.trimlevel); formData.append('USE_METADATA', 0); // don't set USE_METADATA 1 for jingles }); dz.processQueue(); }).fail(function(xhr, status, err) { self.importFileUploadError(cart, dz, file, err, xhr); }); };