/* * rhwebimport * * Copyright (C) 2014-2015 Christian Pointner * * 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 . */ var JingleGroupList = function() { this.groups = []; $(this).on('change', this.render); this.fetchGroups(); }; JingleGroupList.prototype.fetchGroups = function() { console.log('fetchGroups JingleGroupList'); var self = this; data = { LOGIN_NAME: auth_username, PASSWORD: auth_token }; $.post("/rh-bin/listdropboxes.cgi", data, function(groupsXml, status, req) { var dbs = $(groupsXml).find("dropboxList").children(); dbs.each(function(index, groupXml) { type = $(groupXml).find('type').text(); if (type == 'jingle') { var jingleGroup = new JingleGroup( $(groupXml).find('jingle-title').text(), $(groupXml).find('group').text(), $(groupXml).find('group-description').text(), $(groupXml).find('group-low-cart').text(), $(groupXml).find('group-high-cart').text(), $(groupXml).find('normalization-level').text(), $(groupXml).find('autotrim-level').text() ); $(jingleGroup).on('change', function() { $(self).trigger('change'); }); self.groups.push(jingleGroup); } }); }, "xml"); }; JingleGroupList.prototype.render = function() { console.log('render JingleGroupList'); $.each(this.groups, function(index, group) { group.render(); }); }; var JingleGroup = function(title, groupName, description, lowcart, highcart, normlevel, trimlevel) { this.title = title; this.groupName = groupName; this.description = description; this.lowcart = lowcart; this.highcart = highcart; this.normlevel = normlevel; this.trimlevel = trimlevel; this.mainCart = null; this.deleteCart = null; this.fetchCarts(); }; JingleGroup.prototype.render = function() { console.log('render JingleGroup'); if (this.groupName === 'jingAllgem') { $('#jingles-jingAllgem table tbody').find('tr').remove(); $.each(this.mainCart.cuts, function(index, cut) { $('#jingles-jingAllgem table > tbody').append(cut.$el()); }); } else if (this.groupName === 'jingAllgem') { $('#jingles-jingAnlass table tbody').find('tr').remove(); $.each(this.mainCart.cuts, function(index, cut) { $('#jingles-jingAnlass table > tbody').append(cut.$el()); }); } }; JingleGroup.prototype.fetchCarts = function() { console.log('fetchGroups JingleGroup'); var self = this; data = { COMMAND: 7, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: this.lowcart, INCLUDE_CUTS: 1 }; gcd = $.post("/rd-bin/rdxport.cgi", data, function(cartXml) { self.mainCart = self.createCartFromXml(cartXml); $(self).trigger('change'); }, "xml"); data = { COMMAND: 7, LOGIN_NAME: auth_username, PASSWORD: auth_token, CART_NUMBER: this.highcart, INCLUDE_CUTS: 1 }; gcd = $.post("/rd-bin/rdxport.cgi", data, function(cartXml) { self.deleteCart = self.createCartFromXml(cartXml); }, "xml"); }; JingleGroup.prototype.createCartFromXml = function(cartXml) { var cart = new JingleCart( $(cartXml).find('title').text(), $(cartXml).find('groupName').text() ); var cuts = $(cartXml).find("cutList").children(); cuts.each(function(index, cutXml) { cart.addCut(new JingleCut( $(cutXml).find('cutName').text(), $(cutXml).find('description').text() )); }); return cart; }; var JingleCart = function(title, groupName) { this.title = title; this.groupName = groupName; this.cuts = []; }; JingleCart.prototype.addCut = function(cut) { this.cuts.push(cut); }; var JingleCut = function(name, description) { this.name = name; this.description = description; }; JingleCut.prototype.$el = function() { return $('').append($('').text(this.name)) .append($('').text(this.description)) .append($(''))//.text(msToTimeString(cart.length))) .append($(''))//.text(cart.imported)) .append($(''))//.text(cart.playcnt)) .append($(''))//.text(cart.lastplayed)) .append($(''));//.css('text-align', 'center').append(buttons)) //.attr("id", "show-cart-" + elem); }; var jinglesGroupList = null; function jingles_init() { jinglesGroupList = new JingleGroupList(); } function jingles_cleanup() { jinglesGroupList = null; }