open.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. if (key.length > 0 && key.charAt(0) != '.' && value.length > 0 &&
  55. (value.substring(0, 8) === '<mxfile ' ||
  56. value.substring(0, 11) === '<mxlibrary>'))
  57. {
  58. keys.push(key);
  59. }
  60. }
  61. if (keys.length == 0)
  62. {
  63. window.parent.mxUtils.write(div, window.parent.mxResources.get('noFiles'));
  64. window.parent.mxUtils.br(div);
  65. }
  66. else
  67. {
  68. // Sorts the array by filename (key)
  69. keys.sort(function (a, b)
  70. {
  71. return a.toLowerCase().localeCompare(b.toLowerCase());
  72. });
  73. for (var i = 0; i < keys.length; i++)
  74. {
  75. var key = keys[i];
  76. // Ignores "dot" files and dropbox cookies
  77. if (key.length > 0)
  78. {
  79. var link = document.createElement('a');
  80. link.style.fontDecoration = 'none';
  81. link.style.fontSize = '14pt';
  82. window.parent.mxUtils.write(link, key);
  83. link.setAttribute('href', 'javascript:void(0);');
  84. div.appendChild(link);
  85. var img = document.createElement('span');
  86. img.className = 'geSprite geSprite-delete';
  87. img.style.position = 'relative';
  88. img.style.cursor = 'pointer';
  89. img.style.display = 'inline-block';
  90. img.style.cssFloat = 'right';
  91. img.style.styleFloat = 'right';
  92. img.style.paddingRight = '20px';
  93. div.appendChild(img);
  94. window.parent.mxUtils.br(div);
  95. window.parent.mxEvent.addListener(img, 'click', (function(k)
  96. {
  97. return function()
  98. {
  99. if (window.parent.mxUtils.confirm(window.parent.mxResources.get('delete') + ' "' + k + '"?'))
  100. {
  101. localStorage.removeItem(k);
  102. window.location.reload();
  103. }
  104. };
  105. })(key));
  106. window.parent.mxEvent.addListener(link, 'click', (function(k)
  107. {
  108. return function()
  109. {
  110. if (window.parent.openNew && window.parent.baseUrl != null)
  111. {
  112. var of = window.parent.openFile;
  113. var data = localStorage.getItem(k);
  114. window.parent.openWindow(window.parent.baseUrl + '#L' + encodeURIComponent(k), function()
  115. {
  116. of.cancel(false);
  117. }, function()
  118. {
  119. of.setData(data, k);
  120. });
  121. }
  122. else
  123. {
  124. window.parent.openFile.setData(localStorage.getItem(k), k);
  125. }
  126. };
  127. })(key));
  128. }
  129. }
  130. }
  131. window.parent.mxUtils.br(div);
  132. var closeButton = window.parent.mxUtils.button(window.parent.mxResources.get('close'), function()
  133. {
  134. hideWindow(true);
  135. });
  136. closeButton.className = 'geBtn';
  137. div.appendChild(closeButton);
  138. document.body.appendChild(div);
  139. }
  140. else
  141. {
  142. var editLink = document.getElementById('editLink');
  143. var openButton = document.getElementById('openButton');
  144. openButton.value = window.parent.mxResources.get(window.parent.openKey || 'open');
  145. var closeButton = document.getElementById('closeButton');
  146. closeButton.value = window.parent.mxResources.get('close');
  147. var supportedText = document.getElementById('openSupported');
  148. supportedText.innerHTML = window.parent.mxResources.get('openSupported');
  149. var form = window.openForm || document.getElementById('openForm');
  150. form.setAttribute('action', window.parent.OPEN_URL);
  151. }
  152. };
  153. </script>
  154. <body onload="main();">
  155. <form method="POST" enctype="multipart/form-data" action="" name="openForm"
  156. id="openForm" onsubmit="return handleSubmit();" accept-charset="UTF-8">
  157. <table style="width:100%;">
  158. <tr>
  159. <td style="height:40px;vertical-align:top;" colspan="2">
  160. <input type="file" name="upfile" onchange="fileChanged()">
  161. </td>
  162. </tr>
  163. <tr>
  164. <td colspan="2" height="120px" id="openSupported" style="font-family:arial;color:grey;font-size:9pt;vertical-align:top;text-align:left;">
  165. </td>
  166. </tr>
  167. <tr>
  168. <td>
  169. </td>
  170. <td style="vertical-align:middle;text-align:right;white-space:nowrap;">
  171. <input type="button" id="closeButton" class="geBtn" value="Cancel" onclick="hideWindow(true);">
  172. <input type="submit" id="openButton" class="geBtn gePrimaryBtn" value="Open" disabled="disabled">
  173. </td>
  174. </tr>
  175. </table>
  176. </form>
  177. </body>
  178. </html>