##// END OF EJS Templates
Merge pull request #7651 from takluyver/docs-h3-spacing...
Merge pull request #7651 from takluyver/docs-h3-spacing Add some spacing below h3 headers in HTML docs

File last commit:

r20238:fb368b56
r20293:80a87811 merge
Show More
newnotebook.js
105 lines | 3.7 KiB | application/javascript | JavascriptLexer
Min RK
Add kernel-select dropdown to new notebook button...
r19260 // 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;
Min RK
s/current_selection/default_kernel/
r19271 this.default_kernel = null;
Min RK
Add kernel-select dropdown to new notebook button...
r19260 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 */
Min RK
store current kernel selection in frontend config...
r19264 var that = this;
Min RK
kernelspecs is a dict...
r19263 this.kernelspecs = data.kernelspecs;
Jonathan Frederic
New new button
r19694 var menu = this.element.find("#notebook-kernels");
Min RK
kernelspecs is a dict...
r19263 var keys = Object.keys(data.kernelspecs).sort(function (a, b) {
Min RK
update new notebook button with kernelspec changes...
r19744 var da = data.kernelspecs[a].spec.display_name;
var db = data.kernelspecs[b].spec.display_name;
Min RK
kernelspecs is a dict...
r19263 if (da === db) {
return 0;
} else if (da > db) {
return 1;
} else {
return -1;
}
});
Jonathan Frederic
Display kernels in alphabetical order.
r19756
// Create the kernel list in reverse order because
// the .after insertion causes each item to be added
// to the top of the list.
for (var i = keys.length - 1; i >= 0; i--) {
Min RK
kernelspecs is a dict...
r19263 var ks = this.kernelspecs[keys[i]];
Min RK
separate selecting default kernel from new notebook with specified kernel...
r19262 var li = $("<li>")
.attr("id", "kernel-" +ks.name)
.data('kernelspec', ks).append(
Min RK
remove UI for setting default kernel...
r19265 $('<a>')
Min RK
separate selecting default kernel from new notebook with specified kernel...
r19262 .attr('href', '#')
.click($.proxy(this.new_notebook, this, ks.name))
Min RK
update new notebook button with kernelspec changes...
r19744 .text(ks.spec.display_name)
.attr('title', 'Create a new notebook with ' + ks.spec.display_name)
Min RK
remove UI for setting default kernel...
r19265 );
Jonathan Frederic
New new button
r19694 menu.after(li);
Min RK
Add kernel-select dropdown to new notebook button...
r19260 }
};
NewNotebookWidget.prototype.new_notebook = function (kernel_name) {
/** create and open a new notebook */
var that = this;
Min RK
s/current_selection/default_kernel/
r19271 kernel_name = kernel_name || this.default_kernel;
Min RK
Add kernel-select dropdown to new notebook button...
r19260 var w = window.open();
this.contents.new_untitled(that.notebook_path, {type: "notebook"}).then(
function (data) {
var url = utils.url_join_encode(
that.base_url, 'notebooks', data.path
);
if (kernel_name) {
url += "?kernel_name=" + kernel_name;
}
w.location = url;
Min RK
add missing error dialogs to tree actions...
r20238 }).catch(function (e) {
w.close();
dialog.modal({
title : 'Creating Notebook Failed',
body : $('<div/>')
.text("An error occurred while creating a new notebook.")
.append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class' : 'btn-primary'}
}
});
});
Min RK
Add kernel-select dropdown to new notebook button...
r19260 };
return {'NewNotebookWidget': NewNotebookWidget};
});