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': ...@@ -19,5 +19,9 @@ if content_type == 'text/html':
if content_type == 'application/pdf': if content_type == 'application/pdf':
return '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 # Else use preferred source code editor or fallback to Textarea
return context.portal_preferences.getPreferredSourceCodeEditor() or 'text_area' return context.portal_preferences.getPreferredSourceCodeEditor() or 'text_area'
...@@ -15,19 +15,17 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -15,19 +15,17 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
"pdf": {"url": "pdf_js/pdfjs.gadget.html"} "pdf": {"url": "pdf_js/pdfjs.gadget.html"}
}; };
/*
function readBlobAsDataURL(blob) { function readBlobAsDataURL(blob) {
var fr = new FileReader(); var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) { return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", resolve); fr.addEventListener("load", resolve);
fr.addEventListener("error", reject); fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsDataURL(blob); fr.readAsDataURL(blob);
}, function () { }, function () {
fr.abort(); fr.abort();
}); });
} }
*/
rJS(window) rJS(window)
.declareAcquiredMethod('triggerMaximize', 'triggerMaximize') .declareAcquiredMethod('triggerMaximize', 'triggerMaximize')
...@@ -122,6 +120,9 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -122,6 +120,9 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
} else if (gadget.state.editable && } else if (gadget.state.editable &&
(gadget.state.editor === 'text_area')) { (gadget.state.editor === 'text_area')) {
element.appendChild(document.createElement('textarea')); element.appendChild(document.createElement('textarea'));
} else if (!gadget.state.editable &&
(gadget.state.editor === 'svg_editor')) {
element.appendChild(document.createElement('img'));
} else { } else {
element.appendChild(document.createElement('pre')); element.appendChild(document.createElement('pre'));
} }
...@@ -141,6 +142,16 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -141,6 +142,16 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
} else if (gadget.state.editable && } else if (gadget.state.editable &&
(gadget.state.editor === 'text_area')) { (gadget.state.editor === 'text_area')) {
element.querySelector('textarea').value = gadget.state.value; 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 { } else {
element.querySelector('pre').textContent = gadget.state.value; 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