User notification if notebook saving fails #883

Closed
wants to merge 4 commits into from
View
12 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);
@@ -881,10 +882,19 @@ 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);
}
+ 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();
View
15 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);
@@ -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();
};
@@ -96,21 +100,26 @@ 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 = $('<div/>');
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;
};
};
+ SaveWidget.prototype.reset_status = function () {
+ this.is_renaming();
+ };
+
+
SaveWidget.prototype.status_save = function () {
this.element.find('button#save_notebook').button('option', 'label', '<u>S</u>ave');
this.element.find('button#save_notebook').button('enable');