From ca488f8d3609500b89b95c6c2ff6c533e62a7aea Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Fri, 5 Feb 2016 01:07:47 +0100 Subject: rename rivendell.js to rdxport.js diff --git a/www/index.html b/www/index.html index 2a3f28f..706a190 100644 --- a/www/index.html +++ b/www/index.html @@ -18,8 +18,8 @@ - - + + diff --git a/www/js/apps.js b/www/js/apps.js index 1c04526..ab5d4b9 100644 --- a/www/js/apps.js +++ b/www/js/apps.js @@ -101,7 +101,7 @@ function apps_init() { if(auth_token && auth_username) { // todo: do this at a central place - rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi'); + rivendell = new Rivendell.Rdxport(auth_username, auth_token, '/rd-bin/rdxport.cgi'); rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi'); rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi'); @@ -111,7 +111,7 @@ function apps_init() { $(window).on('popstate', function(event) { if(auth_token && auth_username) { // todo: do this at a central place - rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi'); + rivendell = new Rivendell.Rdxport(auth_username, auth_token, '/rd-bin/rdxport.cgi'); rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi'); rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi'); diff --git a/www/js/auth.js b/www/js/auth.js index c9fe52e..df09ce6 100644 --- a/www/js/auth.js +++ b/www/js/auth.js @@ -39,7 +39,7 @@ function auth_loginSuccess(data) { sessionStorage.setItem("auth_token", auth_token); // todo: do this at a central place - rivendell = new Rivendell.Rivendell(auth_username, auth_token, '/rd-bin/rdxport.cgi'); + rivendell = new Rivendell.Rdxport(auth_username, auth_token, '/rd-bin/rdxport.cgi'); rivendell.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi'); rivendell.setMusicgridEndpoint('/rh-bin/musicgrid.cgi'); @@ -89,7 +89,7 @@ function auth_init() { $("#loginform").submit(function(event) { event.preventDefault(); - Rivendell.Rivendell.authLogin( + Rivendell.Rdxport.authLogin( '/rh-bin/authtoken.json', $("#username").val(), $("#password").val(), diff --git a/www/js/rdxport.js b/www/js/rdxport.js new file mode 100644 index 0000000..633b89e --- /dev/null +++ b/www/js/rdxport.js @@ -0,0 +1,472 @@ +/* + * 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.Rdxport = function(username, token, endpoint) { + this.username = username; + this.token = token; + this.endpoint = endpoint; +}; + +Rivendell.Rdxport.prototype.listLog = function(name, success) { + var command = { + COMMAND: 22, + LOGIN_NAME: this.username, + PASSWORD: this.token, + NAME: name + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listLogs = function(success) { + var command = { + COMMAND: 20, + LOGIN_NAME: this.username, + PASSWORD: this.token + //todo: fix optionals + /*SERVICE_NAME: serviceName, + TRACKABLE: trackable*/ + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listServices = function(success) { + var command = { + COMMAND: 21, + LOGIN_NAME: this.username, + PASSWORD: this.token + //todo: fix optionals + /*TRACKABLE: trackable*/ + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listGroups = function(success) { + var command = { + COMMAND: 4, + LOGIN_NAME: this.username, + PASSWORD: this.token + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listGroup = function(groupName, success) { + var command = { + COMMAND: 5, + LOGIN_NAME: this.username, + PASSWORD: this.token, + GROUP_NAME: groupName + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listCarts = function(groupName, includeCuts, success) { + var command = { + COMMAND: 6, + LOGIN_NAME: this.username, + PASSWORD: this.token, + GROUP_NAME: groupName, + INCLUDE_CUTS: includeCuts + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listCart = function(cartNumber, includeCuts, success) { + var command = { + COMMAND: 7, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + INCLUDE_CUTS: includeCuts + }; + return $.post(this.endpoint, command, success); +}; + +Rivendell.Rdxport.prototype.addCart = function(groupName, type, cartNumber, success) { + var command = { + COMMAND: 12, + LOGIN_NAME: this.username, + PASSWORD: this.token, + GROUP_NAME: groupName, + TYPE: type + }; + if (cartNumber !== null) { + command.CART_NUMBER = cartNumber; + } + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.editCart = function(cartNumber, options, success) { + options.COMMAND = 14; + options.LOGIN_NAME = this.username; + options.PASSWORD = this.token; + options.CART_NUMBER = cartNumber; + return $.post(this.endpoint, options, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.removeCart = function(cartNumber, success) { + var command = { + COMMAND: 13, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listCuts = function(cartNumber, success) { + var command = { + COMMAND: 9, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.listCut = function(cartNumber, cutNumber, success) { + var command = { + COMMAND: 8, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.addCut = function(cartNumber, success) { + var command = { + COMMAND: 10, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.editCut = function(cartNumber, cutNumber, options, success) { + options.COMMAND = 15; + options.LOGIN_NAME = this.username; + options.PASSWORD = this.token; + options.CART_NUMBER = cartNumber; + options.CUT_NUMBER = cutNumber; + return $.post(this.endpoint, options, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.addAndEditCut = function(cartNumber, options, success) { + var self = this; + var returnJqXHR = null; + return this.addCut(cartNumber, success) + .success(function(data, textStatus, jqXHR) { + var cutNumber = $('cutAdd cut cutNumber', data).text(); + returnJqXHR = self.editCut(cartNumber, cutNumber, options, null); + }); +}; + +Rivendell.Rdxport.prototype.removeCut = function(cartNumber, cutNumber, success) { + var command = { + COMMAND: 11, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +/** + * + * todo: copy description and other data. + * + * @param sourceCartNumber + * @param sourceCutNumber + * @param destinationCartNumber + * @param success + * @returns {*} + */ +Rivendell.Rdxport.prototype.copyCut = function(sourceCartNumber, sourceCutNumber, + destinationCartNumber, success) { + var self = this; + var returnJqXHR = null; + this.listCut(sourceCartNumber, sourceCutNumber, function(data, textStatus, jqXHR) { + var options = { + DESCRIPTION: $('cutList cut description', data).text() + // todo: add more options + }; + self.addAndEditCut(destinationCartNumber, options, function(data, textStatus, jqXHR) { + var destinationCutNumber = $('cutAdd cut cutNumber', data).text(); + returnJqXHR = self.copyAudio(sourceCartNumber,sourceCutNumber, destinationCartNumber, destinationCutNumber, success) + .fail(function() { + self.removeCut(destinationCartNumber, destinationCutNumber, null); + }); + }); + }); + return returnJqXHR; +}; + +/** + * + * @param sourceCartNumber + * @param sourceCutNumber + * @param destinationCartNumber + * @param success + */ +Rivendell.Rdxport.prototype.moveCut = function(sourceCartNumber, sourceCutNumber, + destinationCartNumber, success) { + var self = this; + var returnJqXHR = null; + this.copyCut(sourceCartNumber, sourceCutNumber, destinationCartNumber, function(data, textStatus, jqXHR) { + returnJqXHR = self.removeCut(sourceCartNumber, sourceCutNumber, success); + }); + return returnJqXHR; +}; + +Rivendell.Rdxport.prototype.copyAudio = function(sourceCartNumber, sourceCutNumber, + destinationCartNumber, destinationCutNumber, success) { + var command = { + COMMAND: 18, + LOGIN_NAME: this.username, + PASSWORD: this.token, + SOURCE_CART_NUMBER: sourceCartNumber, + SOURCE_CUT_NUMBER: sourceCutNumber, + DESTINATION_CART_NUMBER: destinationCartNumber, + DESTINATION_CUT_NUMBER: destinationCutNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.audioInfo = function(cartNumber, cutNumber, success) { + var command = { + COMMAND: 19, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.audioStore = function(success) { + var command = { + COMMAND: 23, + LOGIN_NAME: this.username, + PASSWORD: this.token + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.import = function(cartNumber, cutNumber, channels, normalizationLevel, autotrimLevel, + useMetadata, filename, success) { + var command = { + COMMAND: 2, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber, + CHANNELS: channels, + NORMALIZATION_LEVEL: normalizationLevel, + AUTOTRIM_LEVEL: autotrimLevel, + USE_METADATA: useMetadata, + FILENAME: filename + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.export = function(cartNumber, cutNumber, format, channels, sampleRate, bitRate, + quality, startPoint, endPoint, normalizationLevel, enableMetadata, + success) { + var command = { + COMMAND: 1, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber, + FORMAT: format, + CHANNELS: channels, + SAMPLE_RATE: sampleRate, + BIT_RATE: bitRate, + QUALITY: quality, + START_POINT: startPoint, + END_POINT: endPoint, + NORMALIZATION_LEVEL: normalizationLevel, + ENABLE_METADATA: enableMetadata + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.exportPeaks = function(cartNumber, cutNumber, success) { + var command = { + COMMAND: 16, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.trimAudio = function(cartNumber, cutNumber, trimLevel, success) { + var command = { + COMMAND: 17, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber, + TRIM_LEVEL: trimLevel + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.Rdxport.prototype.deleteAudio = function(cartNumber, cutNumber, success) { + var command = { + COMMAND: 3, + LOGIN_NAME: this.username, + PASSWORD: this.token, + CART_NUMBER: cartNumber, + CUT_NUMBER: cutNumber + }; + return $.post(this.endpoint, command, success, 'xml'); +}; + +Rivendell.GroupList = function(rivendell) { + this.rivendell = rivendell; + + this.groups = []; +}; + +Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, trimlevel) { + this.xml = null; + + if (arguments.length === 1) { + this.xml = arguments[0]; + this.groupName = $('group', this.xml).text(); + this.description = $('group-description', this.xml).text(); + this.lowcart = $('group-low-cart', this.xml).text(); + this.highcart = $('group-high-cart', this.xml).text(); + this.normlevel = $('normalization-level', this.xml).text(); + this.trimlevel = $('autotrim-level', this.xml).text(); + } else { + this.groupName = groupName; + this.description = description; + this.lowcart = lowcart; + this.highcart = highcart; + this.normlevel = normlevel; + this.trimlevel = trimlevel; + } + + this.carts = []; +}; + +Rivendell.Group.prototype.addCart = function(cart) { + this.carts.push(cart); +}; + +Rivendell.Group.prototype.removeCart = function(cart) { + var self = this; + $.each(this.carts, function(index, currentCart){ + if(currentCart === cart) { + self.carts.splice(index, 1); + } + }); +}; + +Rivendell.Group.prototype.fetchCarts = function() { + var self = this; + rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) { + self.carts = []; + + var dbs = $('cartList', cartsXml).children(); + dbs.each(function(index, cartXml) { + var cart = new Rivendell.Cart(cartXml, self); + + var cuts = $('cutList', cartXml).children(); + cuts.each(function(index, cut) { + cart.cuts.push(new Rivendell.Cut(cut, cart)); + }); + + self.carts.push(cart); + }); + $(self).trigger('update'); + }); +}; + +Rivendell.Cart = function(number, title, groupName, group) { + this.xml = null; + + if (arguments.length === 2) { + this.xml = arguments[0]; + this.number = $('number', this.xml).text(); + this.title = $('title', this.xml).text(); + this.groupName = $('groupName', this.xml).text(); + this.group = arguments[1]; + } else { + this.number = number; + this.title = title; + this.groupName = groupName; + this.group = group; + } + + this.cuts = []; +}; + +Rivendell.Cart.prototype.addCut = function(cut) { + this.cuts.push(cut); +}; + +Rivendell.Cart.prototype.removeCut = function(cut) { + var self = this; + $.each(this.cuts, function(index, currentCut){ + if(currentCut === cut) { + self.cuts.splice(index, 1); + } + }); +}; + +Rivendell.Cut = function(name, description, cart, length, originDatetime, + playCounter, lastPlayDatetime) { + this.xml = null; + + if (arguments.length === 2) { + this.xml = arguments[0]; + this.name = $('cutName', this.xml).text(); + this.description = $('description', this.xml).text(); + this.length = $('length', this.xml).text(); + this.originDatetime = $('originDatetime', this.xml).text(); + this.playCounter = $('playCounter', this.xml).text(); + this.lastPlayDatetime = $('lastPlayDatetime', this.xml).text(); + this.cart = arguments[1]; + } else { + this.name = name; + this.description = description; + this.cart = cart; + this.length = length; + this.originDatetime = originDatetime; + this.playCounter = playCounter; + this.lastPlayDatetime = lastPlayDatetime; + } + this.number = this.name.substr(-3); + this.cartNumber = this.cart.number; +}; diff --git a/www/js/rdxport.rh.js b/www/js/rdxport.rh.js new file mode 100644 index 0000000..a80e6de --- /dev/null +++ b/www/js/rdxport.rh.js @@ -0,0 +1,152 @@ +/* + * 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.Rdxport.authLogin = function(authEndpoint, username, password, success) { + return $.ajax(authEndpoint, { + username: username, + password: password, + success: success, + dataType: 'json', + cache: false + }); +}; + +Rivendell.Rdxport.prototype.setListDropboxesEndpoint = function(listDropboxesEndpoint) { + this.listDropboxesEndpoint = listDropboxesEndpoint; +}; + +Rivendell.Rdxport.prototype.setMusicgridEndpoint = function(musicgridEndpoint) { + this.musicgridEndpoint = musicgridEndpoint; +}; + +Rivendell.Rdxport.prototype.listDropboxes = function(type, success) { + var command = { + LOGIN_NAME: this.username, + PASSWORD: this.token + }; + if (type !== null) { + command.TYPE = type; + } + return $.post(this.listDropboxesEndpoint, command, success, 'xml'); +}; + +// see: https://github.com/ElvishArtisan/rivendell/pull/100 +Rivendell.Rdxport.prototype.addAndEditCut = function(cartNumber, options, success) { + options.COMMAND = 10; + options.LOGIN_NAME = this.username; + options.PASSWORD = this.token; + options.CART_NUMBER = cartNumber; + return $.post(this.endpoint, options, success, "xml"); +}; + +// todo: addAndEditCart + +Rivendell.Rdxport.prototype.getMusicgrid = function(success) { + var command = { + LOGIN_NAME: this.username, + PASSWORD: this.token + }; + return $.get(this.musicgridEndpoint, command, success, "xml"); +}; + +Rivendell.Rdxport.prototype.setMusicgrid = function(dow, hour, name, success) { + var command = { + LOGIN_NAME: this.username, + PASSWORD: this.token, + DOW: dow, + HOUR: hour, + NAME: name + }; + return $.post(this.musicgridEndpoint, command, success, "xml"); +}; + +Rivendell.GroupList.prototype.fetch = function(type) { + this.groups = []; + + var self = this; + this.rivendell.listDropboxes(type, function(groupsXml, status, req) { + var dbs = $('dropboxList', groupsXml).children(); + dbs.each(function(index, groupXml) { + var group = null; + switch ($('type', groupXml).text()) { + /*case 'show': + // todo + break;*/ + case 'jingle': + group = new Rivendell.JingleGroup(groupXml); + break; + case 'musicpool': + group = new Rivendell.Musicpool(groupXml); + break; + default: + group = new Rivendell.Group(groupXml); + break; + } + + if (group !== null) { + self.groups.push(group); + } + }); + + $(self).trigger('update'); + }); +}; + +Rivendell.Musicgrid = function() { + this.clocks = []; +}; + +Rivendell.Musicgrid.prototype.fetch = function() { + this.clocks = []; + + var self = this; + rivendell.getMusicgrid(function(gridXml, status, req) { + var dbs = $('grid', gridXml).children(); + dbs.each(function(index, clockXml) { + self.clocks.push(new Rivendell.MusicgridClock(clockXml)); + }); + $(self).trigger('update'); + }); +}; + +Rivendell.MusicgridClock = function(name, color, title, dow, hour) { + this.xml = null; + + if (arguments.length === 1) { + this.xml = arguments[0]; + this.name = $('name', this.xml).text(); + this.color = $('color', this.xml).text(); + this.title = $('title', this.xml).text(); + this.dow = $(this.xml).attr('dow'); + this.hour = $(this.xml).attr('hour'); + } else { + this.name = name; + this.color = color; + this.title = title; + this.dow = dow; + this.hour = hour; + } +}; diff --git a/www/js/rivendell.js b/www/js/rivendell.js deleted file mode 100644 index 0f4bcda..0000000 --- a/www/js/rivendell.js +++ /dev/null @@ -1,472 +0,0 @@ -/* - * 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.Rivendell = function(username, token, rdxportEndpoint) { - this.username = username; - this.token = token; - this.rdxportEndpoint = rdxportEndpoint; -}; - -Rivendell.Rivendell.prototype.listLog = function(name, success) { - var command = { - COMMAND: 22, - LOGIN_NAME: this.username, - PASSWORD: this.token, - NAME: name - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listLogs = function(success) { - var command = { - COMMAND: 20, - LOGIN_NAME: this.username, - PASSWORD: this.token - //todo: fix optionals - /*SERVICE_NAME: serviceName, - TRACKABLE: trackable*/ - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listServices = function(success) { - var command = { - COMMAND: 21, - LOGIN_NAME: this.username, - PASSWORD: this.token - //todo: fix optionals - /*TRACKABLE: trackable*/ - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listGroups = function(success) { - var command = { - COMMAND: 4, - LOGIN_NAME: this.username, - PASSWORD: this.token - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listGroup = function(groupName, success) { - var command = { - COMMAND: 5, - LOGIN_NAME: this.username, - PASSWORD: this.token, - GROUP_NAME: groupName - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listCarts = function(groupName, includeCuts, success) { - var command = { - COMMAND: 6, - LOGIN_NAME: this.username, - PASSWORD: this.token, - GROUP_NAME: groupName, - INCLUDE_CUTS: includeCuts - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listCart = function(cartNumber, includeCuts, success) { - var command = { - COMMAND: 7, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - INCLUDE_CUTS: includeCuts - }; - return $.post(this.rdxportEndpoint, command, success); -}; - -Rivendell.Rivendell.prototype.addCart = function(groupName, type, cartNumber, success) { - var command = { - COMMAND: 12, - LOGIN_NAME: this.username, - PASSWORD: this.token, - GROUP_NAME: groupName, - TYPE: type - }; - if (cartNumber !== null) { - command.CART_NUMBER = cartNumber; - } - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.editCart = function(cartNumber, options, success) { - options.COMMAND = 14; - options.LOGIN_NAME = this.username; - options.PASSWORD = this.token; - options.CART_NUMBER = cartNumber; - return $.post(this.rdxportEndpoint, options, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.removeCart = function(cartNumber, success) { - var command = { - COMMAND: 13, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listCuts = function(cartNumber, success) { - var command = { - COMMAND: 9, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.listCut = function(cartNumber, cutNumber, success) { - var command = { - COMMAND: 8, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.addCut = function(cartNumber, success) { - var command = { - COMMAND: 10, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.editCut = function(cartNumber, cutNumber, options, success) { - options.COMMAND = 15; - options.LOGIN_NAME = this.username; - options.PASSWORD = this.token; - options.CART_NUMBER = cartNumber; - options.CUT_NUMBER = cutNumber; - return $.post(this.rdxportEndpoint, options, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.addAndEditCut = function(cartNumber, options, success) { - var self = this; - var returnJqXHR = null; - return this.addCut(cartNumber, success) - .success(function(data, textStatus, jqXHR) { - var cutNumber = $('cutAdd cut cutNumber', data).text(); - returnJqXHR = self.editCut(cartNumber, cutNumber, options, null); - }); -}; - -Rivendell.Rivendell.prototype.removeCut = function(cartNumber, cutNumber, success) { - var command = { - COMMAND: 11, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -/** - * - * todo: copy description and other data. - * - * @param sourceCartNumber - * @param sourceCutNumber - * @param destinationCartNumber - * @param success - * @returns {*} - */ -Rivendell.Rivendell.prototype.copyCut = function(sourceCartNumber, sourceCutNumber, - destinationCartNumber, success) { - var self = this; - var returnJqXHR = null; - this.listCut(sourceCartNumber, sourceCutNumber, function(data, textStatus, jqXHR) { - var options = { - DESCRIPTION: $('cutList cut description', data).text() - // todo: add more options - }; - self.addAndEditCut(destinationCartNumber, options, function(data, textStatus, jqXHR) { - var destinationCutNumber = $('cutAdd cut cutNumber', data).text(); - returnJqXHR = self.copyAudio(sourceCartNumber,sourceCutNumber, destinationCartNumber, destinationCutNumber, success) - .fail(function() { - self.removeCut(destinationCartNumber, destinationCutNumber, null); - }); - }); - }); - return returnJqXHR; -}; - -/** - * - * @param sourceCartNumber - * @param sourceCutNumber - * @param destinationCartNumber - * @param success - */ -Rivendell.Rivendell.prototype.moveCut = function(sourceCartNumber, sourceCutNumber, - destinationCartNumber, success) { - var self = this; - var returnJqXHR = null; - this.copyCut(sourceCartNumber, sourceCutNumber, destinationCartNumber, function(data, textStatus, jqXHR) { - returnJqXHR = self.removeCut(sourceCartNumber, sourceCutNumber, success); - }); - return returnJqXHR; -}; - -Rivendell.Rivendell.prototype.copyAudio = function(sourceCartNumber, sourceCutNumber, - destinationCartNumber, destinationCutNumber, success) { - var command = { - COMMAND: 18, - LOGIN_NAME: this.username, - PASSWORD: this.token, - SOURCE_CART_NUMBER: sourceCartNumber, - SOURCE_CUT_NUMBER: sourceCutNumber, - DESTINATION_CART_NUMBER: destinationCartNumber, - DESTINATION_CUT_NUMBER: destinationCutNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.audioInfo = function(cartNumber, cutNumber, success) { - var command = { - COMMAND: 19, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.audioStore = function(success) { - var command = { - COMMAND: 23, - LOGIN_NAME: this.username, - PASSWORD: this.token - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.import = function(cartNumber, cutNumber, channels, normalizationLevel, autotrimLevel, - useMetadata, filename, success) { - var command = { - COMMAND: 2, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber, - CHANNELS: channels, - NORMALIZATION_LEVEL: normalizationLevel, - AUTOTRIM_LEVEL: autotrimLevel, - USE_METADATA: useMetadata, - FILENAME: filename - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.export = function(cartNumber, cutNumber, format, channels, sampleRate, bitRate, - quality, startPoint, endPoint, normalizationLevel, enableMetadata, - success) { - var command = { - COMMAND: 1, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber, - FORMAT: format, - CHANNELS: channels, - SAMPLE_RATE: sampleRate, - BIT_RATE: bitRate, - QUALITY: quality, - START_POINT: startPoint, - END_POINT: endPoint, - NORMALIZATION_LEVEL: normalizationLevel, - ENABLE_METADATA: enableMetadata - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.exportPeaks = function(cartNumber, cutNumber, success) { - var command = { - COMMAND: 16, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.trimAudio = function(cartNumber, cutNumber, trimLevel, success) { - var command = { - COMMAND: 17, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber, - TRIM_LEVEL: trimLevel - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.Rivendell.prototype.deleteAudio = function(cartNumber, cutNumber, success) { - var command = { - COMMAND: 3, - LOGIN_NAME: this.username, - PASSWORD: this.token, - CART_NUMBER: cartNumber, - CUT_NUMBER: cutNumber - }; - return $.post(this.rdxportEndpoint, command, success, 'xml'); -}; - -Rivendell.GroupList = function(rivendell) { - this.rivendell = rivendell; - - this.groups = []; -}; - -Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, trimlevel) { - this.xml = null; - - if (arguments.length === 1) { - this.xml = arguments[0]; - this.groupName = $('group', this.xml).text(); - this.description = $('group-description', this.xml).text(); - this.lowcart = $('group-low-cart', this.xml).text(); - this.highcart = $('group-high-cart', this.xml).text(); - this.normlevel = $('normalization-level', this.xml).text(); - this.trimlevel = $('autotrim-level', this.xml).text(); - } else { - this.groupName = groupName; - this.description = description; - this.lowcart = lowcart; - this.highcart = highcart; - this.normlevel = normlevel; - this.trimlevel = trimlevel; - } - - this.carts = []; -}; - -Rivendell.Group.prototype.addCart = function(cart) { - this.carts.push(cart); -}; - -Rivendell.Group.prototype.removeCart = function(cart) { - var self = this; - $.each(this.carts, function(index, currentCart){ - if(currentCart === cart) { - self.carts.splice(index, 1); - } - }); -}; - -Rivendell.Group.prototype.fetchCarts = function() { - var self = this; - rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) { - self.carts = []; - - var dbs = $('cartList', cartsXml).children(); - dbs.each(function(index, cartXml) { - var cart = new Rivendell.Cart(cartXml, self); - - var cuts = $('cutList', cartXml).children(); - cuts.each(function(index, cut) { - cart.cuts.push(new Rivendell.Cut(cut, cart)); - }); - - self.carts.push(cart); - }); - $(self).trigger('update'); - }); -}; - -Rivendell.Cart = function(number, title, groupName, group) { - this.xml = null; - - if (arguments.length === 2) { - this.xml = arguments[0]; - this.number = $('number', this.xml).text(); - this.title = $('title', this.xml).text(); - this.groupName = $('groupName', this.xml).text(); - this.group = arguments[1]; - } else { - this.number = number; - this.title = title; - this.groupName = groupName; - this.group = group; - } - - this.cuts = []; -}; - -Rivendell.Cart.prototype.addCut = function(cut) { - this.cuts.push(cut); -}; - -Rivendell.Cart.prototype.removeCut = function(cut) { - var self = this; - $.each(this.cuts, function(index, currentCut){ - if(currentCut === cut) { - self.cuts.splice(index, 1); - } - }); -}; - -Rivendell.Cut = function(name, description, cart, length, originDatetime, - playCounter, lastPlayDatetime) { - this.xml = null; - - if (arguments.length === 2) { - this.xml = arguments[0]; - this.name = $('cutName', this.xml).text(); - this.description = $('description', this.xml).text(); - this.length = $('length', this.xml).text(); - this.originDatetime = $('originDatetime', this.xml).text(); - this.playCounter = $('playCounter', this.xml).text(); - this.lastPlayDatetime = $('lastPlayDatetime', this.xml).text(); - this.cart = arguments[1]; - } else { - this.name = name; - this.description = description; - this.cart = cart; - this.length = length; - this.originDatetime = originDatetime; - this.playCounter = playCounter; - this.lastPlayDatetime = lastPlayDatetime; - } - this.number = this.name.substr(-3); - this.cartNumber = this.cart.number; -}; diff --git a/www/js/rivendell.rh.js b/www/js/rivendell.rh.js deleted file mode 100644 index a41ccd3..0000000 --- a/www/js/rivendell.rh.js +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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.Rivendell.authLogin = function(authEndpoint, username, password, success) { - return $.ajax(authEndpoint, { - username: username, - password: password, - success: success, - dataType: 'json', - cache: false - }); -}; - -Rivendell.Rivendell.prototype.setListDropboxesEndpoint = function(listDropboxesEndpoint) { - this.listDropboxesEndpoint = listDropboxesEndpoint; -}; - -Rivendell.Rivendell.prototype.setMusicgridEndpoint = function(musicgridEndpoint) { - this.musicgridEndpoint = musicgridEndpoint; -}; - -Rivendell.Rivendell.prototype.listDropboxes = function(type, success) { - var command = { - LOGIN_NAME: this.username, - PASSWORD: this.token - }; - if (type !== null) { - command.TYPE = type; - } - return $.post(this.listDropboxesEndpoint, command, success, 'xml'); -}; - -// see: https://github.com/ElvishArtisan/rivendell/pull/100 -Rivendell.Rivendell.prototype.addAndEditCut = function(cartNumber, options, success) { - options.COMMAND = 10; - options.LOGIN_NAME = this.username; - options.PASSWORD = this.token; - options.CART_NUMBER = cartNumber; - return $.post(this.rdxportEndpoint, options, success, "xml"); -}; - -// todo: addAndEditCart - -Rivendell.Rivendell.prototype.getMusicgrid = function(success) { - var command = { - LOGIN_NAME: this.username, - PASSWORD: this.token - }; - return $.get(this.musicgridEndpoint, command, success, "xml"); -}; - -Rivendell.Rivendell.prototype.setMusicgrid = function(dow, hour, name, success) { - var command = { - LOGIN_NAME: this.username, - PASSWORD: this.token, - DOW: dow, - HOUR: hour, - NAME: name - }; - return $.post(this.musicgridEndpoint, command, success, "xml"); -}; - -Rivendell.GroupList.prototype.fetch = function(type) { - this.groups = []; - - var self = this; - this.rivendell.listDropboxes(type, function(groupsXml, status, req) { - var dbs = $('dropboxList', groupsXml).children(); - dbs.each(function(index, groupXml) { - var group = null; - switch ($('type', groupXml).text()) { - /*case 'show': - // todo - break;*/ - case 'jingle': - group = new Rivendell.JingleGroup(groupXml); - break; - case 'musicpool': - group = new Rivendell.Musicpool(groupXml); - break; - default: - group = new Rivendell.Group(groupXml); - break; - } - - if (group !== null) { - self.groups.push(group); - } - }); - - $(self).trigger('update'); - }); -}; - -Rivendell.Musicgrid = function() { - this.clocks = []; -}; - -Rivendell.Musicgrid.prototype.fetch = function() { - this.clocks = []; - - var self = this; - rivendell.getMusicgrid(function(gridXml, status, req) { - var dbs = $('grid', gridXml).children(); - dbs.each(function(index, clockXml) { - self.clocks.push(new Rivendell.MusicgridClock(clockXml)); - }); - $(self).trigger('update'); - }); -}; - -Rivendell.MusicgridClock = function(name, color, title, dow, hour) { - this.xml = null; - - if (arguments.length === 1) { - this.xml = arguments[0]; - this.name = $('name', this.xml).text(); - this.color = $('color', this.xml).text(); - this.title = $('title', this.xml).text(); - this.dow = $(this.xml).attr('dow'); - this.hour = $(this.xml).attr('hour'); - } else { - this.name = name; - this.color = color; - this.title = title; - this.dow = dow; - this.hour = hour; - } -}; -- cgit v0.10.2