vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.9 KiB

  1. /**
  2. * Created by Alex on 3/5/2015.
  3. */
  4. var eventTypes = {};
  5. var buttonHammers = [];
  6. var createType = undefined;
  7. var connected = false;
  8. var selectedColor = 'white';
  9. function initButtons(data) {
  10. console.log(data)
  11. eventTypes = data;
  12. var keys = Object.keys(data);
  13. for (var i = 0; i < keys.length; i++) {
  14. createButton(keys[i])
  15. }
  16. }
  17. function selectColor(color,id) {
  18. selectedColor = color;
  19. var colors = ['colorRed','colorWhite','colorGreen','colorOrange','colorMagenta'];
  20. for (var i = 0; i < colors.length; i++) {
  21. var classname = document.getElementById(colors[i]).className.replace("selected","");
  22. document.getElementById(colors[i]).className = classname;
  23. }
  24. document.getElementById(id).className = document.getElementById(id).className += " selected";
  25. }
  26. function createButton(name) {
  27. var container = document.getElementById("buttonBunch");
  28. var button = document.createElement("button");
  29. button.type = "button";
  30. button.className = "btn btn-primary " + eventTypes[name].class;
  31. button.innerHTML = name;
  32. container.appendChild(button);
  33. var hammer = Hammer(button, {prevent_default: true});
  34. hammer.on('tap', showOverlay.bind(this,name));
  35. buttonHammers.push(hammer);
  36. }
  37. function showOverlay(name,event) {
  38. createType = name;
  39. document.getElementById("overlay").style.display = 'block';
  40. var optionsWindow = document.getElementById("newTimelineEvent");
  41. optionsWindow.style.top = event.pointers[0].pageY -100 + 'px';
  42. optionsWindow.style.left = event.pointers[0].pageX + 10 + 'px';
  43. }
  44. function newTimelineEvent() {
  45. var minutesDelay = document.getElementById("delaySelect").value;
  46. var date = new Date().valueOf() + 60 * minutesDelay * 1000;
  47. var item = {content: createType, className:eventTypes[createType].class, start:date};
  48. inputProxy.addTimelineEvent(item);
  49. hideOverlay();
  50. }
  51. function sessionClosed() {
  52. if (connected === true) {
  53. document.getElementById("overlayNC").style.display = 'block';
  54. }
  55. }
  56. function hideOverlay() {
  57. document.getElementById("overlay").style.display = 'none';
  58. }
  59. function newEvent() {
  60. var name = document.getElementById('newEvent').value;
  61. var range = false;//document.getElementById('range').checked;
  62. if (name !== "") {
  63. var data = {name: name, class: selectedColor, range: range};
  64. eventTypes[name] = data;
  65. createButton(name);
  66. inputProxy.addEventType(data);
  67. }
  68. else {
  69. alert("Name is required");
  70. }
  71. document.getElementById('newEvent').value = "";
  72. //document.getElementById('range').checked = false;
  73. }
  74. function resetEvents() {
  75. var r = confirm("Really delete all event types? (buttons below)");
  76. if (r == true) {
  77. inputProxy.resetEventTypes();
  78. document.getElementById("buttonBunch").innerHTML = "";
  79. }
  80. for (var i = 0; i < buttonHammers.length; i++) {
  81. buttonHammers[i].dispose();
  82. }
  83. buttonHammers = [];
  84. }
  85. function resetTimelineData() {
  86. var r = confirm("Really delete all data on the timeline?");
  87. if (r == true) {
  88. inputProxy.resetTimelineEvents();
  89. }
  90. }