blob: abe966bd19178f1f3ce6da885ec32e4c2ac44c80 [file] [log] [blame]
Paul Greyson7a300822013-04-09 12:57:49 -07001function updateControllers() {
Paul Greysond20d22e2013-04-09 14:34:53 -07002 var controllers = d3.select('#controllers').selectAll('.controller').data(model.controllers);
Paul Greyson7a300822013-04-09 12:57:49 -07003 controllers.enter().append('div')
4 .each(function (c) {
5 controllerColorMap[c] = colors.pop();
6 d3.select(document.body).classed(controllerColorMap[c] + '-selected', true);
7 })
8 .text(function (d) {
9 return d;
10 })
11 .append('div')
12 .attr('class', 'black-eye');
13
14 controllers.attr('class', function (d) {
15 var color = 'colorInactive';
16 if (model.activeControllers.indexOf(d) != -1) {
17 color = controllerColorMap[d];
18 }
19 var className = 'controller ' + color;
20 return className;
21 });
22
23 // this should never be needed
24 // controllers.exit().remove();
25
26 controllers.on('dblclick', function (c) {
27 if (model.activeControllers.indexOf(c) != -1) {
28 var prompt = 'Dectivate ' + c + '?';
29 if (confirm(prompt)) {
30 controllerDown(c);
31 setPending(d3.select(this));
32 };
33 } else {
34 var prompt = 'Activate ' + c + '?';
35 if (confirm(prompt)) {
36 controllerUp(c);
37 setPending(d3.select(this));
38 };
39 }
40 });
41
42 controllers.select('.black-eye').on('click', function (c) {
43 var allSelected = true;
44 for (var key in controllerColorMap) {
45 if (!d3.select(document.body).classed(controllerColorMap[key] + '-selected')) {
46 allSelected = false;
47 break;
48 }
49 }
50 if (allSelected) {
51 for (var key in controllerColorMap) {
52 d3.select(document.body).classed(controllerColorMap[key] + '-selected', key == c)
53 }
54 } else {
55 for (var key in controllerColorMap) {
56 d3.select(document.body).classed(controllerColorMap[key] + '-selected', true)
57 }
58 }
59
60 // var selected = d3.select(document.body).classed(controllerColorMap[c] + '-selected');
61 // d3.select(document.body).classed(controllerColorMap[c] + '-selected', !selected);
62 });
63
64
65}