diff --git a/IPython/html/static/base/js/contents.js b/IPython/html/static/base/js/contents.js
index 13791a2..365dde6 100644
--- a/IPython/html/static/base/js/contents.js
+++ b/IPython/html/static/base/js/contents.js
@@ -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(
diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js
index 41a21cf..6cbae09 100644
--- a/IPython/html/static/notebook/js/menubar.js
+++ b/IPython/html/static/notebook/js/menubar.js
@@ -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(
diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js
index f567647..8244a1e 100644
--- a/IPython/html/static/tree/js/main.js
+++ b/IPython/html/static/tree/js/main.js
@@ -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;