summaryrefslogtreecommitdiff
path: root/www/js/jingles.js
blob: c32c42433ec61415fde6d94aa409ae0891c0a6fa (plain)
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
/*
 *  rhwebimport
 *
 *  Copyright (C) 2014-2015 Christian Pointner <equinox@helsinki.at>
 *  Copyright (C) 2015 Peter Grassberger <petertheone@gmail.at>
 *
 *  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 <http://www.gnu.org/licenses/>.
 */

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 $('<tr>').append($('<td>').text(this.name))
    .append($('<td>').text(this.description))
    .append($('<td>'))//.text(msToTimeString(cart.length)))
    .append($('<td>'))//.text(cart.imported))
    .append($('<td>'))//.text(cart.playcnt))
    .append($('<td>'))//.text(cart.lastplayed))
    .append($('<td>'));//.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;
}