diff --git a/IPython/html/notebook/handlers.py b/IPython/html/notebook/handlers.py index 0867400..18dc59a 100644 --- a/IPython/html/notebook/handlers.py +++ b/IPython/html/notebook/handlers.py @@ -19,6 +19,8 @@ Authors: import os from tornado import web HTTPError = web.HTTPError +from zmq.utils import jsonapi + from ..base.handlers import IPythonHandler from ..utils import url_path_join @@ -29,20 +31,12 @@ from urllib import quote #----------------------------------------------------------------------------- -class NewPathHandler(IPythonHandler): - - @web.authenticated - def get(self, notebook_path): - notebook_name = self.notebook_manager.new_notebook(notebook_path) - self.redirect(url_path_join(self.base_project_url,"notebooks", notebook_path, notebook_name)) - - -class NewHandler(IPythonHandler): +class NotebookHandler(IPythonHandler): @web.authenticated - def get(self): + def post(self): notebook_name = self.notebook_manager.new_notebook() - self.redirect(url_path_join(self.base_project_url, "notebooks", notebook_name)) + self.finish(jsonapi.dumps({"name": notebook_name})) class NamedNotebookHandler(IPythonHandler): @@ -68,11 +62,11 @@ class NamedNotebookHandler(IPythonHandler): mathjax_url=self.mathjax_url, ) ) - + @web.authenticated def post(self, notebook_path): - nbm =self.notebook_manager - notebook_name = nbm.new_notebook() + notebook_name = self.notebook_manager.new_notebook(notebook_path) + self.finish(jsonapi.dumps({"name": notebook_name})) class NotebookCopyHandler(IPythonHandler): @@ -96,8 +90,7 @@ class NotebookCopyHandler(IPythonHandler): _notebook_path_regex = r"(?P<notebook_path>.+)" default_handlers = [ - (r"/notebooks/%s/new" % _notebook_path_regex, NewPathHandler), - (r"/notebooks/new", NewHandler), (r"/notebooks/%s/copy" % _notebook_path_regex, NotebookCopyHandler), - (r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler) + (r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler), + (r"/notebooks/", NotebookHandler) ] diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 419a789..6125495 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -78,7 +78,7 @@ var IPython = (function (IPython) { // File var that = this; this.element.find('#new_notebook').click(function () { - window.open(that.baseProjectUrl() + 'notebooks/' + that.notebookPath() +'new'); + IPython.notebook.new_notebook(); }); this.element.find('#open_notebook').click(function () { window.open(that.baseProjectUrl() + 'tree/' + that.notebookPath()); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index dc24aca..52e881f 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -89,7 +89,7 @@ var IPython = (function (IPython) { if (path != 'None') { if (path[path.length-1] != '/') { path = path.substring(0,path.length); - }; + }; return path; } else { return ''; @@ -1743,6 +1743,22 @@ var IPython = (function (IPython) { $([IPython.events]).trigger('notebook_save_failed.Notebook'); }; + Notebook.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); + }; + Notebook.prototype.notebook_rename = function (nbname) { var that = this; diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 5f38861..ddcd9da 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -13,18 +13,11 @@ $(document).ready(function () { IPython.page = new IPython.Page(); - - if ($('body').data('notebookPath') == "") { - $('#new_notebook').button().click(function (e) { - window.open($('body').data('baseProjectUrl')+'notebooks/'+'new'); - }); - } - else { - $('#new_notebook').button().click(function (e) { - window.open($('body').data('baseProjectUrl')+'notebooks/'+$('body').data('notebookPath') + '/new'); - }); - } - + + $('#new_notebook').button().click(function (e) { + IPython.notebook_list.new_notebook($('body').data('baseProjectUrl')) + }); + IPython.notebook_list = new IPython.NotebookList('#notebook_list'); IPython.cluster_list = new IPython.ClusterList('#cluster_list'); IPython.login_widget = new IPython.LoginWidget('#login_widget'); diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index e825949..73d4c2c 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -338,6 +338,8 @@ var IPython = (function (IPython) { }; + + IPython.NotebookList = NotebookList; return IPython;