Show More
@@ -71,7 +71,7 b' require([' | |||||
71 |
|
71 | |||
72 | var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); |
|
72 | var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); | |
73 |
|
73 | |||
74 |
var n |
|
74 | var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons", | |
75 | $.extend( |
|
75 | $.extend( | |
76 | {contents: contents}, |
|
76 | {contents: contents}, | |
77 | common_options |
|
77 | common_options | |
@@ -130,7 +130,7 b' require([' | |||||
130 | IPython.session_list = session_list; |
|
130 | IPython.session_list = session_list; | |
131 | IPython.kernel_list = kernel_list; |
|
131 | IPython.kernel_list = kernel_list; | |
132 | IPython.login_widget = login_widget; |
|
132 | IPython.login_widget = login_widget; | |
133 |
IPython.new_notebook_widget = n |
|
133 | IPython.new_notebook_widget = new_buttons; | |
134 |
|
134 | |||
135 | events.trigger('app_initialized.DashboardApp'); |
|
135 | events.trigger('app_initialized.DashboardApp'); | |
136 |
|
136 |
@@ -15,7 +15,6 b' define([' | |||||
15 | this.notebook_path = options.notebook_path; |
|
15 | this.notebook_path = options.notebook_path; | |
16 | this.contents = options.contents; |
|
16 | this.contents = options.contents; | |
17 | this.default_kernel = null; |
|
17 | this.default_kernel = null; | |
18 | this.config = options.config; |
|
|||
19 | this.kernelspecs = {}; |
|
18 | this.kernelspecs = {}; | |
20 | if (this.selector !== undefined) { |
|
19 | if (this.selector !== undefined) { | |
21 | this.element = $(selector); |
|
20 | this.element = $(selector); | |
@@ -41,7 +40,7 b' define([' | |||||
41 | /** load kernelspec list */ |
|
40 | /** load kernelspec list */ | |
42 | var that = this; |
|
41 | var that = this; | |
43 | this.kernelspecs = data.kernelspecs; |
|
42 | this.kernelspecs = data.kernelspecs; | |
44 |
var menu = this.element.find("#n |
|
43 | var menu = this.element.find("#notebook-kernels"); | |
45 | var keys = Object.keys(data.kernelspecs).sort(function (a, b) { |
|
44 | var keys = Object.keys(data.kernelspecs).sort(function (a, b) { | |
46 | var da = data.kernelspecs[a].display_name; |
|
45 | var da = data.kernelspecs[a].display_name; | |
47 | var db = data.kernelspecs[b].display_name; |
|
46 | var db = data.kernelspecs[b].display_name; | |
@@ -64,45 +63,8 b' define([' | |||||
64 | .text(ks.display_name) |
|
63 | .text(ks.display_name) | |
65 | .attr('title', 'Create a new notebook with ' + ks.display_name) |
|
64 | .attr('title', 'Create a new notebook with ' + ks.display_name) | |
66 | ); |
|
65 | ); | |
67 |
menu.a |
|
66 | menu.after(li); | |
68 | } |
|
67 | } | |
69 | this.config.loaded.then(function () { |
|
|||
70 | that._load_default_kernelspec(data['default']); |
|
|||
71 | }); |
|
|||
72 | }; |
|
|||
73 |
|
||||
74 | NewNotebookWidget.prototype._load_default_kernelspec = function (default_name) { |
|
|||
75 | /** load default kernelspec name from config, if defined */ |
|
|||
76 | if (this.config.data.NewNotebookWidget && |
|
|||
77 | this.config.data.NewNotebookWidget.default_kernel && |
|
|||
78 | this.kernelspecs[this.config.data.NewNotebookWidget.default_kernel] !== undefined |
|
|||
79 | ) { |
|
|||
80 | default_name = this.config.data.NewNotebookWidget.default_kernel; |
|
|||
81 | } |
|
|||
82 | this.set_default_kernel(default_name); |
|
|||
83 | }; |
|
|||
84 |
|
||||
85 | NewNotebookWidget.prototype.set_default_kernel = function (kernel_name) { |
|
|||
86 | /** select the current default kernel */ |
|
|||
87 | this.default_kernel = kernel_name; |
|
|||
88 | this.config.update({ |
|
|||
89 | NewNotebookWidget: { |
|
|||
90 | default_kernel: kernel_name |
|
|||
91 | } |
|
|||
92 | }); |
|
|||
93 | var spec = this.kernelspecs[kernel_name]; |
|
|||
94 | var display_name; |
|
|||
95 | if (spec) { |
|
|||
96 | display_name = spec.display_name; |
|
|||
97 | this.element.find("#current-kernel") |
|
|||
98 | .text(display_name) |
|
|||
99 | .attr('title', display_name + " is the default kernel for new notebooks"); |
|
|||
100 | } else { |
|
|||
101 | display_name = 'default kernel'; |
|
|||
102 | } |
|
|||
103 | this.element.find("#new_notebook").attr('title', |
|
|||
104 | 'Create a new notebook with ' + display_name |
|
|||
105 | ); |
|
|||
106 | }; |
|
68 | }; | |
107 |
|
69 | |||
108 | NewNotebookWidget.prototype.new_notebook = function (kernel_name) { |
|
70 | NewNotebookWidget.prototype.new_notebook = function (kernel_name) { |
@@ -7,7 +7,8 b' define([' | |||||
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'base/js/dialog', |
|
8 | 'base/js/dialog', | |
9 | 'base/js/events', |
|
9 | 'base/js/events', | |
10 | ], function(IPython, $, utils, dialog, events) { |
|
10 | 'base/js/keyboard', | |
|
11 | ], function(IPython, $, utils, dialog, events, keyboard) { | |||
11 | "use strict"; |
|
12 | "use strict"; | |
12 |
|
13 | |||
13 | var NotebookList = function (selector, options) { |
|
14 | var NotebookList = function (selector, options) { | |
@@ -54,7 +55,6 b' define([' | |||||
54 | this.element.addClass("list_container"); |
|
55 | this.element.addClass("list_container"); | |
55 | }; |
|
56 | }; | |
56 |
|
57 | |||
57 |
|
||||
58 | NotebookList.prototype.bind_events = function () { |
|
58 | NotebookList.prototype.bind_events = function () { | |
59 | var that = this; |
|
59 | var that = this; | |
60 | $('#refresh_' + this.element_name + '_list').click(function () { |
|
60 | $('#refresh_' + this.element_name + '_list').click(function () { | |
@@ -67,6 +67,25 b' define([' | |||||
67 | that.handleFilesUpload(event,'drop'); |
|
67 | that.handleFilesUpload(event,'drop'); | |
68 | return false; |
|
68 | return false; | |
69 | }); |
|
69 | }); | |
|
70 | ||||
|
71 | // Bind events for singleton controls. | |||
|
72 | if (!NotebookList._bound_singletons) { | |||
|
73 | NotebookList._bound_singletons = true; | |||
|
74 | $('#new-file').click(function(e) { | |||
|
75 | that._prompt_name('File').then(function(name) { | |||
|
76 | that._create('file', name).then(function() { | |||
|
77 | that.load_sessions(); | |||
|
78 | }); | |||
|
79 | }); | |||
|
80 | }); | |||
|
81 | $('#new-folder').click(function(e) { | |||
|
82 | that._prompt_name('Folder').then(function(name) { | |||
|
83 | that._create('directory', name).then(function() { | |||
|
84 | that.load_sessions(); | |||
|
85 | }); | |||
|
86 | }); | |||
|
87 | }); | |||
|
88 | } | |||
70 | }; |
|
89 | }; | |
71 |
|
90 | |||
72 | NotebookList.prototype.handleFilesUpload = function(event, dropOrForm) { |
|
91 | NotebookList.prototype.handleFilesUpload = function(event, dropOrForm) { | |
@@ -519,6 +538,90 b' define([' | |||||
519 | .append(cancel_button); |
|
538 | .append(cancel_button); | |
520 | }; |
|
539 | }; | |
521 |
|
540 | |||
|
541 | /** | |||
|
542 | * Prompt the user for a name. | |||
|
543 | * @param {string} what - What you want a name for. | |||
|
544 | * @return {Promise} Promise that resolve with a string name | |||
|
545 | */ | |||
|
546 | NotebookList.prototype._prompt_name = function(what) { | |||
|
547 | var that = this; | |||
|
548 | var dialog_body = $('<div/>').append( | |||
|
549 | $("<p/>").addClass("rename-message") | |||
|
550 | .text(what + ' name:') | |||
|
551 | ).append( | |||
|
552 | $("<br/>") | |||
|
553 | ).append( | |||
|
554 | $('<input/>').attr('type','text').attr('size','25').addClass('form-control') | |||
|
555 | .val('') // Default to empty | |||
|
556 | ); | |||
|
557 | ||||
|
558 | return new Promise(function(resolve, reject) { | |||
|
559 | var dialog_inst = dialog.modal({ | |||
|
560 | title: "Rename Notebook", | |||
|
561 | body: dialog_body, | |||
|
562 | buttons: { | |||
|
563 | "OK": { | |||
|
564 | class: "btn-primary", | |||
|
565 | click: function () { | |||
|
566 | resolve(dialog_inst.find('input').val()); | |||
|
567 | } | |||
|
568 | }, | |||
|
569 | "Cancel": { | |||
|
570 | click: function () { | |||
|
571 | reject(); | |||
|
572 | } | |||
|
573 | } | |||
|
574 | }, open: function () { | |||
|
575 | /** | |||
|
576 | * Upon ENTER, click the OK button. | |||
|
577 | */ | |||
|
578 | dialog_inst.find('input[type="text"]').keydown(function (event) { | |||
|
579 | if (event.which === keyboard.keycodes.enter) { | |||
|
580 | dialog_inst.find('.btn-primary').first().click(); | |||
|
581 | return false; | |||
|
582 | } | |||
|
583 | }); | |||
|
584 | dialog_inst.find('input[type="text"]').focus().select(); | |||
|
585 | } | |||
|
586 | }); | |||
|
587 | }); | |||
|
588 | }; | |||
|
589 | ||||
|
590 | /** | |||
|
591 | * Creates a `file` or `directory` | |||
|
592 | * @param {string} type - "file" or "directory" | |||
|
593 | * @param {string} name - name of the thing to create | |||
|
594 | * @return {Promise} success | |||
|
595 | */ | |||
|
596 | NotebookList.prototype._create = function(type, name) { | |||
|
597 | var that = this; | |||
|
598 | return new Promise(function(resolve, reject) { | |||
|
599 | var settings = { | |||
|
600 | processData : false, | |||
|
601 | cache : false, | |||
|
602 | type : "PUT", | |||
|
603 | data: JSON.stringify({ | |||
|
604 | type: type, | |||
|
605 | format: 'text', | |||
|
606 | content: '', | |||
|
607 | }), | |||
|
608 | dataType: "json", | |||
|
609 | success: function () { | |||
|
610 | resolve(); | |||
|
611 | }, | |||
|
612 | error: function() { | |||
|
613 | reject(); | |||
|
614 | utils.log_ajax_error.apply(this, arguments); | |||
|
615 | }, | |||
|
616 | }; | |||
|
617 | var url = utils.url_join_encode( | |||
|
618 | that.base_url, | |||
|
619 | 'api/contents/' + name | |||
|
620 | ); | |||
|
621 | $.ajax(url, settings); | |||
|
622 | }); | |||
|
623 | }; | |||
|
624 | ||||
522 |
|
625 | |||
523 | // Backwards compatability. |
|
626 | // Backwards compatability. | |
524 | IPython.NotebookList = NotebookList; |
|
627 | IPython.NotebookList = NotebookList; |
@@ -156,7 +156,7 b' input.engine_num_input {' | |||||
156 | .icon(@fa-var-file-o) |
|
156 | .icon(@fa-var-file-o) | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 |
ul#new- |
|
159 | ul#new-menu { | |
160 | // align right instead of left |
|
160 | // align right instead of left | |
161 | left: auto; |
|
161 | left: auto; | |
162 | right: 0; |
|
162 | right: 0; |
@@ -42,16 +42,22 b' data-terminals-available="{{terminals_available}}"' | |||||
42 | </span> |
|
42 | </span> | |
43 | </span> |
|
43 | </span> | |
44 | </form> |
|
44 | </form> | |
45 |
<div |
|
45 | <div class="pull-right"> | |
46 |
<div id="new- |
|
46 | <div id="new-buttons" class="btn-group"> | |
47 | <button id="new_notebook" class="btn btn-default btn-xs"> |
|
|||
48 | New Notebook |
|
|||
49 | </button> |
|
|||
50 | <button class="dropdown-toggle btn btn-default btn-xs" data-toggle="dropdown"> |
|
47 | <button class="dropdown-toggle btn btn-default btn-xs" data-toggle="dropdown"> | |
51 |
<span |
|
48 | <span>New</span> | |
52 | <span class="caret"></span> |
|
49 | <span class="caret"></span> | |
53 | </button> |
|
50 | </button> | |
54 |
<ul id="new- |
|
51 | <ul id="new-menu" class="dropdown-menu"> | |
|
52 | <li role="presentation" class="dropdown-header" id="notebook-kernels">Notebooks</li> | |||
|
53 | <li role="presentation" class="divider"></li> | |||
|
54 | <li role="presentation" id="new-file"> | |||
|
55 | <a role="menuitem" tabindex="-1" href="#">File</a> | |||
|
56 | </li> | |||
|
57 | <li role="presentation" id="new-folder"> | |||
|
58 | <a role="menuitem" tabindex="-1" href="#">Folder</a> | |||
|
59 | </li> | |||
|
60 | </ul> | |||
55 | </div> |
|
61 | </div> | |
56 | <div class="btn-group"> |
|
62 | <div class="btn-group"> | |
57 | <button id="refresh_notebook_list" title="Refresh notebook list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> |
|
63 | <button id="refresh_notebook_list" title="Refresh notebook list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> |
General Comments 0
You need to be logged in to leave comments.
Login now