From 36fade260d334410604d4b0799326ef0340c6992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rgen=20Hasch?= Date: Wed, 4 Jan 2017 20:21:16 +0100 Subject: [PATCH 1/2] Use util function for upload to add authentication --- .../nbextensions/dragdrop/main.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js b/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js index a63186edf..5eb80f0e4 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js @@ -49,10 +49,10 @@ define([ type : "PUT", data: data, contentType: 'application/json', - dataType : "json", + dataType : "json" }; - IPython.utils.promising_ajax(IPython.contents.api_url(path), settings); - } + utils.promising_ajax(IPython.contents.api_url(path), settings); + }; var send_to_server = function(name, msg) { var path = utils.url_path_join(utils.url_path_split(IPython.notebook.notebook_path)[0], params.subdirectory); @@ -73,15 +73,14 @@ define([ data : JSON.stringify(data), headers : {'Content-Type': 'text/plain'}, async : false, - success : function (data, status, xhr) { + error : function() {console.log('Data transfer for drag-and-drop failed.'); } + }; + utils.promising_ajax(url, settings).then(function (data, status, xhr) { var new_cell = IPython.notebook.insert_cell_below('markdown'); var str = ''; new_cell.set_text(str); new_cell.execute(); - }, - error : function() {console.log('Data transfer for drag-and-drop failed.'); } - }; - $.ajax(url, settings); + }); }; /* the dragover event needs to be canceled to allow firing the drop event */ From 2e3907c4b738fba5aef8124772ba80729eefa3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rgen=20Hasch?= Date: Fri, 6 Jan 2017 17:25:13 +0100 Subject: [PATCH 2/2] Handle on_success and on_error --- .../nbextensions/dragdrop/main.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js b/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js index 5eb80f0e4..6c2ec2670 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js @@ -75,12 +75,16 @@ define([ async : false, error : function() {console.log('Data transfer for drag-and-drop failed.'); } }; - utils.promising_ajax(url, settings).then(function (data, status, xhr) { + utils.promising_ajax(url, settings).then( + function on_success (data, status, xhr) { var new_cell = IPython.notebook.insert_cell_below('markdown'); var str = ''; new_cell.set_text(str); new_cell.execute(); - }); + }, + function on_error (reason) { + console.log('Data transfer for drag-and-drop failed.'); + }); }; /* the dragover event needs to be canceled to allow firing the drop event */