example07_confirm_changes.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <html>
  2. <head>
  3. <title>Timeline demo</title>
  4. <style>
  5. body {font: 10pt arial;}
  6. </style>
  7. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  8. <script type="text/javascript" src="../timeline.js"></script>
  9. <link rel="stylesheet" type="text/css" href="../timeline.css">
  10. <script type="text/javascript">
  11. var timeline = undefined;
  12. var data = undefined;
  13. google.load("visualization", "1");
  14. // Set callback to run when API is loaded
  15. google.setOnLoadCallback(drawVisualization);
  16. function getSelectedRow() {
  17. var row = undefined
  18. var sel = timeline.getSelection();
  19. if (sel.length) {
  20. if (sel[0].row != undefined) {
  21. var row = sel[0].row;
  22. }
  23. }
  24. return row;
  25. }
  26. // Called when the Visualization API is loaded.
  27. function drawVisualization() {
  28. // Create and populate a data table.
  29. data = new google.visualization.DataTable();
  30. data.addColumn('datetime', 'start');
  31. data.addColumn('datetime', 'end');
  32. data.addColumn('string', 'content');
  33. data.addRows([
  34. [new Date(2010,07,23), , '<div>Conversation</div><img src="img/comments-icon.png" style="width:32px; height:32px;">'],
  35. [new Date(2010,07,23,23,00,00), , '<div>Mail from boss</div><img src="img/mail-icon.png" style="width:32px; height:32px;">'],
  36. [new Date(2010,07,24,16,00,00), , 'Report'],
  37. [new Date(2010,07,26), new Date(2010,08,02), 'Traject A'],
  38. [new Date(2010,07,28), , '<div>Memo</div><img src="img/notes-edit-icon.png" style="width:48px; height:48px;">'],
  39. [new Date(2010,07,29), , '<div>Phone call</div><img src="img/Hardware-Mobile-Phone-icon.png" style="width:32px; height:32px;">'],
  40. [new Date(2010,07,31), new Date(2010,08,03), 'Traject B'],
  41. [new Date(2010,08,04,12,00,00), , '<div>Report</div><img src="img/attachment-icon.png" style="width:32px; height:32px;">']
  42. ]);
  43. // specify options
  44. options = {
  45. width: "100%",
  46. height: "300px",
  47. editable: true // make the events dragable
  48. };
  49. // Instantiate our timeline object.
  50. timeline = new links.Timeline(document.getElementById('mytimeline'));
  51. // Make a callback function for the select event
  52. var onselect = function (event) {
  53. var row = getSelectedRow();
  54. document.getElementById("info").innerHTML += "event " + row + " selected<br>";
  55. // Note: you can retrieve the contents of the selected row with
  56. // data.getValue(row, 2);
  57. }
  58. // callback function for the change event
  59. var onchange = function (event) {
  60. // retrieve the changed row
  61. var row = getSelectedRow();
  62. if (row != undefined) {
  63. // request approval from the user.
  64. // You can choose your own approval mechanism here, for example
  65. // send data to a server which responds with approved/denied
  66. var approve = confirm("Are you sure you want to move the event?");
  67. if (approve) {
  68. document.getElementById("info").innerHTML += "event " + row + " changed<br>";
  69. } else {
  70. // new date NOT approved. cancel the change
  71. timeline.cancelChange();
  72. document.getElementById("info").innerHTML += "change of event " + row + " cancelled<br>";
  73. }
  74. }
  75. }
  76. // callback function for the delete event
  77. var ondelete = function (event) {
  78. // retrieve the row to be deleted
  79. var row = getSelectedRow();
  80. if (row != undefined) {
  81. // request approval from the user.
  82. // You can choose your own approval mechanism here, for example
  83. // send data to a server which responds with approved/denied
  84. var approve = confirm("Are you sure you want to delete the event?");
  85. if (approve) {
  86. document.getElementById("info").innerHTML += "event " + row + " deleted<br>";
  87. } else {
  88. // new date NOT approved. cancel the change
  89. timeline.cancelDelete();
  90. document.getElementById("info").innerHTML += "deleting event " + row + " cancelled<br>";
  91. }
  92. }
  93. }
  94. // callback function for adding an event
  95. var onadd = function (event) {
  96. // retrieve the row to be deleted
  97. var row = getSelectedRow();
  98. if (row != undefined) {
  99. // request approval from the user.
  100. // You can choose your own approval mechanism here, for example
  101. // send data to a server which responds with approved/denied
  102. var title = prompt("Enter a title for the new event", "New event");
  103. if (title != undefined) {
  104. data.setValue(row, 2, title);
  105. document.getElementById("info").innerHTML += "event " + row + " created<br>";
  106. timeline.redraw();
  107. } else {
  108. // cancel adding a new event
  109. timeline.cancelAdd();
  110. document.getElementById("info").innerHTML += "creating event " + row + " cancelled<br>";
  111. }
  112. }
  113. }
  114. // Add event listeners
  115. google.visualization.events.addListener(timeline, 'select', onselect);
  116. google.visualization.events.addListener(timeline, 'change', onchange);
  117. google.visualization.events.addListener(timeline, 'delete', ondelete);
  118. google.visualization.events.addListener(timeline, 'add', onadd);
  119. // Draw our timeline with the created data and options
  120. timeline.draw(data, options);
  121. }
  122. </script>
  123. </head>
  124. <body>
  125. <p>This page demonstrates the timeline visualization.</p>
  126. <p>Click and drag to move the timeline, scroll to zoom the timeline.
  127. Click and drag events to change there date.
  128. You will be asked for confirmation before changes are actually applied.</p>
  129. <div id="mytimeline"></div>
  130. <!-- Information about where the used icons come from -->
  131. <p style="color:gray; font-size:10px; font-style:italic;">
  132. Icons by <a href="http://dryicons.com" target="_blank" title="Aesthetica 2 Icons by DryIcons" style="color:gray;" >DryIcons</a>
  133. and <a href="http://www.tpdkdesign.net" target="_blank" title="Refresh Cl Icons by TpdkDesign.net" style="color:gray;" >TpdkDesign.net</a>
  134. </p>
  135. <div id="info"></div>
  136. </body>
  137. </html>