From 41452895cb5fdb423ded8e43d4c397e19d9a48b6 2014-03-25 23:40:24 From: Min RK Date: 2014-03-25 23:40:24 Subject: [PATCH] Merge pull request #5396 from ivanov/fix-5363 prevent saving of partially loaded notebooks --- diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 05cb955..8b7a69a 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -58,6 +58,9 @@ var IPython = (function (IPython) { this.style(); this.create_elements(); this.bind_events(); + this.save_notebook = function() { // don't allow save until notebook_loaded + this.save_notebook_error(null, null, "Load failed, save is disabled"); + }; }; /** @@ -1723,7 +1726,8 @@ var IPython = (function (IPython) { }; /** - * Save this notebook on the server. + * Save this notebook on the server. This becomes a notebook instance's + * .save_notebook method *after* the entire notebook has been loaded. * * @method save_notebook */ @@ -2100,7 +2104,9 @@ var IPython = (function (IPython) { IPython.CellToolbar.global_show(); IPython.CellToolbar.activate_preset(this.metadata.celltoolbar); } - + + // now that we're fully loaded, it is safe to restore save functionality + delete(this.save_notebook); $([IPython.events]).trigger('notebook_loaded.Notebook'); }; diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 87f508e..a2ecad1 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -188,8 +188,8 @@ var IPython = (function (IPython) { $([IPython.events]).on('notebook_saved.Notebook', function () { nnw.set_message("Notebook saved",2000); }); - $([IPython.events]).on('notebook_save_failed.Notebook', function () { - nnw.set_message("Notebook save failed"); + $([IPython.events]).on('notebook_save_failed.Notebook', function (evt, xhr, status, data) { + nnw.set_message(data || "Notebook save failed"); }); // Checkpoint events