From 5c6c7a4092ddb5b82bcea770b11a8233a918b64c 2014-03-20 09:21:38
From: Paul Ivanov <pi@berkeley.edu>
Date: 2014-03-20 09:21:38
Subject: [PATCH] prevent saving of partially loaded notebooks

closes #5363

---

diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 05cb955..6681aa2 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 87f508e..9cc5db2 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