open.html 5.5 KB

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