open.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // Handles form-submit by preparing to process response
  2. function handleSubmit()
  3. {
  4. if (window.parent.openNew && window.parent.baseUrl != null)
  5. {
  6. window.parent.openFile.setConsumer(null);
  7. window.parent.open(window.parent.baseUrl);
  8. }
  9. // NOTE: File is loaded via JS injection into the iframe, which in turn sets the
  10. // file contents in the parent window. The new window asks its opener if any file
  11. // contents are available or waits for the contents to become available.
  12. return true;
  13. };
  14. // Hides this dialog
  15. function hideWindow(cancel)
  16. {
  17. if (window.parent.openFile != null)
  18. {
  19. window.parent.openFile.cancel(cancel);
  20. }
  21. };
  22. function fileChanged()
  23. {
  24. var form = window.openForm || document.getElementById('openForm');
  25. var openButton = document.getElementById('openButton');
  26. if (form.upfile.value.length > 0)
  27. {
  28. openButton.removeAttribute('disabled');
  29. }
  30. else
  31. {
  32. openButton.setAttribute('disabled', 'disabled');
  33. }
  34. };
  35. function main()
  36. {
  37. if (window.parent != null && window.parent.Editor != null)
  38. {
  39. document.body.innerText = '';
  40. var div = document.createElement('div');
  41. div.style.fontFamily = 'Arial';
  42. var darkMode = window.parent.Editor.cssDarkMode ||
  43. (typeof window.parent.Editor.isDarkMode === 'function' &&
  44. window.parent.Editor.isDarkMode());
  45. window.parent.listBrowserFiles(function(filesInfo)
  46. {
  47. if (window.parent != null)
  48. {
  49. if (filesInfo.length == 0)
  50. {
  51. window.parent.mxUtils.write(div, window.parent.mxResources.get('noFiles'));
  52. div.style.color = (darkMode) ? '#cccccc' : '';
  53. window.parent.mxUtils.br(div);
  54. }
  55. else
  56. {
  57. // Sorts the array by filename (titles)
  58. filesInfo.sort(function (a, b)
  59. {
  60. return a.title.toLowerCase().localeCompare(b.title.toLowerCase());
  61. });
  62. var table = document.createElement('table');
  63. var hrow = document.createElement('tr');
  64. hrow.style.backgroundColor = (darkMode) ? '#000' : '#D6D6D6';
  65. hrow.style.color = (darkMode) ? '#cccccc' : '';
  66. hrow.style.height = '25px';
  67. hrow.style.textAlign = 'left';
  68. table.appendChild(hrow);
  69. var hName = document.createElement('th');
  70. window.parent.mxUtils.write(hName, window.parent.mxResources.get('name'));
  71. hrow.appendChild(hName);
  72. var hModified = document.createElement('th');
  73. hModified.style.width = '180px';
  74. window.parent.mxUtils.write(hModified, window.parent.mxResources.get('lastModified'));
  75. hrow.appendChild(hModified);
  76. var hSize = document.createElement('th');
  77. window.parent.mxUtils.write(hSize, window.parent.mxResources.get('size'));
  78. hSize.style.width = '70px';
  79. hrow.appendChild(hSize);
  80. var hCtrl = document.createElement('th');
  81. hCtrl.style.width = '23px';
  82. hrow.appendChild(hCtrl);
  83. table.style.fontSize = '12pt';
  84. table.style.width = '100%';
  85. for (var i = 0; i < filesInfo.length; i++)
  86. {
  87. var fileInfo = filesInfo[i];
  88. if (fileInfo.title.length > 0)
  89. {
  90. var row = document.createElement('tr');
  91. row.style.color = (darkMode) ? '#cccccc' : '';
  92. table.appendChild(row);
  93. if (i & 1 == 1)
  94. {
  95. row.style.backgroundColor = (darkMode) ? '#000' : '#E6E6E6';
  96. }
  97. var nameTd = document.createElement('td');
  98. row.appendChild(nameTd);
  99. var link = document.createElement('a');
  100. link.style.fontDecoration = 'none';
  101. window.parent.mxUtils.write(link, fileInfo.title);
  102. link.style.cursor = 'pointer';
  103. nameTd.appendChild(link);
  104. var modifiedTd = document.createElement('td');
  105. row.appendChild(modifiedTd);
  106. var str = window.parent.EditorUi.prototype.timeSince(new Date(fileInfo.lastModified));
  107. if (str == null)
  108. {
  109. str = window.parent.mxResources.get('lessThanAMinute');
  110. }
  111. window.parent.mxUtils.write(modifiedTd, window.parent.mxResources.get('timeAgo', [str]));
  112. var sizeTd = document.createElement('td');
  113. row.appendChild(sizeTd);
  114. window.parent.mxUtils.write(sizeTd, window.parent.EditorUi.prototype.formatFileSize(fileInfo.size));
  115. var ctrlTd = document.createElement('td');
  116. row.appendChild(ctrlTd);
  117. ctrlTd.style.textAlign = 'center';
  118. var img = document.createElement('span');
  119. img.className = 'geSprite geSprite-delete';
  120. img.style.cursor = 'pointer';
  121. img.style.display = 'inline-block';
  122. ctrlTd.appendChild(img);
  123. if (darkMode)
  124. {
  125. img.style.filter = 'invert(100%)';
  126. }
  127. window.parent.mxEvent.addListener(img, 'click', (function(k)
  128. {
  129. return function()
  130. {
  131. if (window.parent.mxUtils.confirm(window.parent.mxResources.get('delete') + ' "' + k + '"?'))
  132. {
  133. window.parent.deleteBrowserFile(k, function()
  134. {
  135. window.location.reload();
  136. });
  137. }
  138. };
  139. })(fileInfo.title));
  140. window.parent.mxEvent.addListener(link, 'click', (function(k)
  141. {
  142. return function()
  143. {
  144. if (window.parent.openNew && window.parent.baseUrl != null)
  145. {
  146. var of = window.parent.openFile;
  147. window.parent.openBrowserFile(k, function(data)
  148. {
  149. if (window.parent != null)
  150. {
  151. window.parent.geOpenWindow(window.parent.baseUrl + '#L' + encodeURIComponent(k), function()
  152. {
  153. of.cancel(false);
  154. }, function()
  155. {
  156. of.setData(data, k);
  157. });
  158. }
  159. }, function()
  160. {
  161. //TODO add error
  162. });
  163. }
  164. else
  165. {
  166. window.parent.openBrowserFile(k, function(data)
  167. {
  168. if (window.parent != null)
  169. {
  170. window.parent.openFile.setData(data, k);
  171. }
  172. }, function()
  173. {
  174. //TODO add error
  175. });
  176. }
  177. };
  178. })(fileInfo.title));
  179. }
  180. }
  181. div.appendChild(table);
  182. }
  183. var closeButton = window.parent.mxUtils.button(window.parent.mxResources.get('close'), function()
  184. {
  185. hideWindow(true);
  186. });
  187. closeButton.className = 'geBtn';
  188. closeButton.style.position = 'fixed';
  189. closeButton.style.bottom = '0px';
  190. closeButton.style.right = '0px';
  191. div.appendChild(closeButton);
  192. document.body.appendChild(div);
  193. }
  194. });
  195. }
  196. else
  197. {
  198. document.body.innerHTML = 'Missing parent window';
  199. }
  200. };
  201. window.addEventListener('load', main);