Show More
@@ -1929,10 +1929,27 b' define([' | |||
|
1929 | 1929 | nbformat : this.nbformat, |
|
1930 | 1930 | nbformat_minor : this.nbformat_minor |
|
1931 | 1931 | }) |
|
1932 | this.contents.save_notebook(this.notebook_path, | |
|
1933 | this.notebook_name, | |
|
1934 | content, | |
|
1935 | extra_settings); | |
|
1932 | // Create a JSON model to be sent to the server. | |
|
1933 | var model = { | |
|
1934 | name : this.notebook_name, | |
|
1935 | path : this.notebook_path, | |
|
1936 | type : "notebook", | |
|
1937 | content : content | |
|
1938 | }; | |
|
1939 | // time the ajax call for autosave tuning purposes. | |
|
1940 | var start = new Date().getTime(); | |
|
1941 | ||
|
1942 | var that = this; | |
|
1943 | this.contents.save_file(this.notebook_path, this.notebook_name, model, { | |
|
1944 | extra_settings: extra_settings, | |
|
1945 | success_callback: $.proxy(this.events.trigger, this.events, | |
|
1946 | 'notebook_save_success.Contents', | |
|
1947 | $.extend(model, { start : start })), | |
|
1948 | error_callback: function (xhr, status, error) { | |
|
1949 | that.events.trigger('notebook_save_error.Contents', | |
|
1950 | [xhr, status, error, model]); | |
|
1951 | } | |
|
1952 | }); | |
|
1936 | 1953 | }; |
|
1937 | 1954 | |
|
1938 | 1955 | /** |
@@ -2087,18 +2104,26 b' define([' | |||
|
2087 | 2104 | $.ajax(url,settings); |
|
2088 | 2105 | }; |
|
2089 | 2106 | |
|
2090 |
Notebook.prototype.rename = function (n |
|
|
2091 |
if (!n |
|
|
2092 |
n |
|
|
2107 | Notebook.prototype.rename = function (new_name) { | |
|
2108 | if (!new_name.match(/\.ipynb$/)) { | |
|
2109 | new_name = new_name + ".ipynb"; | |
|
2093 | 2110 | } |
|
2094 | 2111 | |
|
2095 | this.contents.rename_notebook(this.notebook_path, | |
|
2096 | this.notebook_name, nbname); | |
|
2112 | var that = this; | |
|
2113 | this.contents.rename_file(this.notebook_path, this.notebook_name, | |
|
2114 | this.notebook_path, new_name, { | |
|
2115 | success_callback: function (json, status, xhr) { | |
|
2116 | that.events.trigger('notebook_rename_success.Contents', json); | |
|
2117 | }, | |
|
2118 | error_callback: function (xhr, status, error) { | |
|
2119 | that.events.trigger('notebook_rename_error.Contents', | |
|
2120 | [xhr, status, error]); | |
|
2121 | } | |
|
2122 | }); | |
|
2097 | 2123 | }; |
|
2098 | 2124 | |
|
2099 | 2125 | Notebook.prototype.delete = function () { |
|
2100 |
this.contents.delete_ |
|
|
2101 | this.notebook_path); | |
|
2126 | this.contents.delete_file(this.notebook_name, this.notebook_path); | |
|
2102 | 2127 | }; |
|
2103 | 2128 | |
|
2104 | 2129 | Notebook.prototype.rename_error = function (xhr, status, error) { |
@@ -2142,11 +2167,10 b' define([' | |||
|
2142 | 2167 | Notebook.prototype.load_notebook = function (notebook_name, notebook_path) { |
|
2143 | 2168 | this.notebook_name = notebook_name; |
|
2144 | 2169 | this.notebook_path = notebook_path; |
|
2145 |
this.contents.load_ |
|
|
2146 | notebook_path, | |
|
2147 | notebook_name, | |
|
2148 | $.proxy(this.load_notebook_success,this), | |
|
2149 | $.proxy(this.load_notebook_error,this)); | |
|
2170 | this.contents.load_file(notebook_path, notebook_name, { | |
|
2171 | success_callback: $.proxy(this.load_notebook_success, this), | |
|
2172 | error_callback: $.proxy(this.load_notebook_error, this) | |
|
2173 | }); | |
|
2150 | 2174 | }; |
|
2151 | 2175 | |
|
2152 | 2176 | /** |
@@ -30,14 +30,13 b' define([' | |||
|
30 | 30 | }; |
|
31 | 31 | |
|
32 | 32 | /** |
|
33 | * Notebook Functions | |
|
33 | * File Functions (including notebook operations) | |
|
34 | 34 | */ |
|
35 | 35 | |
|
36 | 36 | /** |
|
37 |
* Load a |
|
|
37 | * Load a file. | |
|
38 | 38 | * |
|
39 |
* Calls success_callback with |
|
|
40 | * error_callback with error. | |
|
39 | * Calls success_callback with file JSON model, or error_callback with error. | |
|
41 | 40 | * |
|
42 | 41 | * @method load_notebook |
|
43 | 42 | * @param {String} path |
@@ -45,16 +44,15 b' define([' | |||
|
45 | 44 | * @param {Function} success_callback |
|
46 | 45 | * @param {Function} error_callback |
|
47 | 46 | */ |
|
48 |
Contents.prototype.load_ |
|
|
49 | error_callback) { | |
|
47 | Contents.prototype.load_file = function (path, name, options) { | |
|
50 | 48 | // We do the call with settings so we can set cache to false. |
|
51 | 49 | var settings = { |
|
52 | 50 | processData : false, |
|
53 | 51 | cache : false, |
|
54 | 52 | type : "GET", |
|
55 | 53 | dataType : "json", |
|
56 | success : success_callback, | |
|
57 |
error : error_callback |
|
|
54 | success : options.success_callback, | |
|
55 | error : options.error_callback || function() {} | |
|
58 | 56 | }; |
|
59 | 57 | this.events.trigger('notebook_loading.Notebook'); |
|
60 | 58 | var url = this.api_url(path, name); |
@@ -63,52 +61,44 b' define([' | |||
|
63 | 61 | |
|
64 | 62 | |
|
65 | 63 | /** |
|
66 |
* Creates a new notebook file at the specified |
|
|
67 | * opens that notebook in a new window. | |
|
64 | * Creates a new notebook file at the specified directory path. | |
|
68 | 65 | * |
|
69 | 66 | * @method scroll_to_cell |
|
70 | 67 | * @param {String} path The path to create the new notebook at |
|
71 | 68 | */ |
|
72 | 69 | Contents.prototype.new_notebook = function(path, options) { |
|
73 | var base_url = this.base_url; | |
|
74 | var success_callback = options.success_callback || function(data, status, xhr) {}; | |
|
75 | var error_callback = options.error_callback || function(xhr, status, error) {}; | |
|
70 | var error_callback = options.error_callback || function() {}; | |
|
76 | 71 | var settings = { |
|
77 | 72 | processData : false, |
|
78 | 73 | cache : false, |
|
79 | 74 | type : "POST", |
|
80 | 75 | dataType : "json", |
|
81 | async : false, | |
|
82 | success : success_callback, | |
|
83 | error : function(xhr, status, error) { | |
|
84 | utils.log_ajax_error(xhr, status, error); | |
|
85 | error_callback(xhr, status, error); | |
|
86 | } | |
|
76 | success : options.success_callback || function() {}, | |
|
77 | error : options.error_callback || function() {} | |
|
87 | 78 | }; |
|
88 | 79 | $.ajax(this.api_url(path), settings); |
|
89 | 80 | }; |
|
90 | 81 | |
|
91 |
Contents.prototype.delete_ |
|
|
82 | Contents.prototype.delete_file = function(name, path, options) { | |
|
83 | var error_callback = options.error_callback || function() {}; | |
|
84 | var that = this; | |
|
92 | 85 | var settings = { |
|
93 | 86 | processData : false, |
|
94 | 87 | cache : false, |
|
95 | 88 | type : "DELETE", |
|
96 | 89 | dataType : "json", |
|
97 | success : $.proxy(this.events.trigger, this.events, | |
|
98 | 'notebook_deleted.Contents', | |
|
99 | { | |
|
100 | name: name, | |
|
101 | path: path | |
|
102 | }), | |
|
103 | error : utils.log_ajax_error | |
|
90 | success : options.success_callback || function() {}, | |
|
91 | error : function(xhr, status, error) { | |
|
92 | utils.log_ajax_error(xhr, status, error); | |
|
93 | error_callback(xhr, status, error); | |
|
94 | } | |
|
104 | 95 | }; |
|
105 | 96 | var url = this.api_url(path, name); |
|
106 | 97 | $.ajax(url, settings); |
|
107 | 98 | }; |
|
108 | 99 | |
|
109 |
Contents.prototype.rename_ |
|
|
110 | var that = this; | |
|
111 | var data = {name: new_name}; | |
|
100 | Contents.prototype.rename_file = function(path, name, new_path, new_name, options) { | |
|
101 | var data = {name: new_name, path: new_path}; | |
|
112 | 102 | var settings = { |
|
113 | 103 | processData : false, |
|
114 | 104 | cache : false, |
@@ -116,31 +106,14 b' define([' | |||
|
116 | 106 | data : JSON.stringify(data), |
|
117 | 107 | dataType: "json", |
|
118 | 108 | contentType: 'application/json', |
|
119 | success : function (json, status, xhr) { | |
|
120 | that.events.trigger('notebook_rename_success.Contents', | |
|
121 | json); | |
|
122 | }, | |
|
123 | error : function (xhr, status, error) { | |
|
124 | that.events.trigger('notebook_rename_error.Contents', | |
|
125 | [xhr, status, error]); | |
|
126 | } | |
|
109 | success : options.success_callback || function() {}, | |
|
110 | error : options.error_callback || function() {} | |
|
127 | 111 | }; |
|
128 | 112 | var url = this.api_url(path, name); |
|
129 | 113 | $.ajax(url, settings); |
|
130 | 114 | }; |
|
131 | 115 | |
|
132 |
Contents.prototype.save_ |
|
|
133 | extra_settings) { | |
|
134 | var that = content; | |
|
135 | // Create a JSON model to be sent to the server. | |
|
136 | var model = { | |
|
137 | name : name, | |
|
138 | path : path, | |
|
139 | type : "notebook", | |
|
140 | content : content | |
|
141 | }; | |
|
142 | // time the ajax call for autosave tuning purposes. | |
|
143 | var start = new Date().getTime(); | |
|
116 | Contents.prototype.save_file = function(path, name, model, options) { | |
|
144 | 117 | // We do the call with settings so we can set cache to false. |
|
145 | 118 | var settings = { |
|
146 | 119 | processData : false, |
@@ -148,18 +121,11 b' define([' | |||
|
148 | 121 | type : "PUT", |
|
149 | 122 | data : JSON.stringify(model), |
|
150 | 123 | contentType: 'application/json', |
|
151 | success : $.proxy(this.events.trigger, this.events, | |
|
152 | 'notebook_save_success.Contents', | |
|
153 | $.extend(model, { start : start })), | |
|
154 | error : function (xhr, status, error) { | |
|
155 | that.events.trigger('notebook_save_error.Contents', | |
|
156 | [xhr, status, error, model]); | |
|
157 | } | |
|
124 | success : options.success_callback || function() {}, | |
|
125 | error : options.error_callback || function() {} | |
|
158 | 126 | }; |
|
159 | if (extra_settings) { | |
|
160 |
|
|
|
161 | settings[key] = extra_settings[key]; | |
|
162 | } | |
|
127 | if (options.extra_settings) { | |
|
128 | $.extend(settings, options.extra_settings); | |
|
163 | 129 | } |
|
164 | 130 | var url = this.api_url(path, name); |
|
165 | 131 | $.ajax(url, settings); |
@@ -173,8 +139,8 b' define([' | |||
|
173 | 139 | var url = this.api_url(path, name, 'checkpoints'); |
|
174 | 140 | var settings = { |
|
175 | 141 | type : "POST", |
|
176 |
success: options.success_callback || function( |
|
|
177 |
error: options.error_callback || function( |
|
|
142 | success: options.success_callback || function() {}, | |
|
143 | error: options.error_callback || function() {} | |
|
178 | 144 | }; |
|
179 | 145 | $.ajax(url, settings); |
|
180 | 146 | }; |
@@ -183,8 +149,8 b' define([' | |||
|
183 | 149 | var url = this.api_url(path, name, 'checkpoints'); |
|
184 | 150 | var settings = { |
|
185 | 151 | type : "GET", |
|
186 |
success: options.success_callback |
|
|
187 |
error: options.error_callback || function( |
|
|
152 | success: options.success_callback, | |
|
153 | error: options.error_callback || function() {} | |
|
188 | 154 | }; |
|
189 | 155 | $.ajax(url, settings); |
|
190 | 156 | }; |
@@ -193,8 +159,8 b' define([' | |||
|
193 | 159 | var url = this.api_url(path, name, 'checkpoints', checkpoint_id); |
|
194 | 160 | var settings = { |
|
195 | 161 | type : "POST", |
|
196 |
success: options.success_callback || function( |
|
|
197 |
error: options.error_callback || function( |
|
|
162 | success: options.success_callback || function() {}, | |
|
163 | error: options.error_callback || function() {} | |
|
198 | 164 | }; |
|
199 | 165 | $.ajax(url, settings); |
|
200 | 166 | }; |
@@ -203,8 +169,8 b' define([' | |||
|
203 | 169 | var url = this.api_url(path, name, 'checkpoints', checkpoint_id); |
|
204 | 170 | var settings = { |
|
205 | 171 | type : "DELETE", |
|
206 |
success: options.success_callback || function( |
|
|
207 |
error: options.error_callback || function( |
|
|
172 | success: options.success_callback || function() {}, | |
|
173 | error: options.error_callback || function() {} | |
|
208 | 174 | }; |
|
209 | 175 | $.ajax(url, settings); |
|
210 | 176 | }; |
@@ -229,15 +195,14 b' define([' | |||
|
229 | 195 | * @param {Function} load_callback called with list of notebooks on success |
|
230 | 196 | * @param {Function} error_callback called with ajax results on error |
|
231 | 197 | */ |
|
232 |
Contents.prototype.list_contents = function(path, |
|
|
233 | error_callback) { | |
|
198 | Contents.prototype.list_contents = function(path, options) { | |
|
234 | 199 | var settings = { |
|
235 | 200 | processData : false, |
|
236 | 201 | cache : false, |
|
237 | 202 | type : "GET", |
|
238 | 203 | dataType : "json", |
|
239 |
success : |
|
|
240 | error : error_callback | |
|
204 | success : options.success_callback, | |
|
205 | error : options.error_callback || function() {} | |
|
241 | 206 | }; |
|
242 | 207 | |
|
243 | 208 | $.ajax(this.api_url(path), settings); |
@@ -157,14 +157,13 b' define([' | |||
|
157 | 157 | |
|
158 | 158 | NotebookList.prototype.load_list = function () { |
|
159 | 159 | var that = this |
|
160 | this.contents.list_contents( | |
|
161 | that.notebook_path, | |
|
162 | $.proxy(that.draw_notebook_list, that), | |
|
163 | $.proxy( function(xhr, status, error) { | |
|
160 | this.contents.list_contents(that.notebook_path, { | |
|
161 | success_callback: $.proxy(this.draw_notebook_list, this), | |
|
162 | error_callback: function(xhr, status, error) { | |
|
164 | 163 | utils.log_ajax_error(xhr, status, error); |
|
165 | 164 | that.draw_notebook_list([], "Error connecting to server."); |
|
166 |
} |
|
|
167 | ); | |
|
165 | } | |
|
166 | }); | |
|
168 | 167 | }; |
|
169 | 168 | |
|
170 | 169 | /** |
@@ -347,7 +346,12 b' define([' | |||
|
347 | 346 | Delete : { |
|
348 | 347 | class: "btn-danger", |
|
349 | 348 | click: function() { |
|
350 |
notebooklist.contents.delete_ |
|
|
349 | notebooklist.contents.delete_file(nbname, path, { | |
|
350 | success_callback: function() { | |
|
351 | that.events.trigger('notebook_deleted.Contents', | |
|
352 | {name: name, path: path}); | |
|
353 | } | |
|
354 | }); | |
|
351 | 355 | } |
|
352 | 356 | }, |
|
353 | 357 | Cancel : {} |
General Comments 0
You need to be logged in to leave comments.
Login now