How to create new Image in draw.io and Save it database from within my website?
I have created a dummy image in my jsp file.
<img id="image" style="max-width:100%;cursor:pointer;" onclick="editDiagram(this); " src="data:image/png;base64,iVBORw0K.....>
On clicking the dummy image the a .js function editDiagram is called which in turn opens draw.io in an iFrame and provide option to make new image and save it.
function editDiagram(image)
{
var initial = image.getAttribute('src');
image.setAttribute('src', 'http://www.draw.io/images/ajax-loader.gif');
var iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
var close = function()
{
image.setAttribute('src', initial);
document.body.removeChild(iframe);
window.removeEventListener('message', receive);
};
var receive = function(evt)
{
if (evt.data.length > 0)
{
var msg = JSON.parse(evt.data);
if (msg.event == 'init')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'load',
xmlpng: initial}), '*');
}
else if (msg.event == 'export')
{
close();
image.setAttribute('src', msg.data);
save(location.href);
}
else if (msg.event == 'save')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'export',
format: 'xmlpng', spin: 'Updating page'}), '*');
}
else if (msg.event == 'exit')
{
close();
}
}
};
window.addEventListener('message', receive);
iframe.setAttribute('src', 'https://www.draw.io/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json');
document.body.appendChild(iframe);
};
function save(url)
{
if (url != null)
{
var req = new XMLHttpRequest();
req.withCredentials = true;
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status < 200 || req.status > 299)
{
alert('Error ' + req.status);
}
}
};
req.open('PUT', url, true);
req.send(document.documentElement.outerHTML);
}
}
But when i create the new image and click save the new image is not displayed in the webpage, instead only the dummmy image that fires the .js file is only shown. How do I show the new image in my website and replace the dummy image and also save it in Database ?
javascript jsp draw.io
add a comment |
I have created a dummy image in my jsp file.
<img id="image" style="max-width:100%;cursor:pointer;" onclick="editDiagram(this); " src="data:image/png;base64,iVBORw0K.....>
On clicking the dummy image the a .js function editDiagram is called which in turn opens draw.io in an iFrame and provide option to make new image and save it.
function editDiagram(image)
{
var initial = image.getAttribute('src');
image.setAttribute('src', 'http://www.draw.io/images/ajax-loader.gif');
var iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
var close = function()
{
image.setAttribute('src', initial);
document.body.removeChild(iframe);
window.removeEventListener('message', receive);
};
var receive = function(evt)
{
if (evt.data.length > 0)
{
var msg = JSON.parse(evt.data);
if (msg.event == 'init')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'load',
xmlpng: initial}), '*');
}
else if (msg.event == 'export')
{
close();
image.setAttribute('src', msg.data);
save(location.href);
}
else if (msg.event == 'save')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'export',
format: 'xmlpng', spin: 'Updating page'}), '*');
}
else if (msg.event == 'exit')
{
close();
}
}
};
window.addEventListener('message', receive);
iframe.setAttribute('src', 'https://www.draw.io/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json');
document.body.appendChild(iframe);
};
function save(url)
{
if (url != null)
{
var req = new XMLHttpRequest();
req.withCredentials = true;
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status < 200 || req.status > 299)
{
alert('Error ' + req.status);
}
}
};
req.open('PUT', url, true);
req.send(document.documentElement.outerHTML);
}
}
But when i create the new image and click save the new image is not displayed in the webpage, instead only the dummmy image that fires the .js file is only shown. How do I show the new image in my website and replace the dummy image and also save it in Database ?
javascript jsp draw.io
add a comment |
I have created a dummy image in my jsp file.
<img id="image" style="max-width:100%;cursor:pointer;" onclick="editDiagram(this); " src="data:image/png;base64,iVBORw0K.....>
On clicking the dummy image the a .js function editDiagram is called which in turn opens draw.io in an iFrame and provide option to make new image and save it.
function editDiagram(image)
{
var initial = image.getAttribute('src');
image.setAttribute('src', 'http://www.draw.io/images/ajax-loader.gif');
var iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
var close = function()
{
image.setAttribute('src', initial);
document.body.removeChild(iframe);
window.removeEventListener('message', receive);
};
var receive = function(evt)
{
if (evt.data.length > 0)
{
var msg = JSON.parse(evt.data);
if (msg.event == 'init')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'load',
xmlpng: initial}), '*');
}
else if (msg.event == 'export')
{
close();
image.setAttribute('src', msg.data);
save(location.href);
}
else if (msg.event == 'save')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'export',
format: 'xmlpng', spin: 'Updating page'}), '*');
}
else if (msg.event == 'exit')
{
close();
}
}
};
window.addEventListener('message', receive);
iframe.setAttribute('src', 'https://www.draw.io/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json');
document.body.appendChild(iframe);
};
function save(url)
{
if (url != null)
{
var req = new XMLHttpRequest();
req.withCredentials = true;
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status < 200 || req.status > 299)
{
alert('Error ' + req.status);
}
}
};
req.open('PUT', url, true);
req.send(document.documentElement.outerHTML);
}
}
But when i create the new image and click save the new image is not displayed in the webpage, instead only the dummmy image that fires the .js file is only shown. How do I show the new image in my website and replace the dummy image and also save it in Database ?
javascript jsp draw.io
I have created a dummy image in my jsp file.
<img id="image" style="max-width:100%;cursor:pointer;" onclick="editDiagram(this); " src="data:image/png;base64,iVBORw0K.....>
On clicking the dummy image the a .js function editDiagram is called which in turn opens draw.io in an iFrame and provide option to make new image and save it.
function editDiagram(image)
{
var initial = image.getAttribute('src');
image.setAttribute('src', 'http://www.draw.io/images/ajax-loader.gif');
var iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
var close = function()
{
image.setAttribute('src', initial);
document.body.removeChild(iframe);
window.removeEventListener('message', receive);
};
var receive = function(evt)
{
if (evt.data.length > 0)
{
var msg = JSON.parse(evt.data);
if (msg.event == 'init')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'load',
xmlpng: initial}), '*');
}
else if (msg.event == 'export')
{
close();
image.setAttribute('src', msg.data);
save(location.href);
}
else if (msg.event == 'save')
{
iframe.contentWindow.postMessage(JSON.stringify({action: 'export',
format: 'xmlpng', spin: 'Updating page'}), '*');
}
else if (msg.event == 'exit')
{
close();
}
}
};
window.addEventListener('message', receive);
iframe.setAttribute('src', 'https://www.draw.io/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json');
document.body.appendChild(iframe);
};
function save(url)
{
if (url != null)
{
var req = new XMLHttpRequest();
req.withCredentials = true;
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status < 200 || req.status > 299)
{
alert('Error ' + req.status);
}
}
};
req.open('PUT', url, true);
req.send(document.documentElement.outerHTML);
}
}
But when i create the new image and click save the new image is not displayed in the webpage, instead only the dummmy image that fires the .js file is only shown. How do I show the new image in my website and replace the dummy image and also save it in Database ?
javascript jsp draw.io
javascript jsp draw.io
asked Sep 26 '18 at 7:16
Arindam DasArindam Das
591523
591523
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think the image is not updated because after setting the new image data with:
image.setAttribute('src', msg.data);
you reload the page through your save(url) function, if I understood correctly your code.
Anyway, to persist the graph in a database you can save it as plain xml, and then store it in the DB.
You need to modify your code as the following:
else if (msg.event == 'save') {
var contentXML=msg.xml;
var decodedXML=decode(contentXML);
saveDiagramInMyDB(decodedXML);
}
Please, see the code for the decode function in 'Decode' button in https://jgraph.github.io/drawio-tools/tools/convert.html
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52512054%2fhow-to-create-new-image-in-draw-io-and-save-it-database-from-within-my-website%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think the image is not updated because after setting the new image data with:
image.setAttribute('src', msg.data);
you reload the page through your save(url) function, if I understood correctly your code.
Anyway, to persist the graph in a database you can save it as plain xml, and then store it in the DB.
You need to modify your code as the following:
else if (msg.event == 'save') {
var contentXML=msg.xml;
var decodedXML=decode(contentXML);
saveDiagramInMyDB(decodedXML);
}
Please, see the code for the decode function in 'Decode' button in https://jgraph.github.io/drawio-tools/tools/convert.html
add a comment |
I think the image is not updated because after setting the new image data with:
image.setAttribute('src', msg.data);
you reload the page through your save(url) function, if I understood correctly your code.
Anyway, to persist the graph in a database you can save it as plain xml, and then store it in the DB.
You need to modify your code as the following:
else if (msg.event == 'save') {
var contentXML=msg.xml;
var decodedXML=decode(contentXML);
saveDiagramInMyDB(decodedXML);
}
Please, see the code for the decode function in 'Decode' button in https://jgraph.github.io/drawio-tools/tools/convert.html
add a comment |
I think the image is not updated because after setting the new image data with:
image.setAttribute('src', msg.data);
you reload the page through your save(url) function, if I understood correctly your code.
Anyway, to persist the graph in a database you can save it as plain xml, and then store it in the DB.
You need to modify your code as the following:
else if (msg.event == 'save') {
var contentXML=msg.xml;
var decodedXML=decode(contentXML);
saveDiagramInMyDB(decodedXML);
}
Please, see the code for the decode function in 'Decode' button in https://jgraph.github.io/drawio-tools/tools/convert.html
I think the image is not updated because after setting the new image data with:
image.setAttribute('src', msg.data);
you reload the page through your save(url) function, if I understood correctly your code.
Anyway, to persist the graph in a database you can save it as plain xml, and then store it in the DB.
You need to modify your code as the following:
else if (msg.event == 'save') {
var contentXML=msg.xml;
var decodedXML=decode(contentXML);
saveDiagramInMyDB(decodedXML);
}
Please, see the code for the decode function in 'Decode' button in https://jgraph.github.io/drawio-tools/tools/convert.html
edited Nov 23 '18 at 11:07
answered Nov 21 '18 at 15:59
Marco AzzaliniMarco Azzalini
33
33
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52512054%2fhow-to-create-new-image-in-draw-io-and-save-it-database-from-within-my-website%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown