blob: 501ac1dd768b501cb8dccd826bda60fccaac30f5 [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 Greyson900ecc52013-04-10 17:02:27 -070029 var that = this;
Paul Greyson28cf92b2013-04-10 13:15:06 -070030 doConfirm(prompt, function (result) {
31 if (result) {
32 controllerDown(c);
Paul Greyson900ecc52013-04-10 17:02:27 -070033 setPending(d3.select(that));
Paul Greyson28cf92b2013-04-10 13:15:06 -070034 };
35 })
Paul Greyson7a300822013-04-09 12:57:49 -070036 } else {
37 var prompt = 'Activate ' + c + '?';
Paul Greyson900ecc52013-04-10 17:02:27 -070038 var that = this;
Paul Greyson28cf92b2013-04-10 13:15:06 -070039 doConfirm(prompt, function (result) {
40 if (result) {
41 controllerUp(c);
Paul Greyson900ecc52013-04-10 17:02:27 -070042 setPending(d3.select(that));
Paul Greyson28cf92b2013-04-10 13:15:06 -070043 };
44 });
Paul Greyson7a300822013-04-09 12:57:49 -070045 }
46 });
47
48 controllers.select('.black-eye').on('click', function (c) {
49 var allSelected = true;
50 for (var key in controllerColorMap) {
51 if (!d3.select(document.body).classed(controllerColorMap[key] + '-selected')) {
52 allSelected = false;
53 break;
54 }
55 }
56 if (allSelected) {
57 for (var key in controllerColorMap) {
58 d3.select(document.body).classed(controllerColorMap[key] + '-selected', key == c)
59 }
60 } else {
61 for (var key in controllerColorMap) {
62 d3.select(document.body).classed(controllerColorMap[key] + '-selected', true)
63 }
64 }
65
66 // var selected = d3.select(document.body).classed(controllerColorMap[c] + '-selected');
67 // d3.select(document.body).classed(controllerColorMap[c] + '-selected', !selected);
68 });
69
70
71}