mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-19 13:20:36 +08:00
Merge pull request #6975 from minrk/rename-error
Don't dismiss rename dialog until rename is complete
This commit is contained in:
commit
9caf579d8d
@ -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 = $('<div/>').append(
|
||||
$("<p/>").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.
|
||||
*
|
||||
|
@ -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([
|
||||
$("<br/>")
|
||||
).append(
|
||||
$('<input/>').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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user