Advertisement
jobinrjohnson

jgraph / drawio

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