open.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. // Reads files locally
  10. function handleFiles(files)
  11. {
  12. for (var i = 0; i < files.length; i++)
  13. {
  14. (function(file)
  15. {
  16. // Small hack to support import
  17. if (window.parent.openNew)
  18. {
  19. window.parent.open(window.parent.location.href);
  20. }
  21. var reader = new FileReader();
  22. reader.onload = function(e)
  23. {
  24. window.parent.openFile.setData(e.target.result, file.name);
  25. };
  26. reader.onerror = function(e)
  27. {
  28. console.log(e);
  29. };
  30. reader.readAsText(file);
  31. })(files[i]);
  32. }
  33. };
  34. // Handles form-submit by preparing to process response
  35. function handleSubmit()
  36. {
  37. var form = window.openForm || document.getElementById('openForm');
  38. // Checks for support of the File API for local file access
  39. // except for files where the parse is on the server
  40. if (window.parent.Graph.fileSupport && form.upfile.files.length > 0)
  41. {
  42. handleFiles(form.upfile.files);
  43. return false;
  44. }
  45. else
  46. {
  47. if (/(\.xml)$/i.test(form.upfile.value) || /(\.txt)$/i.test(form.upfile.value) ||
  48. /(\.mxe)$/i.test(form.upfile.value))
  49. {
  50. // Small hack to support import
  51. if (window.parent.openNew)
  52. {
  53. window.parent.open(window.parent.location.href);
  54. }
  55. // NOTE: File is loaded via JS injection into the iframe, which in turn sets the
  56. // file contents in the parent window. The new window asks its opener if any file
  57. // contents are available or waits for the contents to become available.
  58. return true;
  59. }
  60. else
  61. {
  62. window.parent.mxUtils.alert(window.parent.mxResources.get('invalidOrMissingFile'));
  63. return false;
  64. }
  65. }
  66. };
  67. // Hides this dialog
  68. function hideWindow(cancel)
  69. {
  70. window.parent.openFile.cancel(cancel);
  71. }
  72. function fileChanged()
  73. {
  74. var form = window.openForm || document.getElementById('openForm');
  75. var openButton = document.getElementById('openButton');
  76. if (form.upfile.value.length > 0)
  77. {
  78. openButton.removeAttribute('disabled');
  79. }
  80. else
  81. {
  82. openButton.setAttribute('disabled', 'disabled');
  83. }
  84. }
  85. function main()
  86. {
  87. if (window.parent.Editor.useLocalStorage)
  88. {
  89. document.body.innerHTML = '';
  90. var div = document.createElement('div');
  91. div.style.fontFamily = 'Arial';
  92. if (localStorage.length == 0)
  93. {
  94. window.parent.mxUtils.write(div, window.parent.mxResources.get('noFiles'));
  95. }
  96. else
  97. {
  98. var keys = [];
  99. for (var i = 0; i < localStorage.length; i++)
  100. {
  101. keys.push(localStorage.key(i));
  102. }
  103. // Sorts the array by filename (key)
  104. keys.sort(function (a, b)
  105. {
  106. return a.toLowerCase().localeCompare(b.toLowerCase());
  107. });
  108. for (var i = 0; i < keys.length; i++)
  109. {
  110. var link = document.createElement('a');
  111. link.style.fontDecoration = 'none';
  112. link.style.fontSize = '14pt';
  113. var key = keys[i];
  114. window.parent.mxUtils.write(link, key);
  115. link.setAttribute('href', 'javascript:void(0);');
  116. div.appendChild(link);
  117. var img = document.createElement('span');
  118. img.className = 'geSprite geSprite-delete';
  119. img.style.position = 'relative';
  120. img.style.cursor = 'pointer';
  121. img.style.display = 'inline-block';
  122. div.appendChild(img);
  123. window.parent.mxUtils.br(div);
  124. window.parent.mxEvent.addListener(img, 'click', (function(k)
  125. {
  126. return function()
  127. {
  128. if (window.parent.mxUtils.confirm(window.parent.mxResources.get('delete') + ' "' + k + '"?'))
  129. {
  130. localStorage.removeItem(k);
  131. window.location.reload();
  132. }
  133. };
  134. })(key));
  135. window.parent.mxEvent.addListener(link, 'click', (function(k)
  136. {
  137. return function()
  138. {
  139. try
  140. {
  141. window.parent.open(window.parent.location.href);
  142. window.parent.openFile.setData(localStorage.getItem(k), k);
  143. }
  144. catch (e)
  145. {
  146. window.parent.mxUtils.alert(e.message);
  147. }
  148. };
  149. })(key));
  150. }
  151. }
  152. window.parent.mxUtils.br(div);
  153. window.parent.mxUtils.br(div);
  154. var cancelBtn = window.parent.mxUtils.button(window.parent.mxResources.get('cancel'), function()
  155. {
  156. hideWindow(true);
  157. });
  158. cancelBtn.className = 'geBtn';
  159. div.appendChild(cancelBtn);
  160. document.body.appendChild(div);
  161. }
  162. else
  163. {
  164. var editLink = document.getElementById('editLink');
  165. var openButton = document.getElementById('openButton');
  166. openButton.value = window.parent.mxResources.get(window.parent.openKey || 'open');
  167. var cancelButton = document.getElementById('cancelButton');
  168. cancelButton.value = window.parent.mxResources.get('cancel');
  169. var supportedText = document.getElementById('openSupported');
  170. supportedText.innerHTML = window.parent.mxResources.get('openSupported');
  171. var form = window.openForm || document.getElementById('openForm');
  172. form.setAttribute('action', window.parent.OPEN_URL);
  173. }
  174. };
  175. </script>
  176. <body onload="main();">
  177. <form method="POST" enctype="multipart/form-data" action="" name="openForm"
  178. id="openForm" onsubmit="return handleSubmit();" accept-charset="UTF-8">
  179. <table style="width:100%;">
  180. <tr>
  181. <td style="height:40px;vertical-align:top;" colspan="2">
  182. <input type="file" name="upfile" onchange="fileChanged()">
  183. </td>
  184. </tr>
  185. <tr>
  186. <td colspan="2" height="120px" id="openSupported" style="font-family:arial;color:grey;font-size:9pt;vertical-align:top;text-align:left;">
  187. </td>
  188. </tr>
  189. <tr>
  190. <td>
  191. </td>
  192. <td style="vertical-align:middle;text-align:right;white-space:nowrap;">
  193. <input type="button" id="cancelButton" class="geBtn" value="Cancel" onclick="hideWindow(true);">
  194. <input type="submit" id="openButton" class="geBtn gePrimaryBtn" value="Open" disabled="disabled">
  195. </td>
  196. </tr>
  197. </table>
  198. </form>
  199. </body>
  200. </html>