From a89d947322573f5ca9172a5ecfa7aac5aeb10834 Mon Sep 17 00:00:00 2001 From: Felix Werner Date: Sun, 16 Oct 2011 18:18:32 +0200 Subject: [PATCH 1/3] Update document title and last_saved_name only after a successful save. --- IPython/frontend/html/notebook/static/js/notebook.js | 1 + IPython/frontend/html/notebook/static/js/savewidget.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index f5fcdc859..e400f5903 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -881,6 +881,7 @@ var IPython = (function (IPython) { Notebook.prototype.notebook_saved = function (data, status, xhr) { this.dirty = false; + IPython.save_widget.notebook_saved(); setTimeout($.proxy(IPython.save_widget.status_save,IPython.save_widget),500); } diff --git a/IPython/frontend/html/notebook/static/js/savewidget.js b/IPython/frontend/html/notebook/static/js/savewidget.js index 148acb6e0..f6918f2bb 100644 --- a/IPython/frontend/html/notebook/static/js/savewidget.js +++ b/IPython/frontend/html/notebook/static/js/savewidget.js @@ -49,6 +49,10 @@ var IPython = (function (IPython) { SaveWidget.prototype.save_notebook = function () { IPython.notebook.save_notebook(); + }; + + + SaveWidget.prototype.notebook_saved = function () { this.set_document_title(); this.last_saved_name = this.get_notebook_name(); }; From f5b52442aa7a42c8ac70d7dc99277611227e6bd5 Mon Sep 17 00:00:00 2001 From: Felix Werner Date: Sun, 16 Oct 2011 18:24:12 +0200 Subject: [PATCH 2/3] Notify the user of errors when saving a notebook. --- IPython/frontend/html/notebook/static/js/notebook.js | 11 ++++++++++- .../frontend/html/notebook/static/js/savewidget.js | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index e400f5903..159a48c0a 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -871,7 +871,8 @@ var IPython = (function (IPython) { type : "PUT", data : JSON.stringify(data), headers : {'Content-Type': 'application/json'}, - success : $.proxy(this.notebook_saved,this) + success : $.proxy(this.notebook_saved,this), + error : $.proxy(this.notebook_save_failed,this) }; IPython.save_widget.status_saving(); $.ajax("/notebooks/" + notebook_id, settings); @@ -886,6 +887,14 @@ var IPython = (function (IPython) { } + Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) { + // Notify the user and reset the save button + // TODO: Handle different types of errors (timeout etc.) + alert('An unexpected error occured while saving the notebook.'); + setTimeout($.proxy(IPython.save_widget.reset_status,IPython.save_widget),500); + } + + Notebook.prototype.load_notebook = function (callback) { var that = this; var notebook_id = IPython.save_widget.get_notebook_id(); diff --git a/IPython/frontend/html/notebook/static/js/savewidget.js b/IPython/frontend/html/notebook/static/js/savewidget.js index f6918f2bb..e3c9844f7 100644 --- a/IPython/frontend/html/notebook/static/js/savewidget.js +++ b/IPython/frontend/html/notebook/static/js/savewidget.js @@ -115,6 +115,11 @@ var IPython = (function (IPython) { }; + SaveWidget.prototype.reset_status = function () { + this.is_renaming(); + }; + + SaveWidget.prototype.status_save = function () { this.element.find('button#save_notebook').button('option', 'label', 'Save'); this.element.find('button#save_notebook').button('enable'); From a4bec7e65db070ad142e9093d6ffc48c1ac480e2 Mon Sep 17 00:00:00 2001 From: Felix Werner Date: Sun, 16 Oct 2011 19:35:18 +0200 Subject: [PATCH 3/3] Fixed testing of new notebook name before saving. --- IPython/frontend/html/notebook/static/js/savewidget.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/savewidget.js b/IPython/frontend/html/notebook/static/js/savewidget.js index e3c9844f7..8aafca8d7 100644 --- a/IPython/frontend/html/notebook/static/js/savewidget.js +++ b/IPython/frontend/html/notebook/static/js/savewidget.js @@ -15,7 +15,7 @@ var IPython = (function (IPython) { var SaveWidget = function (selector) { this.selector = selector; - this.notebook_name_re = /[^/\\]+/ + this.notebook_name_blacklist_re = /[\/\\]/ this.last_saved_name = ''; if (this.selector !== undefined) { this.element = $(selector); @@ -100,14 +100,14 @@ var IPython = (function (IPython) { SaveWidget.prototype.test_notebook_name = function () { var nbname = this.get_notebook_name(); - if (this.notebook_name_re.test(nbname)) { + if (this.notebook_name_blacklist_re.test(nbname) == false) { return true; } else { var bad_name = $('
'); bad_name.html( "The notebook name you entered (" + nbname + - ") is not valid. Notebook names can contain any characters except / and \\" + ") is not valid. Notebook names can contain any characters except / and \\." ); bad_name.dialog({title: 'Invalid name', modal: true}); return false;