Commit 19b6485f authored by Romain Casati's avatar Romain Casati
Browse files

Open function goes from notebook to GUI.

parent 235ddb75
......@@ -160,6 +160,40 @@ Un lien vers la page de Basthon avec le contenu actuel du script a été créé.
document.body.removeChild(anchor);
};
/**
* Load a notebook.
*/
that.openNotebook = function (file) {
return new Promise(function (resolve, reject) {
var input = document.createElement('input');
input.type = 'file';
input.style.display = "none";
input.onchange = async function (event) {
for( var file of event.target.files ) {
const ext = file.name.split('.').pop();
var reader = new FileReader();
if(ext === 'ipynb') {
reader.readAsText(file);
reader.onload = function (event) {
/* TODO: connect filename to notebook name */
await that.notebook.load(JSON.parse(event.target.result));
resolve();
};
} else {
reader.readAsArrayBuffer(file);
reader.onload = function (event) {
await Basthon.putFile(file.name, event.target.result);
resolve();
};
}
}
}
document.body.appendChild(input);
input.click();
document.body.removeChild(input);
});
};
return that;
})();
......
......@@ -891,7 +891,7 @@ define([
help_index: 'fd',
icon: 'fa-folder-open-o',
handler : function (env, event) {
env.notebook.openNotebook();
basthonGUI.openNotebook();
if(event){
event.preventDefault();
}
......
......@@ -159,7 +159,7 @@ define([
var that = this;
this.element.find('#open_notebook').click(function () {
that.notebook.openNotebook();
basthonGUI.openNotebook();
});
this.element.find('#copy_notebook').click(function () {
that.notebook.copy_notebook();
......
......@@ -3077,39 +3077,6 @@ define([
}
};
/**
* [Basthon]
* Open notebook from file.
*/
Notebook.prototype.openNotebook = function () {
var that = this;
var input = document.createElement('input');
input.type = 'file';
input.style.display = "none";
input.onchange = function (event) {
for( var file of event.target.files ) {
const ext = file.name.split('.').pop();
var reader = new FileReader();
if(ext === 'ipynb') {
/* TODO: connect filename to notebook name */
reader.readAsText(file);
reader.onload = function (event) {
that.load(JSON.parse(event.target.result));
};
} else {
reader.readAsArrayBuffer(file);
reader.onload = function (event) {
Basthon.putFile(file.name, event.target.result);
};
}
}
};
document.body.appendChild(input);
input.click();
document.body.removeChild(input);
};
/**
* Explicitly trust the output of this notebook.
*/
......
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