Commit 36889ca4 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_core] Display non editable SVG as an image

parent 122608e3
......@@ -19,5 +19,9 @@ if content_type == 'text/html':
if content_type == 'application/pdf':
return 'pdf'
# If this is a SVG, use the default SVG editor
if content_type == 'image/svg+xml':
return 'svg_editor'
# Else use preferred source code editor or fallback to Textarea
return context.portal_preferences.getPreferredSourceCodeEditor() or 'text_area'
......@@ -15,19 +15,17 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
"pdf": {"url": "pdf_js/pdfjs.gadget.html"}
};
/*
function readBlobAsDataURL(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", resolve);
fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsDataURL(blob);
}, function () {
fr.abort();
});
}
*/
rJS(window)
.declareAcquiredMethod('triggerMaximize', 'triggerMaximize')
......@@ -122,6 +120,9 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
} else if (gadget.state.editable &&
(gadget.state.editor === 'text_area')) {
element.appendChild(document.createElement('textarea'));
} else if (!gadget.state.editable &&
(gadget.state.editor === 'svg_editor')) {
element.appendChild(document.createElement('img'));
} else {
element.appendChild(document.createElement('pre'));
}
......@@ -141,6 +142,16 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
} else if (gadget.state.editable &&
(gadget.state.editor === 'text_area')) {
element.querySelector('textarea').value = gadget.state.value;
} else if (!gadget.state.editable &&
(gadget.state.editor === 'svg_editor')) {
queue
.push(function () {
var blob = new Blob([gadget.state.value], {type: 'image/svg+xml'});
return readBlobAsDataURL(blob);
})
.push(function (evt) {
element.querySelector('img').src = evt.target.result;
});
} else {
element.querySelector('pre').textContent = gadget.state.value;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment