From 495f64137c9d129c7131ab49bdf3fd7ccb5f7492 2014-11-03 22:29:39 From: Thomas Kluyver Date: 2014-11-03 22:29:39 Subject: [PATCH] Make Contents.new more generic --- diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 01b09ae..3060599 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -89,8 +89,8 @@ 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(that.notebook.notebook_path, null, { + ext: ".ipynb", success: function (data) { window.open( utils.url_join_encode( diff --git a/IPython/html/static/services/contents.js b/IPython/html/static/services/contents.js index 9c82b54..b9971c5 100644 --- a/IPython/html/static/services/contents.js +++ b/IPython/html/static/services/contents.js @@ -97,12 +97,23 @@ define([ * * @method scroll_to_cell * @param {String} path The path to create the new notebook at + * @param {String} name Name for new file. Chosen by server if unspecified. + * @param {Object} options: + * ext: file extension to use if name unspecified */ - Contents.prototype.new_notebook = function(path, options) { - var error = options.error || function() {}; + Contents.prototype.new = function(path, name, options) { + var method, data; + if (name) { + method = "PUT"; + } else { + method = "POST"; + data = JSON.stringify({ext: options.ext || ".ipynb"}); + } + var settings = { processData : false, - type : "POST", + type : method, + data: data, dataType : "json", success : options.success || function() {}, error : this.create_basic_error_handler(options.error) diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 73ed8b1..b2db0b3 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -60,8 +60,8 @@ require([ login_widget = new loginwidget.LoginWidget('#login_widget', common_options); $('#new_notebook').click(function (e) { - contents.new_notebook(common_options.notebook_path, - { + contents.new(common_options.notebook_path, null, { + ext: ".ipynb", success: function (data) { window.open( utils.url_join_encode(