Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 1 | function updateControllers() { |
Paul Greyson | d20d22e | 2013-04-09 14:34:53 -0700 | [diff] [blame] | 2 | var controllers = d3.select('#controllers').selectAll('.controller').data(model.controllers); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 3 | 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 Greyson | 900ecc5 | 2013-04-10 17:02:27 -0700 | [diff] [blame] | 29 | var that = this; |
Paul Greyson | 28cf92b | 2013-04-10 13:15:06 -0700 | [diff] [blame] | 30 | doConfirm(prompt, function (result) { |
| 31 | if (result) { |
| 32 | controllerDown(c); |
Paul Greyson | 900ecc5 | 2013-04-10 17:02:27 -0700 | [diff] [blame] | 33 | setPending(d3.select(that)); |
Paul Greyson | 28cf92b | 2013-04-10 13:15:06 -0700 | [diff] [blame] | 34 | }; |
| 35 | }) |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 36 | } else { |
| 37 | var prompt = 'Activate ' + c + '?'; |
Paul Greyson | 900ecc5 | 2013-04-10 17:02:27 -0700 | [diff] [blame] | 38 | var that = this; |
Paul Greyson | 28cf92b | 2013-04-10 13:15:06 -0700 | [diff] [blame] | 39 | doConfirm(prompt, function (result) { |
| 40 | if (result) { |
| 41 | controllerUp(c); |
Paul Greyson | 900ecc5 | 2013-04-10 17:02:27 -0700 | [diff] [blame] | 42 | setPending(d3.select(that)); |
Paul Greyson | 28cf92b | 2013-04-10 13:15:06 -0700 | [diff] [blame] | 43 | }; |
| 44 | }); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 45 | } |
| 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 | } |