diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js
index ec25f2342..999c01da1 100644
--- a/IPython/html/static/notebook/js/main.js
+++ b/IPython/html/static/notebook/js/main.js
@@ -46,16 +46,23 @@ function (marked) {
$('#ipython-main-app').addClass('border-box-sizing');
$('div#notebook_panel').addClass('border-box-sizing');
- var baseProjectUrl = $('body').data('baseProjectUrl')
+ var baseProjectUrl = $('body').data('baseProjectUrl');
+ var notebookPath = $('body').data('notebookPath');
+ var notebookName = $('body').data('notebookName');
+ notebookName = decodeURIComponent(notebookName);
+ console.log(notebookName);
+ if (notebookPath == 'None'){
+ notebookPath = "";
+ }
IPython.page = new IPython.Page();
IPython.layout_manager = new IPython.LayoutManager();
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.quick_help = new IPython.QuickHelp();
IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl});
- IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl});
+ IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, notebookPath:notebookPath, notebookName:notebookName});
IPython.save_widget = new IPython.SaveWidget('span#save_widget');
- IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl})
+ IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl, notebookPath: notebookPath})
IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container')
IPython.tooltip = new IPython.Tooltip()
IPython.notification_area = new IPython.NotificationArea('#notification_area')
@@ -91,7 +98,7 @@ function (marked) {
$([IPython.events]).on('notebook_loaded.Notebook', first_load);
$([IPython.events]).trigger('app_initialized.NotebookApp');
- IPython.notebook.load_notebook($('body').data('notebookId'));
+ IPython.notebook.load_notebook(notebookName, notebookPath);
if (marked) {
marked.setOptions({
diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js
index fee79d6bf..ea1fc2739 100644
--- a/IPython/html/static/notebook/js/menubar.js
+++ b/IPython/html/static/notebook/js/menubar.js
@@ -50,7 +50,10 @@ var IPython = (function (IPython) {
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
-
+ MenuBar.prototype.notebookPath = function(){
+ return this._notebookPath || $('body').data('notebookPath');
+ };
+
MenuBar.prototype.style = function () {
this.element.addClass('border-box-sizing');
this.element.find("li").click(function (event, ui) {
@@ -66,38 +69,68 @@ var IPython = (function (IPython) {
MenuBar.prototype.bind_events = function () {
// File
var that = this;
- this.element.find('#new_notebook').click(function () {
- window.open(that.baseProjectUrl()+'new');
- });
- this.element.find('#open_notebook').click(function () {
- window.open(that.baseProjectUrl());
- });
+ if (this.notebookPath() != 'None') {
+ this.element.find('#new_notebook').click(function () {
+ window.open(that.baseProjectUrl() + 'notebooks/' + that.notebookPath() +'/new');
+ });
+ this.element.find('#open_notebook').click(function () {
+ 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');
+ return false;
+ });
+ this.element.find('#download_ipynb').click(function () {
+ var notebook_name = IPython.notebook.get_notebook_name();
+ var url = that.baseProjectUrl() + 'api/notebooks/' +
+ notebook_name + '?format=json';
+ window.location.assign(url);
+ });
+ this.element.find('#download_py').click(function () {
+ var notebook_name = IPython.notebook.get_notebook_name();
+ var url = that.baseProjectUrl() + 'api/notebooks/' +
+ notebook_name + '?format=py';
+ window.location.assign(url);
+ });
+ }
+ else {
+ this.element.find('#new_notebook').click(function () {
+ window.open(that.baseProjectUrl()+'notebooks/new');
+ });
+ this.element.find('#open_notebook').click(function () {
+ window.open(that.baseProjectUrl() + 'tree');
+ });
+ this.element.find('#copy_notebook').click(function () {
+ var notebook_name = IPython.notebook.get_notebook_name();
+ var url = that.baseProjectUrl() + 'notebooks/' + notebook_name + '/copy';
+ window.open(url,'_blank');
+ return false;
+ });
+ this.element.find('#download_ipynb').click(function () {
+ var notebook_name = IPython.notebook.get_notebook_name();
+ var url = that.baseProjectUrl() + 'api/notebooks/' +
+ notebook_name + '?format=json';
+ window.location.assign(url);
+ });
+ this.element.find('#download_py').click(function () {
+ var notebook_name = IPython.notebook.get_notebook_name();
+ var url = that.baseProjectUrl() + 'api/notebooks/' +
+ notebook_name + '?format=py';
+ window.location.assign(url);
+ });
+
+
+ }
this.element.find('#rename_notebook').click(function () {
IPython.save_widget.rename_notebook();
});
- this.element.find('#copy_notebook').click(function () {
- var notebook_id = IPython.notebook.get_notebook_id();
- var url = that.baseProjectUrl() + notebook_id + '/copy';
- window.open(url,'_blank');
- return false;
- });
this.element.find('#save_checkpoint').click(function () {
IPython.notebook.save_checkpoint();
});
this.element.find('#restore_checkpoint').click(function () {
});
- this.element.find('#download_ipynb').click(function () {
- var notebook_id = IPython.notebook.get_notebook_id();
- var url = that.baseProjectUrl() + 'notebooks/' +
- notebook_id + '?format=json';
- window.location.assign(url);
- });
- this.element.find('#download_py').click(function () {
- var notebook_id = IPython.notebook.get_notebook_id();
- var url = that.baseProjectUrl() + 'notebooks/' +
- notebook_id + '?format=py';
- window.location.assign(url);
- });
this.element.find('#kill_and_exit').click(function () {
IPython.notebook.kernel.kill();
setTimeout(function(){window.close();}, 200);
diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 2392690c9..068098e4e 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -26,12 +26,13 @@ var IPython = (function (IPython) {
var Notebook = function (selector, options) {
var options = options || {};
this._baseProjectUrl = options.baseProjectUrl;
-
+ this.notebook_path = options.notebookPath;
+ this.notebook_name = options.notebookName;
this.element = $(selector);
this.element.scroll();
this.element.data("notebook", this);
this.next_prompt_number = 1;
- this.kernel = null;
+ this.session = null;
this.clipboard = null;
this.undelete_backup = null;
this.undelete_index = null;
@@ -49,7 +50,6 @@ var IPython = (function (IPython) {
// single worksheet for now
this.worksheet_metadata = {};
this.control_key_active = false;
- this.notebook_id = null;
this.notebook_name = null;
this.notebook_name_blacklist_re = /[\/\\:]/;
this.nbformat = 3 // Increment this when changing the nbformat
@@ -78,6 +78,18 @@ var IPython = (function (IPython) {
return this._baseProjectUrl || $('body').data('baseProjectUrl');
};
+ Notebook.prototype.notebookPath = function() {
+ var path = $('body').data('notebookPath');
+ if (path != 'None') {
+ if (path[path.length-1] != '/') {
+ path = path.substring(0,path.length);
+ };
+ return path;
+ } else {
+ return '';
+ }
+ };
+
/**
* Create an HTML and CSS representation of the notebook.
*
@@ -745,7 +757,7 @@ var IPython = (function (IPython) {
var i = this.index_or_selected(index);
var cell = this.get_selected_cell();
this.undelete_backup = cell.toJSON();
- $('#undelete_cell').removeClass('disabled');
+ $('#undelete_cell').removeClass('ui-state-disabled');
if (this.is_valid_cell_index(i)) {
var ce = this.get_cell_element(i);
ce.remove();
@@ -1028,11 +1040,11 @@ var IPython = (function (IPython) {
Notebook.prototype.enable_paste = function () {
var that = this;
if (!this.paste_enabled) {
- $('#paste_cell_replace').removeClass('disabled')
+ $('#paste_cell_replace').removeClass('ui-state-disabled')
.on('click', function () {that.paste_cell_replace();});
- $('#paste_cell_above').removeClass('disabled')
+ $('#paste_cell_above').removeClass('ui-state-disabled')
.on('click', function () {that.paste_cell_above();});
- $('#paste_cell_below').removeClass('disabled')
+ $('#paste_cell_below').removeClass('ui-state-disabled')
.on('click', function () {that.paste_cell_below();});
this.paste_enabled = true;
};
@@ -1045,9 +1057,9 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.disable_paste = function () {
if (this.paste_enabled) {
- $('#paste_cell_replace').addClass('disabled').off('click');
- $('#paste_cell_above').addClass('disabled').off('click');
- $('#paste_cell_below').addClass('disabled').off('click');
+ $('#paste_cell_replace').addClass('ui-state-disabled').off('click');
+ $('#paste_cell_above').addClass('ui-state-disabled').off('click');
+ $('#paste_cell_below').addClass('ui-state-disabled').off('click');
this.paste_enabled = false;
};
};
@@ -1146,7 +1158,7 @@ var IPython = (function (IPython) {
this.undelete_backup = null;
this.undelete_index = null;
}
- $('#undelete_cell').addClass('disabled');
+ $('#undelete_cell').addClass('ui-state-disabled');
}
// Split/merge
@@ -1370,50 +1382,20 @@ var IPython = (function (IPython) {
this.get_selected_cell().toggle_line_numbers();
};
- // Kernel related things
+ // Session related things
/**
- * Start a new kernel and set it on each code cell.
+ * Start a new session and set it on each code cell.
*
- * @method start_kernel
+ * @method start_session
*/
- Notebook.prototype.start_kernel = function () {
- var base_url = $('body').data('baseKernelUrl') + "kernels";
- this.kernel = new IPython.Kernel(base_url);
- this.kernel.start({notebook: this.notebook_id});
- // Now that the kernel has been created, tell the CodeCells about it.
- var ncells = this.ncells();
- for (var i=0; i").html(
- 'Do you want to restart the current kernel? You will lose all variables defined in it.'
- ),
- buttons : {
- "Continue running" : {},
- "Restart" : {
- "class" : "btn-danger",
- "click" : function() {
- that.kernel.restart();
- }
- }
- }
- });
- };
/**
* Run the selected cell.
@@ -1548,6 +1530,7 @@ var IPython = (function (IPython) {
* @param {Object} data JSON representation of a notebook
*/
Notebook.prototype.fromJSON = function (data) {
+ data = data.content;
var ncells = this.ncells();
var i;
for (i=0; i