diff --git a/IPython/html/static/style/style.min.css b/IPython/html/static/style/style.min.css index d8a6ef6c1..a2ccd2f7b 100644 --- a/IPython/html/static/style/style.min.css +++ b/IPython/html/static/style/style.min.css @@ -8164,6 +8164,10 @@ input.engine_num_input { .file_icon:before.pull-right { margin-left: .3em; } +ul#new-notebook-menu { + left: auto; + right: 0; +} /*! * * IPython notebook diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 617f5f586..7eb99c9aa 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -14,6 +14,7 @@ require([ 'tree/js/sessionlist', 'tree/js/kernellist', 'tree/js/terminallist', + 'tree/js/newnotebook', 'auth/js/loginwidget', // only loaded, not used: 'jqueryui', @@ -27,11 +28,12 @@ require([ page, utils, contents_service, - notebooklist, - clusterlist, - sesssionlist, + notebooklist, + clusterlist, + sesssionlist, kernellist, terminallist, + newnotebook, loginwidget){ "use strict"; @@ -63,24 +65,12 @@ require([ var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); - $('#new_notebook').click(function (e) { - var w = window.open(); - contents.new_untitled(common_options.notebook_path, {type: "notebook"}).then( - function (data) { - w.location = utils.url_join_encode( - common_options.base_url, 'notebooks', data.path - ); - }, - function(error) { - w.close(); - dialog.modal({ - title : 'Creating Notebook Failed', - body : "The error was: " + error.message, - buttons : {'OK' : {'class' : 'btn-primary'}} - }); - } - ); - }); + var nnw = new newnotebook.NewNotebookWidget("#new-notebook-buttons", + $.extend( + {contents: contents}, + common_options + ) + ); var interval_id=0; // auto refresh every xx secondes, no need to be fast, diff --git a/IPython/html/static/tree/js/newnotebook.js b/IPython/html/static/tree/js/newnotebook.js new file mode 100644 index 000000000..ae24c217e --- /dev/null +++ b/IPython/html/static/tree/js/newnotebook.js @@ -0,0 +1,112 @@ +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'jquery', + 'base/js/namespace', + 'base/js/utils', + 'base/js/dialog', +], function ($, IPython, utils, dialog) { + "use strict"; + + var NewNotebookWidget = function (selector, options) { + this.selector = selector; + this.base_url = options.base_url; + this.notebook_path = options.notebook_path; + this.contents = options.contents; + this.current_selection = null; + this.kernelspecs = {}; + if (this.selector !== undefined) { + this.element = $(selector); + this.request_kernelspecs(); + } + this.bind_events(); + }; + + NewNotebookWidget.prototype.bind_events = function () { + var that = this; + this.element.find('#new_notebook').click(function () { + that.new_notebook(); + }); + }; + + NewNotebookWidget.prototype.request_kernelspecs = function () { + /** request and then load kernel specs */ + var url = utils.url_join_encode(this.base_url, 'api/kernelspecs'); + utils.promising_ajax(url).then($.proxy(this._load_kernelspecs, this)); + }; + + NewNotebookWidget.prototype._load_kernelspecs = function (data) { + /** load kernelspec list */ + this.kernelspecs = {}; + var menu = this.element.find("#new-notebook-menu"); + for (var i = 0; i < data.length; i++) { + var ks = data[i]; + this.kernelspecs[ks.name] = ks; + var ksentry = $("