diff --git a/IPython/html/notebook/handlers.py b/IPython/html/notebook/handlers.py
index 18dc59a..45f1e17 100644
--- a/IPython/html/notebook/handlers.py
+++ b/IPython/html/notebook/handlers.py
@@ -35,7 +35,13 @@ class NotebookHandler(IPythonHandler):
@web.authenticated
def post(self):
- notebook_name = self.notebook_manager.new_notebook()
+ nbm = self.notebook_manager
+ data=self.request.body
+ if data == "":
+ notebook_name = nbm.new_notebook()
+ else:
+ data = jsonapi.loads(data)
+ notebook_name = nbm.copy_notebook(data['name'])
self.finish(jsonapi.dumps({"name": notebook_name}))
@@ -65,7 +71,13 @@ class NamedNotebookHandler(IPythonHandler):
@web.authenticated
def post(self, notebook_path):
- notebook_name = self.notebook_manager.new_notebook(notebook_path)
+ nbm = self.notebook_manager
+ data = self.request.body
+ if data == "":
+ notebook_name = nbm.new_notebook(notebook_path)
+ else:
+ data = jsonapi.loads(data)
+ notebook_name = nbm.copy_notebook(data['name'], notebook_path)
self.finish(jsonapi.dumps({"name": notebook_name}))
diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py
index f9140c7..5743b88 100644
--- a/IPython/html/services/notebooks/filenbmanager.py
+++ b/IPython/html/services/notebooks/filenbmanager.py
@@ -142,7 +142,7 @@ class FileNotebookManager(NotebookManager):
raise web.HTTPError(400, msg, reason=msg)
return last_modified, nb
- def read_notebook_object(self, notebook_name, notebook_path):
+ def read_notebook_object(self, notebook_name, notebook_path=None):
"""Get the Notebook representation of a notebook by notebook_name."""
path = self.get_path(notebook_name, notebook_path)
if not os.path.isfile(path):
diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py
index b8adfcd..8b83048 100644
--- a/IPython/html/services/notebooks/nbmanager.py
+++ b/IPython/html/services/notebooks/nbmanager.py
@@ -157,7 +157,7 @@ class NotebookManager(LoggingConfigurable):
name = nb.metadata.get('name', 'notebook')
return last_mod, representation, name
- def read_notebook_object(self, notebook_name, notebook_path):
+ def read_notebook_object(self, notebook_name, notebook_path=None):
"""Get the object representation of a notebook by notebook_id."""
raise NotImplementedError('must be implemented in a subclass')
@@ -229,7 +229,7 @@ class NotebookManager(LoggingConfigurable):
notebook_name = self.write_notebook_object(nb, notebook_path=notebook_path)
return notebook_name
- def copy_notebook(self, name, path):
+ def copy_notebook(self, name, path=None):
"""Copy an existing notebook and return its notebook_id."""
last_mod, nb = self.read_notebook_object(name, path)
name = nb.metadata.name + '-Copy'
diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js
index 6125495..6dd906e 100644
--- a/IPython/html/static/notebook/js/menubar.js
+++ b/IPython/html/static/notebook/js/menubar.js
@@ -84,9 +84,7 @@ var IPython = (function (IPython) {
window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath());
});
this.element.find('#copy_notebook').click(function () {
- var notebook_name = IPython.notebook.get_notebook_name();
- var url = that.baseProjectUrl() + 'notebooks/' + that.notebookPath() + notebook_name + '/copy';
- window.open(url,'_blank');
+ IPython.notebook.copy_notebook();
return false;
});
this.element.find('#download_ipynb').click(function () {
diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 52e881f..fa65407 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -80,6 +80,7 @@ var IPython = (function (IPython) {
Notebook.prototype.notebookName = function() {
var name = $('body').data('notebookName');
+ name = decodeURIComponent(name);
return name;
};
@@ -1759,6 +1760,23 @@ var IPython = (function (IPython) {
$.ajax(url,settings);
};
+ Notebook.prototype.copy_notebook = function(){
+ var path = this.notebookPath();
+ var name = {'name': this.notebook_name}
+ var settings = {
+ processData : false,
+ cache : false,
+ type : "POST",
+ data: JSON.stringify(name),
+ dataType : "json",
+ success:$.proxy(function (data, status, xhr){
+ notebook_name = data.name;
+ window.open(this._baseProjectUrl +'notebooks/' + this.notebookPath()+ notebook_name);
+ }, this)
+ };
+ var url = this._baseProjectUrl + 'notebooks/' + path;
+ $.ajax(url,settings);
+ };
Notebook.prototype.notebook_rename = function (nbname) {
var that = this;
diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js
index 73d4c2c..ff498cc 100644
--- a/IPython/html/static/tree/js/notebooklist.js
+++ b/IPython/html/static/tree/js/notebooklist.js
@@ -338,7 +338,21 @@ var IPython = (function (IPython) {
};
-
+ NotebookList.prototype.new_notebook = function(){
+ var path = this.notebookPath();
+ var settings = {
+ processData : false,
+ cache : false,
+ type : "POST",
+ dataType : "json",
+ success:$.proxy(function (data, status, xhr){
+ notebook_name = data.name;
+ window.open(this.baseProjectUrl() +'notebooks/' + this.notebookPath()+ notebook_name);
+ }, this)
+ };
+ var url = this.baseProjectUrl() + 'notebooks/' + path;
+ $.ajax(url,settings);
+ };
IPython.NotebookList = NotebookList;