Commit 32c14fc9 authored by Jérome Perrin's avatar Jérome Perrin

Fix download JSON for IE

parent 8ffffaff
...@@ -118,6 +118,14 @@ def _runWithTimeout(queue, func, args, kw): ...@@ -118,6 +118,14 @@ def _runWithTimeout(queue, func, args, kw):
queue.put(func(*args, **kw)) queue.put(func(*args, **kw))
@app.route("/postJSONData", methods=["POST", "OPTIONS"])
def postJSONData():
"""Returns posted JSON data as it is for Export button"""
data = json.loads(request.form.get('data'))
response = jsonify(data)
response.headers['Content-Disposition'] = 'attachment; filename=dream.json'
return response
@app.route("/runSimulation", methods=["POST", "OPTIONS"]) @app.route("/runSimulation", methods=["POST", "OPTIONS"])
def runSimulation(): def runSimulation():
parameter_dict = request.json parameter_dict = request.json
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
</head> </head>
<body> <body>
<a class="export_link ui-btn ui-btn-inline ui-icon-action ui-btn-icon-right">Export</a> <a class="export_link ui-btn ui-btn-inline ui-icon-action ui-btn-icon-right">Export</a>
<form id="export_form" style="display:none" method="post" action="../../postJSONData">
<textarea id="export_json" name="data"></textarea>
</form>
<form class="knowledge_form"> <form class="knowledge_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline <button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-refresh ui-btn-icon-right">Run Knowledge Extraction Tool</button> ui-icon-refresh ui-btn-icon-right">Run Knowledge Extraction Tool</button>
......
...@@ -4,14 +4,6 @@ ...@@ -4,14 +4,6 @@
initGadgetMixin) { initGadgetMixin) {
"use strict"; "use strict";
function datatouri(data, mime_type) {
var result = "data:";
if (mime_type !== undefined) {
result += mime_type;
}
return result + ";base64," + window.btoa(data);
}
function disableAllButtons(gadget) { function disableAllButtons(gadget) {
// Prevent double click // Prevent double click
var i, var i,
...@@ -141,8 +133,12 @@ ...@@ -141,8 +133,12 @@
}) })
.push(function (result_list) { .push(function (result_list) {
var export_link = gadget.props.element.querySelector(".export_link"); var export_link = gadget.props.element.querySelector(".export_link");
export_link.download = result_list[0].data.title; // XXX this breaks promise chain
export_link.href = datatouri(result_list[1], "application/json"); $(export_link).click(
function() {
$('#export_json').val(result_list[1]);
return $('#export_form').submit();
});
}); });
}) })
......
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