maxGraph/examples/grapheditor/www/open.html

223 lines
5.8 KiB
HTML
Raw Normal View History

2012-05-21 20:32:26 +00:00
<!DOCTYPE html>
<html>
<head>
<title>Open Diagram</title>
<link rel="stylesheet" type="text/css" href="styles/grapheditor.css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script type="text/javascript">
// Reads files locally
function handleFiles(files)
{
for (var i = 0; i < files.length; i++)
{
(function(file)
{
2012-05-30 16:26:17 +00:00
// Small hack to support import
if (window.parent.openNew)
{
window.parent.open(window.parent.location.href);
}
2012-05-21 20:32:26 +00:00
var reader = new FileReader();
reader.onload = function(e)
{
window.parent.openFile.setData(e.target.result, file.name);
};
reader.onerror = function(e)
{
console.log(e);
};
reader.readAsText(file);
})(files[i]);
}
};
// Handles form-submit by preparing to process response
function handleSubmit()
{
var form = window.openForm || document.getElementById('openForm');
// Checks for support of the File API for local file access
2016-09-07 12:29:15 +00:00
// except for files where the parse is on the server
2016-05-09 10:56:11 +00:00
if (window.parent.Graph.fileSupport && form.upfile.files.length > 0)
2012-05-21 20:32:26 +00:00
{
handleFiles(form.upfile.files);
return false;
}
else
{
if (/(\.xml)$/i.test(form.upfile.value) || /(\.txt)$/i.test(form.upfile.value) ||
/(\.mxe)$/i.test(form.upfile.value))
{
2012-05-30 16:26:17 +00:00
// Small hack to support import
if (window.parent.openNew)
{
window.parent.open(window.parent.location.href);
}
2012-05-21 20:32:26 +00:00
// NOTE: File is loaded via JS injection into the iframe, which in turn sets the
// file contents in the parent window. The new window asks its opener if any file
// contents are available or waits for the contents to become available.
return true;
}
else
{
window.parent.mxUtils.alert(window.parent.mxResources.get('invalidOrMissingFile'));
return false;
}
}
};
// Hides this dialog
2013-12-20 16:51:26 +00:00
function hideWindow(cancel)
2012-05-21 20:32:26 +00:00
{
2013-12-20 16:51:26 +00:00
window.parent.openFile.cancel(cancel);
2012-05-21 20:32:26 +00:00
}
function fileChanged()
{
var form = window.openForm || document.getElementById('openForm');
var openButton = document.getElementById('openButton');
if (form.upfile.value.length > 0)
{
openButton.removeAttribute('disabled');
}
else
{
openButton.setAttribute('disabled', 'disabled');
}
}
function main()
{
2016-05-09 10:56:11 +00:00
if (window.parent.Editor.useLocalStorage)
2012-05-21 20:32:26 +00:00
{
document.body.innerHTML = '';
var div = document.createElement('div');
div.style.fontFamily = 'Arial';
if (localStorage.length == 0)
{
window.parent.mxUtils.write(div, window.parent.mxResources.get('noFiles'));
}
else
{
var keys = [];
for (var i = 0; i < localStorage.length; i++)
{
keys.push(localStorage.key(i));
}
// Sorts the array by filename (key)
2015-08-28 13:41:48 +00:00
keys.sort(function (a, b)
{
return a.toLowerCase().localeCompare(b.toLowerCase());
});
2012-05-21 20:32:26 +00:00
for (var i = 0; i < keys.length; i++)
{
var link = document.createElement('a');
link.style.fontDecoration = 'none';
link.style.fontSize = '14pt';
var key = keys[i];
window.parent.mxUtils.write(link, key);
2020-06-19 12:31:34 +00:00
link.style.cursor = 'pointer';
2012-05-21 20:32:26 +00:00
div.appendChild(link);
var img = document.createElement('span');
2013-06-28 19:07:06 +00:00
img.className = 'geSprite geSprite-delete';
2012-05-21 20:32:26 +00:00
img.style.position = 'relative';
img.style.cursor = 'pointer';
img.style.display = 'inline-block';
div.appendChild(img);
window.parent.mxUtils.br(div);
window.parent.mxEvent.addListener(img, 'click', (function(k)
{
return function()
{
if (window.parent.mxUtils.confirm(window.parent.mxResources.get('delete') + ' "' + k + '"?'))
{
localStorage.removeItem(k);
window.location.reload();
}
};
})(key));
window.parent.mxEvent.addListener(link, 'click', (function(k)
{
return function()
{
try
{
window.parent.open(window.parent.location.href);
window.parent.openFile.setData(localStorage.getItem(k), k);
}
catch (e)
{
window.parent.mxUtils.alert(e.message);
}
};
})(key));
}
}
window.parent.mxUtils.br(div);
window.parent.mxUtils.br(div);
2014-11-28 08:55:09 +00:00
var cancelBtn = window.parent.mxUtils.button(window.parent.mxResources.get('cancel'), function()
2012-05-21 20:32:26 +00:00
{
2013-12-20 16:51:26 +00:00
hideWindow(true);
2014-11-28 08:55:09 +00:00
});
cancelBtn.className = 'geBtn';
div.appendChild(cancelBtn);
2012-05-21 20:32:26 +00:00
document.body.appendChild(div);
}
else
{
var editLink = document.getElementById('editLink');
var openButton = document.getElementById('openButton');
2012-05-30 16:26:17 +00:00
openButton.value = window.parent.mxResources.get(window.parent.openKey || 'open');
2012-05-21 20:32:26 +00:00
var cancelButton = document.getElementById('cancelButton');
cancelButton.value = window.parent.mxResources.get('cancel');
var supportedText = document.getElementById('openSupported');
supportedText.innerHTML = window.parent.mxResources.get('openSupported');
var form = window.openForm || document.getElementById('openForm');
2015-02-09 10:42:21 +00:00
2012-05-21 20:32:26 +00:00
form.setAttribute('action', window.parent.OPEN_URL);
}
};
</script>
<body onload="main();">
<form method="POST" enctype="multipart/form-data" action="" name="openForm"
id="openForm" onsubmit="return handleSubmit();" accept-charset="UTF-8">
2015-02-09 10:42:21 +00:00
<table style="width:100%;">
2012-05-21 20:32:26 +00:00
<tr>
<td style="height:40px;vertical-align:top;" colspan="2">
<input type="file" name="upfile" onchange="fileChanged()">
</td>
</tr>
<tr>
2014-06-02 08:21:19 +00:00
<td colspan="2" height="120px" id="openSupported" style="font-family:arial;color:grey;font-size:9pt;vertical-align:top;text-align:left;">
2012-05-21 20:32:26 +00:00
</td>
</tr>
<tr>
<td>
</td>
<td style="vertical-align:middle;text-align:right;white-space:nowrap;">
2014-11-28 08:55:09 +00:00
<input type="button" id="cancelButton" class="geBtn" value="Cancel" onclick="hideWindow(true);">
<input type="submit" id="openButton" class="geBtn gePrimaryBtn" value="Open" disabled="disabled">
2012-05-21 20:32:26 +00:00
</td>
</tr>
</table>
</form>
</body>
</html>