Don't do UI stuff in contents API module

Thomas Kluyver 11 years ago
parent 478648bde5
commit 9538726b16

@ -68,39 +68,20 @@ define([
* @method scroll_to_cell
* @param {String} path The path to create the new notebook at
*/
Contents.prototype.new_notebook = function(path) {
Contents.prototype.new_notebook = function(path, options) {
var base_url = this.base_url;
var success_callback = options.success_callback || function(data, status, xhr) {};
var error_callback = options.error_callback || function(xhr, status, error) {};
var settings = {
processData : false,
cache : false,
type : "POST",
dataType : "json",
async : false,
success : function (data, status, xhr){
var notebook_name = data.name;
window.open(
utils.url_join_encode(
base_url,
'notebooks',
path,
notebook_name
),
'_blank'
);
},
success : success_callback,
error : function(xhr, status, error) {
utils.log_ajax_error(xhr, status, error);
var msg;
if (xhr.responseJSON && xhr.responseJSON.message) {
msg = xhr.responseJSON.message;
} else {
msg = xhr.statusText;
}
dialog.modal({
title : 'Creating Notebook Failed',
body : "The error was: " + msg,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
error_callback(xhr, status, error);
}
};
var url = utils.url_join_encode(

@ -89,7 +89,29 @@ define([
this.element.find('#new_notebook').click(function () {
// Create a new notebook in the same path as the current
// notebook's path.
that.contents.new_notebook(that.notebook.notebook_path);
that.contents.new_notebook(that.notebook.notebook_path,
{
success_callback: function (data, status, xhr) {
window.open(
utils.url_join_encode(
common_options.base_url, 'notebooks',
data.path, data.name
), '_blank');
},
error_callback: function(xhr, status, error) {
var msg;
if (xhr.responseJSON && xhr.responseJSON.message) {
msg = xhr.responseJSON.message;
} else {
msg = xhr.statusText;
}
dialog.modal({
title : 'Creating Notebook Failed',
body : "The error was: " + msg,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
}
});
});
this.element.find('#open_notebook').click(function () {
window.open(utils.url_join_encode(

@ -60,7 +60,29 @@ require([
login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
$('#new_notebook').button().click(function (e) {
contents.new_notebook(common_options.notebook_path);
contents.new_notebook(common_options.notebook_path,
{
success_callback: function (data, status, xhr) {
window.open(
utils.url_join_encode(
common_options.base_url, 'notebooks',
data.path, data.name
), '_blank');
},
error_callback: function(xhr, status, error) {
var msg;
if (xhr.responseJSON && xhr.responseJSON.message) {
msg = xhr.responseJSON.message;
} else {
msg = xhr.statusText;
}
dialog.modal({
title : 'Creating Notebook Failed',
body : "The error was: " + msg,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
}
});
});
var interval_id=0;

Loading…
Cancel
Save