Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use util function for upload to add authentication #831

Merged
merged 2 commits into from
Jan 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/jupyter_contrib_nbextensions/nbextensions/dragdrop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -73,15 +73,18 @@ 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.'); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get ignored - see notebook/static/base/js/utils.js#L718

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want instead a

utils.promising_ajax(url, settings).then(
    function on_success (data, status, xhr) {/*...*/},
    function on_error (reason) {/*...*/}
);

pattern

};
utils.promising_ajax(url, settings).then(
function on_success (data, status, xhr) {
var new_cell = IPython.notebook.insert_cell_below('markdown');
var str = '<img src="' + utils.url_path_join(params.subdirectory, name) + '"/>';
new_cell.set_text(str);
new_cell.execute();
},
error : function() {console.log('Data transfer for drag-and-drop failed.'); }
};
$.ajax(url, settings);
},
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 */
Expand Down