summaryrefslogtreecommitdiff
path: root/js/shows.js
blob: b0cb55b78c6f0e30002fad58f28e01df4b6ddc68 (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
166
167
168
169
170
171
172
173
174
var shows_currentid;
var shows_list = [];
var shows_current;
var shows_group_carts = {};
var shows_log_carts = [];

function shows_deleteCart(cart) {
  alert('removing cart: ' + cart);
}

function shows_importCart(cart) {
  alert('removing cart: ' + cart);
}

// <td>
//   <button class="btn btn-info btn-mini disabled"><i class="icon-arrow-up icon-white"></i></button>
//   <button class="btn btn-info btn-mini disabled"><i class="icon-arrow-down icon-white"></i></button>
//   <button class="btn btn-danger btn-mini"><i class="icon-trash icon-white"></i> Löschen</button>
// </td>
// <td>
//   <button class="btn btn-info btn-mini"><i class="icon-arrow-up icon-white"></i></button>
//   <button class="btn btn-info btn-mini disabled"><i class="icon-arrow-down icon-white"></i></button>
//   <button class="btn btn-success btn-mini"><i class="icon-upload icon-white"></i> Importieren</button>
// </td>

function shows_udpateCartListing() {
  $('#show-carts tbody').find('tr').remove();
  $('#show-info-dumper').text(
     'Current Show:\n' + JSON.stringify(shows_current, null, ' ') +
     '\n\nGroup Carts:\n' + JSON.stringify(shows_group_carts, null, ' ') +
     '\n\nLog Carts:\n' + JSON.stringify(shows_log_carts, null, ' ')
   );

  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 ? 
          '<button class="btn btn-danger btn-mini" onclick="shows_deleteCart(' + elem + ');">' +
             '<i class="icon-trash icon-white"></i> Löschen</button>' : 
          '<button class="btn btn-success btn-mini" onclick="shows_importCart(' + elem + ');">' + 
             '<i class="icon-upload icon-white"></i> Importieren</button>';

    $('#show-carts > tbody:last').append(
      $('<tr>').append($('<td>').text(elem))
               .append($('<td>').text(cart.title))
               .append($('<td>').text(cart.length))
               .append($('<td>').text(cart.imported))
               .append($('<td>').text(cart.playcnt))
               .append($('<td>').text(cart.lastplayed))
               .append($('<td>').append(buttons))
      );
    });
}

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('showid').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(),
          group: {
            name: $(this).find('group').text(),
            lowcart: $(this).find('group-low-cart').text(),
            highcart: $(this).find('group-high-cart').text(),
          },
          log: $(this).find('log').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($('<option>').attr('value',show.id).text(name));

        shows_list.push(show);
      }
    }
  );
  $('#show-selector').val(shows_currentid);
  shows_showSelected();
}

function shows_init() {
  shows_currentid = sessionStorage.getItem("shows_currentid");
  shows_list = [];
  data = { LOGIN_NAME: auth_username, PASSWORD: auth_token };
  $.post("/listdropboxes.cgi", data, shows_updateList, "xml")
}

function shows_cleanup() {
  sessionStorage.removeItem("shows_currentid");
  delete shows_currentid;
  shows_list = [];
  shows_group_carts = {};
  shows_log_carts = [];
}