From c7ad3aa47de62a9a276f981ce7ec5f44eaef4794 Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 18 Nov 2014 13:59:02 -0800 Subject: [PATCH] Don't dismiss rename dialog until rename is complete - draws error message in the same dialog, rather than triggering a new dialog via events. - `Notebook.rename` returns the contents Promise, rather than registering its own error handler. --- IPython/html/static/notebook/js/notebook.js | 37 +------------- IPython/html/static/notebook/js/savewidget.js | 48 +++++++++++-------- 2 files changed, 31 insertions(+), 54 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 5bd4315a3..798172a7a 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -2066,14 +2066,13 @@ define([ var that = this; var parent = utils.url_path_split(this.notebook_path)[0]; var new_path = utils.url_path_join(parent, new_name); - this.contents.rename(this.notebook_path, new_path).then( + return this.contents.rename(this.notebook_path, new_path).then( function (json) { that.notebook_name = json.name; that.notebook_path = json.path; that.session.rename_notebook(json.path); that.events.trigger('notebook_renamed.Notebook', json); - }, - $.proxy(this.rename_error, this) + } ); }; @@ -2081,38 +2080,6 @@ define([ this.contents.delete(this.notebook_path); }; - Notebook.prototype.rename_error = function (error) { - var that = this; - var dialog_body = $('
').append( - $("

").text('This notebook name already exists.') - ); - this.events.trigger('notebook_rename_failed.Notebook', error); - dialog.modal({ - notebook: this, - keyboard_manager: this.keyboard_manager, - title: "Notebook Rename Error!", - body: dialog_body, - buttons : { - "Cancel": {}, - "OK": { - class: "btn-primary", - click: function () { - that.save_widget.rename_notebook({notebook:that}); - }} - }, - open : function (event, ui) { - var that = $(this); - // Upon ENTER, click the OK button. - that.find('input[type="text"]').keydown(function (event, ui) { - if (event.which === this.keyboard.keycodes.enter) { - that.find('.btn-primary').first().click(); - } - }); - that.find('input[type="text"]').focus(); - } - }); - }; - /** * Request a notebook's data from the server. * diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index 8c7f3338a..2bcd2c568 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -28,7 +28,7 @@ define([ SaveWidget.prototype.bind_events = function () { var that = this; this.element.find('span#notebook_name').click(function () { - that.rename_notebook(); + that.rename_notebook({notebook: that.notebook}); }); this.events.on('notebook_loaded.Notebook', function () { that.update_notebook_name(); @@ -69,9 +69,9 @@ define([ $("
") ).append( $('').attr('type','text').attr('size','25').addClass('form-control') - .val(that.notebook.get_notebook_name()) + .val(options.notebook.get_notebook_name()) ); - dialog.modal({ + var d = dialog.modal({ title: "Rename Notebook", body: dialog_body, notebook: options.notebook, @@ -80,30 +80,40 @@ define([ "OK": { class: "btn-primary", click: function () { - var new_name = $(this).find('input').val(); - if (!that.notebook.test_notebook_name(new_name)) { - $(this).find('.rename-message').text( - "Invalid notebook name. Notebook names must "+ - "have 1 or more characters and can contain any characters " + - "except :/\\. Please enter a new notebook name:" - ); - return false; - } else { - that.notebook.rename(new_name); + var new_name = d.find('input').val(); + if (!options.notebook.test_notebook_name(new_name)) { + d.find('.rename-message').text( + "Invalid notebook name. Notebook names must "+ + "have 1 or more characters and can contain any characters " + + "except :/\\. Please enter a new notebook name:" + ); + return false; + } else { + d.find('.rename-message').text("Renaming..."); + d.find('input[type="text"]').prop('disabled', true); + that.notebook.rename(new_name).then( + function () { + d.modal('hide'); + }, function (error) { + d.find('.rename-message').text(error.message || 'Unknown error'); + d.find('input[type="text"]').prop('disabled', false).focus().select(); + } + ); + return false; + } } - }}, + }, "Cancel": {} }, - open : function (event, ui) { - var that = $(this); + open : function () { // Upon ENTER, click the OK button. - that.find('input[type="text"]').keydown(function (event, ui) { + d.find('input[type="text"]').keydown(function (event) { if (event.which === keyboard.keycodes.enter) { - that.find('.btn-primary').first().click(); + d.find('.btn-primary').first().click(); return false; } }); - that.find('input[type="text"]').focus().select(); + d.find('input[type="text"]').focus().select(); } }); };