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