1 function format_track(index, title, length, bpm, notes) {
2 length = Math.round(length);
3 var minutes = Math.floor(length / 60);
4 var seconds = length % 60;
5 var length = minutes + ":" + ( "0" + seconds ).slice(-2);
6 var bpm = Math.round(bpm);
7 if ( notes == null ) notes = '-';
8 entry = $('<div id="track_' + index + '" class="track" onClick="current(' + index + ');">');
9 entry.append($('<span class="index">' + index + '</span>'));
10 entry.append($('<span class="title" title="' + title + '">' + title.slice(0,65) + '</span>'));
11 entry.append($('<span class="length">' + length + '</span>'));
12 entry.append($('<span class="clear"></span>'));
13 entry.append($('<span class="bpm">' + bpm + ' BPM</span>'));
14 entry.append($('<span class="notes" title="' + notes + '">' + notes.slice(0,80) + '</span>'));
19 for (var index in tracklist) {
20 track = tracklist[index];
21 entry = format_track(track['index'], track['title'], track['length'], track['bpm'], track['notes']);
22 $('#tracks').append(entry);
26 /* Track 0 is 'no current track' */
27 function current(index) {
28 if (index < 0 || index > maximum_index)
30 current_index = index;
31 $("div.track").removeClass("current");
32 $("div.track > .index").off('click.commit');
33 $("div#track_" + index).addClass("current");
34 $("div#track_" + index + " > .index").on('click.commit', commit);
37 function updating(index) {
38 if (index < 0 || index > maximum_index)
40 $("div.track").removeClass("running sending");
41 $("div#track_" + index).addClass("sending");
44 function running(index) {
45 if (index < 0 || index > maximum_index)
47 $("div.track").removeClass("running sending");
48 $("div#track_" + index).addClass("running");
52 current(current_index + 1);
56 current(current_index - 1);
60 running_index = current_index;
66 data: { index: current_index }
69 var req = $.ajax(params)
70 .done(function(data, textStatus, req) {
73 .fail(function(req, textStatus, errorThrown) {
74 console.log("AjaxFailed:" + textStatus + " - " + errorThrown);
79 function commit_ready() {
80 running(running_index);
83 function commit_update() {
84 updating(running_index);
87 function commit_failed() {
88 current(running_index);
89 $('div.track').removeClass("running sending");
92 maximum_index = tracklist.length;
96 $(document).ready(init);