From c28096f0c5d20884020fb065c605232b3bafee07 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Thu, 20 Mar 2014 02:21:38 -0700 Subject: [PATCH 1/2] prevent saving of partially loaded notebooks closes #5363 --- IPython/html/static/notebook/js/notebook.js | 10 ++++++++-- IPython/html/static/notebook/js/notificationarea.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 05cb955c1..6681aa2c3 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, "Notebook was not fully loaded."); + }; }; /** @@ -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 87f508ef1..9cc5db26f 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("Notebook save failed:" + data); }); // Checkpoint events From f41750ca6b7855728cafe8500809516565a0d02a Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Tue, 25 Mar 2014 16:31:29 -0700 Subject: [PATCH 2/2] address PR feedback --- IPython/html/static/notebook/js/notebook.js | 2 +- IPython/html/static/notebook/js/notificationarea.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 6681aa2c3..8b7a69a1a 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -59,7 +59,7 @@ var IPython = (function (IPython) { this.create_elements(); this.bind_events(); this.save_notebook = function() { // don't allow save until notebook_loaded - this.save_notebook_error(null, null, "Notebook was not fully loaded."); + this.save_notebook_error(null, null, "Load failed, save is disabled"); }; }; diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 9cc5db26f..a2ecad1dc 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -189,7 +189,7 @@ var IPython = (function (IPython) { nnw.set_message("Notebook saved",2000); }); $([IPython.events]).on('notebook_save_failed.Notebook', function (evt, xhr, status, data) { - nnw.set_message("Notebook save failed:" + data); + nnw.set_message(data || "Notebook save failed"); }); // Checkpoint events