Show More
@@ -25,6 +25,10 b' define([' | |||||
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
27 | /** |
|
27 | /** | |
|
28 | * Notebook Functions | |||
|
29 | */ | |||
|
30 | ||||
|
31 | /** | |||
28 | * Creates a new notebook file at the specified path, and |
|
32 | * Creates a new notebook file at the specified path, and | |
29 | * opens that notebook in a new window. |
|
33 | * opens that notebook in a new window. | |
30 | * |
|
34 | * | |
@@ -165,6 +169,10 b' define([' | |||||
165 | $.ajax(url, settings); |
|
169 | $.ajax(url, settings); | |
166 | }; |
|
170 | }; | |
167 |
|
171 | |||
|
172 | /** | |||
|
173 | * Checkpointing Functions | |||
|
174 | */ | |||
|
175 | ||||
168 | ContentManager.prototype.save_checkpoint = function() { |
|
176 | ContentManager.prototype.save_checkpoint = function() { | |
169 | // This is not necessary - integrated into save |
|
177 | // This is not necessary - integrated into save | |
170 | }; |
|
178 | }; | |
@@ -203,6 +211,44 b' define([' | |||||
203 | ); |
|
211 | ); | |
204 | }; |
|
212 | }; | |
205 |
|
213 | |||
|
214 | /** | |||
|
215 | * File management functions | |||
|
216 | */ | |||
|
217 | ||||
|
218 | /** | |||
|
219 | * List notebooks and directories at a given path | |||
|
220 | * | |||
|
221 | * On success, load_callback is called with an array of dictionaries | |||
|
222 | * representing individual files or directories. Each dictionary has | |||
|
223 | * the keys: | |||
|
224 | * type: "notebook" or "directory" | |||
|
225 | * name: the name of the file or directory | |||
|
226 | * created: created date | |||
|
227 | * last_modified: last modified dat | |||
|
228 | * path: the path | |||
|
229 | * @method list_notebooks | |||
|
230 | * @param {String} path The path to list notebooks in | |||
|
231 | * @param {Function} load_callback called with list of notebooks on success | |||
|
232 | * @param {Function} error_callback called with ajax results on error | |||
|
233 | */ | |||
|
234 | ContentManager.prototype.list_contents = function(path, load_callback, | |||
|
235 | error_callback) { | |||
|
236 | var that = this; | |||
|
237 | var settings = { | |||
|
238 | processData : false, | |||
|
239 | cache : false, | |||
|
240 | type : "GET", | |||
|
241 | dataType : "json", | |||
|
242 | success : load_callback, | |||
|
243 | error : error_callback | |||
|
244 | }; | |||
|
245 | ||||
|
246 | var url = utils.url_join_encode(this.base_url, 'api', 'notebooks', | |||
|
247 | path); | |||
|
248 | $.ajax(url, settings); | |||
|
249 | } | |||
|
250 | ||||
|
251 | ||||
206 | IPython.ContentManager = ContentManager; |
|
252 | IPython.ContentManager = ContentManager; | |
207 |
|
253 | |||
208 | return {'ContentManager': ContentManager}; |
|
254 | return {'ContentManager': ContentManager}; |
@@ -156,37 +156,26 b' define([' | |||||
156 | }; |
|
156 | }; | |
157 |
|
157 | |||
158 | NotebookList.prototype.load_list = function () { |
|
158 | NotebookList.prototype.load_list = function () { | |
159 | var that = this; |
|
159 | this.content_manager.list_contents( | |
160 | var settings = { |
|
160 | this.notebook_path, | |
161 | processData : false, |
|
161 | $.proxy(this.draw_notebook_list, this), | |
162 | cache : false, |
|
162 | $.proxy( function(xhr, status, error) { | |
163 | type : "GET", |
|
|||
164 | dataType : "json", |
|
|||
165 | success : $.proxy(this.list_loaded, this), |
|
|||
166 | error : $.proxy( function(xhr, status, error){ |
|
|||
167 | utils.log_ajax_error(xhr, status, error); |
|
163 | utils.log_ajax_error(xhr, status, error); | |
168 |
that.list |
|
164 | that.draw_notebook_list([], "Error connecting to server."); | |
169 |
|
|
165 | }, this) | |
170 | }; |
|
|||
171 |
|
||||
172 | var url = utils.url_join_encode( |
|
|||
173 | this.base_url, |
|
|||
174 | 'api', |
|
|||
175 | 'contents', |
|
|||
176 | this.notebook_path |
|
|||
177 | ); |
|
166 | ); | |
178 | $.ajax(url, settings); |
|
|||
179 | }; |
|
167 | }; | |
180 |
|
168 | |||
181 |
|
169 | /** | ||
182 | NotebookList.prototype.list_loaded = function (data, status, xhr, param) { |
|
170 | * Draw the list of notebooks | |
183 | var message = 'Notebook list empty.'; |
|
171 | * @method draw_notebook_list | |
184 | if (param !== undefined && param.msg) { |
|
172 | * @param {Array} list An array of dictionaries representing files or | |
185 | message = param.msg; |
|
173 | * direcotories. | |
186 | } |
|
174 | * @param {String} error_msg An error message | |
|
175 | */ | |||
|
176 | NotebookList.prototype.draw_notebook_list = function (list, error_msg) { | |||
|
177 | var message = error_msg || 'Notebook list empty.'; | |||
187 | var item = null; |
|
178 | var item = null; | |
188 | var model = null; |
|
|||
189 | var list = data.content; |
|
|||
190 | var len = list.length; |
|
179 | var len = list.length; | |
191 | this.clear_list(); |
|
180 | this.clear_list(); | |
192 | var n_uploads = this.element.children('.list_item').length; |
|
181 | var n_uploads = this.element.children('.list_item').length; | |
@@ -209,9 +198,21 b' define([' | |||||
209 | offset += 1; |
|
198 | offset += 1; | |
210 | } |
|
199 | } | |
211 | for (var i=0; i<len; i++) { |
|
200 | for (var i=0; i<len; i++) { | |
212 | model = list[i]; |
|
201 | if (list[i].type === 'directory') { | |
213 | item = this.new_item(i+offset); |
|
202 | var name = list[i].name; | |
214 | this.add_link(model, item); |
|
203 | item = this.new_notebook_item(i+offset); | |
|
204 | this.add_dir(path, name, item); | |||
|
205 | } else { | |||
|
206 | var name = list[i].name; | |||
|
207 | item = this.new_notebook_item(i+offset); | |||
|
208 | this.add_link(path, name, item); | |||
|
209 | name = utils.url_path_join(path, name); | |||
|
210 | if(this.sessions[name] === undefined){ | |||
|
211 | this.add_delete_button(item); | |||
|
212 | } else { | |||
|
213 | this.add_shutdown_button(item,this.sessions[name]); | |||
|
214 | } | |||
|
215 | } | |||
215 | } |
|
216 | } | |
216 | }; |
|
217 | }; | |
217 |
|
218 |
General Comments 0
You need to be logged in to leave comments.
Login now