blob: 513799b80d678bddf164438a2274b3402858d264 [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 + '?';
Paul Greyson28cf92b2013-04-10 13:15:06 -070029 doConfirm(prompt, function (result) {
30 if (result) {
31 controllerDown(c);
32 setPending(d3.select(this));
33 };
34 })
Paul Greyson7a300822013-04-09 12:57:49 -070035 } else {
36 var prompt = 'Activate ' + c + '?';
Paul Greyson28cf92b2013-04-10 13:15:06 -070037 doConfirm(prompt, function (result) {
38 if (result) {
39 controllerUp(c);
40 setPending(d3.select(this));
41 };
42 });
Paul Greyson7a300822013-04-09 12:57:49 -070043 }
44 });
45
46 controllers.select('.black-eye').on('click', function (c) {
47 var allSelected = true;
48 for (var key in controllerColorMap) {
49 if (!d3.select(document.body).classed(controllerColorMap[key] + '-selected')) {
50 allSelected = false;
51 break;
52 }
53 }
54 if (allSelected) {
55 for (var key in controllerColorMap) {
56 d3.select(document.body).classed(controllerColorMap[key] + '-selected', key == c)
57 }
58 } else {
59 for (var key in controllerColorMap) {
60 d3.select(document.body).classed(controllerColorMap[key] + '-selected', true)
61 }
62 }
63
64 // var selected = d3.select(document.body).classed(controllerColorMap[c] + '-selected');
65 // d3.select(document.body).classed(controllerColorMap[c] + '-selected', !selected);
66 });
67
68
69}