open.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Open Diagram</title>
  5. <link rel="stylesheet" type="text/css" href="styles/grapheditor.css" />
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. </head>
  8. <script type="text/javascript">
  9. // Handles form-submit by preparing to process response
  10. function handleSubmit()
  11. {
  12. var form = window.openForm || document.getElementById('openForm');
  13. if (window.parent.openNew && window.parent.baseUrl != null)
  14. {
  15. window.parent.openFile.setConsumer(null);
  16. window.parent.open(window.parent.baseUrl);
  17. }
  18. // NOTE: File is loaded via JS injection into the iframe, which in turn sets the
  19. // file contents in the parent window. The new window asks its opener if any file
  20. // contents are available or waits for the contents to become available.
  21. return true;
  22. };
  23. // Hides this dialog
  24. function hideWindow(cancel)
  25. {
  26. window.parent.openFile.cancel(cancel);
  27. }
  28. function fileChanged()
  29. {
  30. var supportedText = document.getElementById('openSupported');
  31. var form = window.openForm || document.getElementById('openForm');
  32. var openButton = document.getElementById('openButton');
  33. if (form.upfile.value.length > 0)
  34. {
  35. openButton.removeAttribute('disabled');
  36. }
  37. else
  38. {
  39. openButton.setAttribute('disabled', 'disabled');
  40. }
  41. }
  42. function main()
  43. {
  44. if (window.parent.Editor.useLocalStorage)
  45. {
  46. document.body.innerHTML = '';
  47. var div = document.createElement('div');
  48. div.style.fontFamily = 'Arial';
  49. var keys = [];
  50. for (var i = 0; i < localStorage.length; i++)
  51. {
  52. var key = localStorage.key(i);
  53. var value = localStorage.getItem(key);
  54. console.log('key', key, value);
  55. if (key.length > 0 && key.charAt(0) != '.' && value.length > 0 &&
  56. (value.substring(0, 8) === '<mxfile ' ||
  57. value.substring(0, 11) === '<mxlibrary>'))
  58. {
  59. keys.push(key);
  60. }
  61. }
  62. if (keys.length == 0)
  63. {
  64. window.parent.mxUtils.write(div, window.parent.mxResources.get('noFiles'));
  65. window.parent.mxUtils.br(div);
  66. }
  67. else
  68. {
  69. // Sorts the array by filename (key)
  70. keys.sort(function (a, b)
  71. {
  72. return a.toLowerCase().localeCompare(b.toLowerCase());
  73. });
  74. for (var i = 0; i < keys.length; i++)
  75. {
  76. var key = keys[i];
  77. // Ignores "dot" files and dropbox cookies
  78. if (key.length > 0)
  79. {
  80. var link = document.createElement('a');
  81. link.style.fontDecoration = 'none';
  82. link.style.fontSize = '14pt';
  83. window.parent.mxUtils.write(link, key);
  84. link.setAttribute('href', 'javascript:void(0);');
  85. div.appendChild(link);
  86. var img = document.createElement('span');
  87. img.className = 'geSprite geSprite-delete';
  88. img.style.position = 'relative';
  89. img.style.cursor = 'pointer';
  90. img.style.display = 'inline-block';
  91. img.style.cssFloat = 'right';
  92. img.style.styleFloat = 'right';
  93. img.style.paddingRight = '20px';
  94. div.appendChild(img);
  95. window.parent.mxUtils.br(div);
  96. window.parent.mxEvent.addListener(img, 'click', (function(k)
  97. {
  98. return function()
  99. {
  100. if (window.parent.mxUtils.confirm(window.parent.mxResources.get('delete') + ' "' + k + '"?'))
  101. {
  102. localStorage.removeItem(k);
  103. window.location.reload();
  104. }
  105. };
  106. })(key));
  107. window.parent.mxEvent.addListener(link, 'click', (function(k)
  108. {
  109. return function()
  110. {
  111. if (window.parent.openNew && window.parent.baseUrl != null)
  112. {
  113. var of = window.parent.openFile;
  114. var data = localStorage.getItem(k);
  115. window.parent.openWindow(window.parent.baseUrl + '#L' + encodeURIComponent(k), function()
  116. {
  117. of.cancel(false);
  118. }, function()
  119. {
  120. of.setData(data, k);
  121. });
  122. }
  123. else
  124. {
  125. window.parent.openFile.setData(localStorage.getItem(k), k);
  126. }
  127. };
  128. })(key));
  129. }
  130. }
  131. }
  132. window.parent.mxUtils.br(div);
  133. var closeButton = window.parent.mxUtils.button(window.parent.mxResources.get('close'), function()
  134. {
  135. hideWindow(true);
  136. });
  137. closeButton.className = 'geBtn';
  138. div.appendChild(closeButton);
  139. document.body.appendChild(div);
  140. }
  141. else
  142. {
  143. var editLink = document.getElementById('editLink');
  144. var openButton = document.getElementById('openButton');
  145. openButton.value = window.parent.mxResources.get(window.parent.openKey || 'open');
  146. var closeButton = document.getElementById('closeButton');
  147. closeButton.value = window.parent.mxResources.get('close');
  148. var supportedText = document.getElementById('openSupported');
  149. supportedText.innerHTML = window.parent.mxResources.get('openSupported');
  150. var form = window.openForm || document.getElementById('openForm');
  151. form.setAttribute('action', window.parent.OPEN_URL);
  152. }
  153. };
  154. </script>
  155. <body onload="main();">
  156. <form method="POST" enctype="multipart/form-data" action="" name="openForm"
  157. id="openForm" onsubmit="return handleSubmit();" accept-charset="UTF-8">
  158. <table style="width:100%;">
  159. <tr>
  160. <td style="height:40px;vertical-align:top;" colspan="2">
  161. <input type="file" name="upfile" onchange="fileChanged()">
  162. </td>
  163. </tr>
  164. <tr>
  165. <td colspan="2" height="120px" id="openSupported" style="font-family:arial;color:grey;font-size:9pt;vertical-align:top;text-align:left;">
  166. </td>
  167. </tr>
  168. <tr>
  169. <td>
  170. </td>
  171. <td style="vertical-align:middle;text-align:right;white-space:nowrap;">
  172. <input type="button" id="closeButton" class="geBtn" value="Cancel" onclick="hideWindow(true);">
  173. <input type="submit" id="openButton" class="geBtn gePrimaryBtn" value="Open" disabled="disabled">
  174. </td>
  175. </tr>
  176. </table>
  177. </form>
  178. </body>
  179. </html>