Show More
@@ -2066,14 +2066,13 define([ | |||||
2066 | var that = this; |
|
2066 | var that = this; | |
2067 | var parent = utils.url_path_split(this.notebook_path)[0]; |
|
2067 | var parent = utils.url_path_split(this.notebook_path)[0]; | |
2068 | var new_path = utils.url_path_join(parent, new_name); |
|
2068 | var new_path = utils.url_path_join(parent, new_name); | |
2069 | this.contents.rename(this.notebook_path, new_path).then( |
|
2069 | return this.contents.rename(this.notebook_path, new_path).then( | |
2070 | function (json) { |
|
2070 | function (json) { | |
2071 | that.notebook_name = json.name; |
|
2071 | that.notebook_name = json.name; | |
2072 | that.notebook_path = json.path; |
|
2072 | that.notebook_path = json.path; | |
2073 | that.session.rename_notebook(json.path); |
|
2073 | that.session.rename_notebook(json.path); | |
2074 | that.events.trigger('notebook_renamed.Notebook', json); |
|
2074 | that.events.trigger('notebook_renamed.Notebook', json); | |
2075 |
} |
|
2075 | } | |
2076 | $.proxy(this.rename_error, this) |
|
|||
2077 | ); |
|
2076 | ); | |
2078 | }; |
|
2077 | }; | |
2079 |
|
2078 | |||
@@ -2081,38 +2080,6 define([ | |||||
2081 | this.contents.delete(this.notebook_path); |
|
2080 | this.contents.delete(this.notebook_path); | |
2082 | }; |
|
2081 | }; | |
2083 |
|
2082 | |||
2084 | Notebook.prototype.rename_error = function (error) { |
|
|||
2085 | var that = this; |
|
|||
2086 | var dialog_body = $('<div/>').append( |
|
|||
2087 | $("<p/>").text('This notebook name already exists.') |
|
|||
2088 | ); |
|
|||
2089 | this.events.trigger('notebook_rename_failed.Notebook', error); |
|
|||
2090 | dialog.modal({ |
|
|||
2091 | notebook: this, |
|
|||
2092 | keyboard_manager: this.keyboard_manager, |
|
|||
2093 | title: "Notebook Rename Error!", |
|
|||
2094 | body: dialog_body, |
|
|||
2095 | buttons : { |
|
|||
2096 | "Cancel": {}, |
|
|||
2097 | "OK": { |
|
|||
2098 | class: "btn-primary", |
|
|||
2099 | click: function () { |
|
|||
2100 | that.save_widget.rename_notebook({notebook:that}); |
|
|||
2101 | }} |
|
|||
2102 | }, |
|
|||
2103 | open : function (event, ui) { |
|
|||
2104 | var that = $(this); |
|
|||
2105 | // Upon ENTER, click the OK button. |
|
|||
2106 | that.find('input[type="text"]').keydown(function (event, ui) { |
|
|||
2107 | if (event.which === this.keyboard.keycodes.enter) { |
|
|||
2108 | that.find('.btn-primary').first().click(); |
|
|||
2109 | } |
|
|||
2110 | }); |
|
|||
2111 | that.find('input[type="text"]').focus(); |
|
|||
2112 | } |
|
|||
2113 | }); |
|
|||
2114 | }; |
|
|||
2115 |
|
||||
2116 | /** |
|
2083 | /** | |
2117 | * Request a notebook's data from the server. |
|
2084 | * Request a notebook's data from the server. | |
2118 | * |
|
2085 | * |
@@ -28,7 +28,7 define([ | |||||
28 | SaveWidget.prototype.bind_events = function () { |
|
28 | SaveWidget.prototype.bind_events = function () { | |
29 | var that = this; |
|
29 | var that = this; | |
30 | this.element.find('span#notebook_name').click(function () { |
|
30 | this.element.find('span#notebook_name').click(function () { | |
31 | that.rename_notebook(); |
|
31 | that.rename_notebook({notebook: that.notebook}); | |
32 | }); |
|
32 | }); | |
33 | this.events.on('notebook_loaded.Notebook', function () { |
|
33 | this.events.on('notebook_loaded.Notebook', function () { | |
34 | that.update_notebook_name(); |
|
34 | that.update_notebook_name(); | |
@@ -69,9 +69,9 define([ | |||||
69 | $("<br/>") |
|
69 | $("<br/>") | |
70 | ).append( |
|
70 | ).append( | |
71 | $('<input/>').attr('type','text').attr('size','25').addClass('form-control') |
|
71 | $('<input/>').attr('type','text').attr('size','25').addClass('form-control') | |
72 |
.val( |
|
72 | .val(options.notebook.get_notebook_name()) | |
73 | ); |
|
73 | ); | |
74 | dialog.modal({ |
|
74 | var d = dialog.modal({ | |
75 | title: "Rename Notebook", |
|
75 | title: "Rename Notebook", | |
76 | body: dialog_body, |
|
76 | body: dialog_body, | |
77 | notebook: options.notebook, |
|
77 | notebook: options.notebook, | |
@@ -80,30 +80,40 define([ | |||||
80 | "OK": { |
|
80 | "OK": { | |
81 | class: "btn-primary", |
|
81 | class: "btn-primary", | |
82 | click: function () { |
|
82 | click: function () { | |
83 |
var new_name = |
|
83 | var new_name = d.find('input').val(); | |
84 |
if (! |
|
84 | if (!options.notebook.test_notebook_name(new_name)) { | |
85 |
|
|
85 | d.find('.rename-message').text( | |
86 | "Invalid notebook name. Notebook names must "+ |
|
86 | "Invalid notebook name. Notebook names must "+ | |
87 | "have 1 or more characters and can contain any characters " + |
|
87 | "have 1 or more characters and can contain any characters " + | |
88 | "except :/\\. Please enter a new notebook name:" |
|
88 | "except :/\\. Please enter a new notebook name:" | |
89 | ); |
|
89 | ); | |
90 | return false; |
|
90 | return false; | |
91 | } else { |
|
91 | } else { | |
92 |
|
|
92 | d.find('.rename-message').text("Renaming..."); | |
|
93 | d.find('input[type="text"]').prop('disabled', true); | |||
|
94 | that.notebook.rename(new_name).then( | |||
|
95 | function () { | |||
|
96 | d.modal('hide'); | |||
|
97 | }, function (error) { | |||
|
98 | d.find('.rename-message').text(error.message || 'Unknown error'); | |||
|
99 | d.find('input[type="text"]').prop('disabled', false).focus().select(); | |||
|
100 | } | |||
|
101 | ); | |||
|
102 | return false; | |||
|
103 | } | |||
93 | } |
|
104 | } | |
94 |
|
|
105 | }, | |
95 | "Cancel": {} |
|
106 | "Cancel": {} | |
96 | }, |
|
107 | }, | |
97 |
open : function ( |
|
108 | open : function () { | |
98 | var that = $(this); |
|
|||
99 | // Upon ENTER, click the OK button. |
|
109 | // Upon ENTER, click the OK button. | |
100 |
|
|
110 | d.find('input[type="text"]').keydown(function (event) { | |
101 | if (event.which === keyboard.keycodes.enter) { |
|
111 | if (event.which === keyboard.keycodes.enter) { | |
102 |
|
|
112 | d.find('.btn-primary').first().click(); | |
103 | return false; |
|
113 | return false; | |
104 | } |
|
114 | } | |
105 | }); |
|
115 | }); | |
106 |
|
|
116 | d.find('input[type="text"]').focus().select(); | |
107 | } |
|
117 | } | |
108 | }); |
|
118 | }); | |
109 | }; |
|
119 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now