##// END OF EJS Templates
contents.new_untitled to match Python API
Min RK -
Show More
@@ -1,360 +1,360 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 define([
5 5 'jquery',
6 6 'base/js/namespace',
7 7 'base/js/dialog',
8 8 'base/js/utils',
9 9 'notebook/js/tour',
10 10 'bootstrap',
11 11 'moment',
12 12 ], function($, IPython, dialog, utils, tour, bootstrap, moment) {
13 13 "use strict";
14 14
15 15 var MenuBar = function (selector, options) {
16 16 // Constructor
17 17 //
18 18 // A MenuBar Class to generate the menubar of IPython notebook
19 19 //
20 20 // Parameters:
21 21 // selector: string
22 22 // options: dictionary
23 23 // Dictionary of keyword arguments.
24 24 // notebook: Notebook instance
25 25 // contents: ContentManager instance
26 26 // layout_manager: LayoutManager instance
27 27 // events: $(Events) instance
28 28 // save_widget: SaveWidget instance
29 29 // quick_help: QuickHelp instance
30 30 // base_url : string
31 31 // notebook_path : string
32 32 // notebook_name : string
33 33 options = options || {};
34 34 this.base_url = options.base_url || utils.get_body_data("baseUrl");
35 35 this.selector = selector;
36 36 this.notebook = options.notebook;
37 37 this.contents = options.contents;
38 38 this.layout_manager = options.layout_manager;
39 39 this.events = options.events;
40 40 this.save_widget = options.save_widget;
41 41 this.quick_help = options.quick_help;
42 42
43 43 try {
44 44 this.tour = new tour.Tour(this.notebook, this.events);
45 45 } catch (e) {
46 46 this.tour = undefined;
47 47 console.log("Failed to instantiate Notebook Tour", e);
48 48 }
49 49
50 50 if (this.selector !== undefined) {
51 51 this.element = $(selector);
52 52 this.style();
53 53 this.bind_events();
54 54 }
55 55 };
56 56
57 57 // TODO: This has definitively nothing to do with style ...
58 58 MenuBar.prototype.style = function () {
59 59 var that = this;
60 60 this.element.find("li").click(function (event, ui) {
61 61 // The selected cell loses focus when the menu is entered, so we
62 62 // re-select it upon selection.
63 63 var i = that.notebook.get_selected_index();
64 64 that.notebook.select(i);
65 65 }
66 66 );
67 67 };
68 68
69 69 MenuBar.prototype._nbconvert = function (format, download) {
70 70 download = download || false;
71 71 var notebook_path = this.notebook.notebook_path;
72 72 var notebook_name = this.notebook.notebook_name;
73 73 if (this.notebook.dirty) {
74 74 this.notebook.save_notebook({async : false});
75 75 }
76 76 var url = utils.url_join_encode(
77 77 this.base_url,
78 78 'nbconvert',
79 79 format,
80 80 notebook_path,
81 81 notebook_name
82 82 ) + "?download=" + download.toString();
83 83
84 84 window.open(url);
85 85 };
86 86
87 87 MenuBar.prototype.bind_events = function () {
88 88 // File
89 89 var that = this;
90 90 this.element.find('#new_notebook').click(function () {
91 91 // Create a new notebook in the same path as the current
92 92 // notebook's path.
93 93 var parent = utils.url_path_split(that.notebook.notebook_path)[0];
94 that.contents.new(parent, {
94 that.contents.new_untitled(parent, {
95 95 type: "notebook",
96 96 extra_settings: {async: false}, // So we can open a new window afterwards
97 97 success: function (data) {
98 98 window.open(
99 99 utils.url_join_encode(
100 100 that.base_url, 'notebooks', data.path
101 101 ), '_blank');
102 102 },
103 103 error: function(error) {
104 104 dialog.modal({
105 105 title : 'Creating Notebook Failed',
106 106 body : "The error was: " + error.message,
107 107 buttons : {'OK' : {'class' : 'btn-primary'}}
108 108 });
109 109 }
110 110 });
111 111 });
112 112 this.element.find('#open_notebook').click(function () {
113 113 window.open(utils.url_join_encode(
114 114 that.notebook.base_url,
115 115 'tree',
116 116 that.notebook.notebook_path
117 117 ));
118 118 });
119 119 this.element.find('#copy_notebook').click(function () {
120 120 that.notebook.copy_notebook();
121 121 return false;
122 122 });
123 123 this.element.find('#download_ipynb').click(function () {
124 124 var base_url = that.notebook.base_url;
125 125 var notebook_path = that.notebook.notebook_path;
126 126 var notebook_name = that.notebook.notebook_name;
127 127 if (that.notebook.dirty) {
128 128 that.notebook.save_notebook({async : false});
129 129 }
130 130
131 131 var url = utils.url_join_encode(
132 132 base_url,
133 133 'files',
134 134 notebook_path,
135 135 notebook_name
136 136 );
137 137 window.open(url + '?download=1');
138 138 });
139 139
140 140 this.element.find('#print_preview').click(function () {
141 141 that._nbconvert('html', false);
142 142 });
143 143
144 144 this.element.find('#download_py').click(function () {
145 145 that._nbconvert('python', true);
146 146 });
147 147
148 148 this.element.find('#download_html').click(function () {
149 149 that._nbconvert('html', true);
150 150 });
151 151
152 152 this.element.find('#download_rst').click(function () {
153 153 that._nbconvert('rst', true);
154 154 });
155 155
156 156 this.element.find('#download_pdf').click(function () {
157 157 that._nbconvert('pdf', true);
158 158 });
159 159
160 160 this.element.find('#rename_notebook').click(function () {
161 161 that.save_widget.rename_notebook({notebook: that.notebook});
162 162 });
163 163 this.element.find('#save_checkpoint').click(function () {
164 164 that.notebook.save_checkpoint();
165 165 });
166 166 this.element.find('#restore_checkpoint').click(function () {
167 167 });
168 168 this.element.find('#trust_notebook').click(function () {
169 169 that.notebook.trust_notebook();
170 170 });
171 171 this.events.on('trust_changed.Notebook', function (event, trusted) {
172 172 if (trusted) {
173 173 that.element.find('#trust_notebook')
174 174 .addClass("disabled")
175 175 .find("a").text("Trusted Notebook");
176 176 } else {
177 177 that.element.find('#trust_notebook')
178 178 .removeClass("disabled")
179 179 .find("a").text("Trust Notebook");
180 180 }
181 181 });
182 182 this.element.find('#kill_and_exit').click(function () {
183 183 var close_window = function () {
184 184 // allow closing of new tabs in Chromium, impossible in FF
185 185 window.open('', '_self', '');
186 186 window.close();
187 187 };
188 188 // finish with close on success or failure
189 189 that.notebook.session.delete(close_window, close_window);
190 190 });
191 191 // Edit
192 192 this.element.find('#cut_cell').click(function () {
193 193 that.notebook.cut_cell();
194 194 });
195 195 this.element.find('#copy_cell').click(function () {
196 196 that.notebook.copy_cell();
197 197 });
198 198 this.element.find('#delete_cell').click(function () {
199 199 that.notebook.delete_cell();
200 200 });
201 201 this.element.find('#undelete_cell').click(function () {
202 202 that.notebook.undelete_cell();
203 203 });
204 204 this.element.find('#split_cell').click(function () {
205 205 that.notebook.split_cell();
206 206 });
207 207 this.element.find('#merge_cell_above').click(function () {
208 208 that.notebook.merge_cell_above();
209 209 });
210 210 this.element.find('#merge_cell_below').click(function () {
211 211 that.notebook.merge_cell_below();
212 212 });
213 213 this.element.find('#move_cell_up').click(function () {
214 214 that.notebook.move_cell_up();
215 215 });
216 216 this.element.find('#move_cell_down').click(function () {
217 217 that.notebook.move_cell_down();
218 218 });
219 219 this.element.find('#edit_nb_metadata').click(function () {
220 220 that.notebook.edit_metadata({
221 221 notebook: that.notebook,
222 222 keyboard_manager: that.notebook.keyboard_manager});
223 223 });
224 224
225 225 // View
226 226 this.element.find('#toggle_header').click(function () {
227 227 $('div#header').toggle();
228 228 that.layout_manager.do_resize();
229 229 });
230 230 this.element.find('#toggle_toolbar').click(function () {
231 231 $('div#maintoolbar').toggle();
232 232 that.layout_manager.do_resize();
233 233 });
234 234 // Insert
235 235 this.element.find('#insert_cell_above').click(function () {
236 236 that.notebook.insert_cell_above('code');
237 237 that.notebook.select_prev();
238 238 });
239 239 this.element.find('#insert_cell_below').click(function () {
240 240 that.notebook.insert_cell_below('code');
241 241 that.notebook.select_next();
242 242 });
243 243 // Cell
244 244 this.element.find('#run_cell').click(function () {
245 245 that.notebook.execute_cell();
246 246 });
247 247 this.element.find('#run_cell_select_below').click(function () {
248 248 that.notebook.execute_cell_and_select_below();
249 249 });
250 250 this.element.find('#run_cell_insert_below').click(function () {
251 251 that.notebook.execute_cell_and_insert_below();
252 252 });
253 253 this.element.find('#run_all_cells').click(function () {
254 254 that.notebook.execute_all_cells();
255 255 });
256 256 this.element.find('#run_all_cells_above').click(function () {
257 257 that.notebook.execute_cells_above();
258 258 });
259 259 this.element.find('#run_all_cells_below').click(function () {
260 260 that.notebook.execute_cells_below();
261 261 });
262 262 this.element.find('#to_code').click(function () {
263 263 that.notebook.to_code();
264 264 });
265 265 this.element.find('#to_markdown').click(function () {
266 266 that.notebook.to_markdown();
267 267 });
268 268 this.element.find('#to_raw').click(function () {
269 269 that.notebook.to_raw();
270 270 });
271 271
272 272 this.element.find('#toggle_current_output').click(function () {
273 273 that.notebook.toggle_output();
274 274 });
275 275 this.element.find('#toggle_current_output_scroll').click(function () {
276 276 that.notebook.toggle_output_scroll();
277 277 });
278 278 this.element.find('#clear_current_output').click(function () {
279 279 that.notebook.clear_output();
280 280 });
281 281
282 282 this.element.find('#toggle_all_output').click(function () {
283 283 that.notebook.toggle_all_output();
284 284 });
285 285 this.element.find('#toggle_all_output_scroll').click(function () {
286 286 that.notebook.toggle_all_output_scroll();
287 287 });
288 288 this.element.find('#clear_all_output').click(function () {
289 289 that.notebook.clear_all_output();
290 290 });
291 291
292 292 // Kernel
293 293 this.element.find('#int_kernel').click(function () {
294 294 that.notebook.kernel.interrupt();
295 295 });
296 296 this.element.find('#restart_kernel').click(function () {
297 297 that.notebook.restart_kernel();
298 298 });
299 299 this.element.find('#reconnect_kernel').click(function () {
300 300 that.notebook.kernel.reconnect();
301 301 });
302 302 // Help
303 303 if (this.tour) {
304 304 this.element.find('#notebook_tour').click(function () {
305 305 that.tour.start();
306 306 });
307 307 } else {
308 308 this.element.find('#notebook_tour').addClass("disabled");
309 309 }
310 310 this.element.find('#keyboard_shortcuts').click(function () {
311 311 that.quick_help.show_keyboard_shortcuts();
312 312 });
313 313
314 314 this.update_restore_checkpoint(null);
315 315
316 316 this.events.on('checkpoints_listed.Notebook', function (event, data) {
317 317 that.update_restore_checkpoint(that.notebook.checkpoints);
318 318 });
319 319
320 320 this.events.on('checkpoint_created.Notebook', function (event, data) {
321 321 that.update_restore_checkpoint(that.notebook.checkpoints);
322 322 });
323 323 };
324 324
325 325 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
326 326 var ul = this.element.find("#restore_checkpoint").find("ul");
327 327 ul.empty();
328 328 if (!checkpoints || checkpoints.length === 0) {
329 329 ul.append(
330 330 $("<li/>")
331 331 .addClass("disabled")
332 332 .append(
333 333 $("<a/>")
334 334 .text("No checkpoints")
335 335 )
336 336 );
337 337 return;
338 338 }
339 339
340 340 var that = this;
341 341 checkpoints.map(function (checkpoint) {
342 342 var d = new Date(checkpoint.last_modified);
343 343 ul.append(
344 344 $("<li/>").append(
345 345 $("<a/>")
346 346 .attr("href", "#")
347 347 .text(moment(d).format("LLLL"))
348 348 .click(function () {
349 349 that.notebook.restore_checkpoint_dialog(checkpoint);
350 350 })
351 351 )
352 352 );
353 353 });
354 354 };
355 355
356 356 // Backwards compatability.
357 357 IPython.MenuBar = MenuBar;
358 358
359 359 return {'MenuBar': MenuBar};
360 360 });
@@ -1,273 +1,273 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 define([
5 5 'base/js/namespace',
6 6 'jquery',
7 7 'base/js/utils',
8 8 ], function(IPython, $, utils) {
9 9 var Contents = function(options) {
10 10 // Constructor
11 11 //
12 12 // A contents handles passing file operations
13 13 // to the back-end. This includes checkpointing
14 14 // with the normal file operations.
15 15 //
16 16 // Parameters:
17 17 // options: dictionary
18 18 // Dictionary of keyword arguments.
19 19 // base_url: string
20 20 this.base_url = options.base_url;
21 21 };
22 22
23 23 /** Error type */
24 24 Contents.DIRECTORY_NOT_EMPTY_ERROR = 'DirectoryNotEmptyError';
25 25
26 26 Contents.DirectoryNotEmptyError = function() {
27 27 // Constructor
28 28 //
29 29 // An error representing the result of attempting to delete a non-empty
30 30 // directory.
31 31 this.message = 'A directory must be empty before being deleted.';
32 32 };
33 33
34 34 Contents.DirectoryNotEmptyError.prototype = Object.create(Error.prototype);
35 35 Contents.DirectoryNotEmptyError.prototype.name =
36 36 Contents.DIRECTORY_NOT_EMPTY_ERROR;
37 37
38 38
39 39 Contents.prototype.api_url = function() {
40 40 var url_parts = [this.base_url, 'api/contents'].concat(
41 41 Array.prototype.slice.apply(arguments));
42 42 return utils.url_join_encode.apply(null, url_parts);
43 43 };
44 44
45 45 /**
46 46 * Creates a basic error handler that wraps a jqXHR error as an Error.
47 47 *
48 48 * Takes a callback that accepts an Error, and returns a callback that can
49 49 * be passed directly to $.ajax, which will wrap the error from jQuery
50 50 * as an Error, and pass that to the original callback.
51 51 *
52 52 * @method create_basic_error_handler
53 53 * @param{Function} callback
54 54 * @return{Function}
55 55 */
56 56 Contents.prototype.create_basic_error_handler = function(callback) {
57 57 if (!callback) {
58 58 return utils.log_ajax_error;
59 59 }
60 60 return function(xhr, status, error) {
61 61 callback(utils.wrap_ajax_error(xhr, status, error));
62 62 };
63 63 };
64 64
65 65 /**
66 66 * File Functions (including notebook operations)
67 67 */
68 68
69 69 /**
70 70 * Get a file.
71 71 *
72 72 * Calls success with file JSON model, or error with error.
73 73 *
74 74 * @method get
75 75 * @param {String} path
76 76 * @param {Function} success
77 77 * @param {Function} error
78 78 */
79 79 Contents.prototype.get = function (path, options) {
80 80 // We do the call with settings so we can set cache to false.
81 81 var settings = {
82 82 processData : false,
83 83 cache : false,
84 84 type : "GET",
85 85 dataType : "json",
86 86 success : options.success,
87 87 error : this.create_basic_error_handler(options.error)
88 88 };
89 89 var url = this.api_url(path);
90 90 $.ajax(url, settings);
91 91 };
92 92
93 93
94 94 /**
95 * Creates a new file at the specified directory path.
95 * Creates a new untitled file or directory in the specified directory path.
96 96 *
97 97 * @method new
98 * @param {String} path The path to create the new notebook at
98 * @param {String} path: the directory in which to create the new file/directory
99 99 * @param {Object} options:
100 100 * ext: file extension to use
101 101 * type: model type to create ('notebook', 'file', or 'directory')
102 102 */
103 Contents.prototype.new = function(path, options) {
103 Contents.prototype.new_untitled = function(path, options) {
104 104 var data = JSON.stringify({
105 105 ext: options.ext,
106 106 type: options.type
107 107 });
108 108
109 109 var settings = {
110 110 processData : false,
111 111 type : "POST",
112 112 data: data,
113 113 dataType : "json",
114 114 success : options.success || function() {},
115 115 error : this.create_basic_error_handler(options.error)
116 116 };
117 117 if (options.extra_settings) {
118 118 $.extend(settings, options.extra_settings);
119 119 }
120 120 $.ajax(this.api_url(path), settings);
121 121 };
122 122
123 123 Contents.prototype.delete = function(path, options) {
124 124 var error_callback = options.error || function() {};
125 125 var settings = {
126 126 processData : false,
127 127 type : "DELETE",
128 128 dataType : "json",
129 129 success : options.success || function() {},
130 130 error : function(xhr, status, error) {
131 131 // TODO: update IPEP27 to specify errors more precisely, so
132 132 // that error types can be detected here with certainty.
133 133 if (xhr.status === 400) {
134 134 error_callback(new Contents.DirectoryNotEmptyError());
135 135 }
136 136 error_callback(utils.wrap_ajax_error(xhr, status, error));
137 137 }
138 138 };
139 139 var url = this.api_url(path);
140 140 $.ajax(url, settings);
141 141 };
142 142
143 143 Contents.prototype.rename = function(path, new_path, options) {
144 144 var data = {path: new_path};
145 145 var settings = {
146 146 processData : false,
147 147 type : "PATCH",
148 148 data : JSON.stringify(data),
149 149 dataType: "json",
150 150 contentType: 'application/json',
151 151 success : options.success || function() {},
152 152 error : this.create_basic_error_handler(options.error)
153 153 };
154 154 var url = this.api_url(path);
155 155 $.ajax(url, settings);
156 156 };
157 157
158 158 Contents.prototype.save = function(path, model, options) {
159 159 // We do the call with settings so we can set cache to false.
160 160 var settings = {
161 161 processData : false,
162 162 type : "PUT",
163 163 data : JSON.stringify(model),
164 164 contentType: 'application/json',
165 165 success : options.success || function() {},
166 166 error : this.create_basic_error_handler(options.error)
167 167 };
168 168 if (options.extra_settings) {
169 169 $.extend(settings, options.extra_settings);
170 170 }
171 171 var url = this.api_url(path);
172 172 $.ajax(url, settings);
173 173 };
174 174
175 175 Contents.prototype.copy = function(from_file, to_dir, options) {
176 176 // Copy a file into a given directory via POST
177 177 // The server will select the name of the copied file
178 178 var url = this.api_url(to_dir);
179 179
180 180 var settings = {
181 181 processData : false,
182 182 type: "POST",
183 183 data: JSON.stringify({copy_from: from_file}),
184 184 dataType : "json",
185 185 success: options.success || function() {},
186 186 error: this.create_basic_error_handler(options.error)
187 187 };
188 188 if (options.extra_settings) {
189 189 $.extend(settings, options.extra_settings);
190 190 }
191 191 $.ajax(url, settings);
192 192 };
193 193
194 194 /**
195 195 * Checkpointing Functions
196 196 */
197 197
198 198 Contents.prototype.create_checkpoint = function(path, options) {
199 199 var url = this.api_url(path, 'checkpoints');
200 200 var settings = {
201 201 type : "POST",
202 202 success: options.success || function() {},
203 203 error : this.create_basic_error_handler(options.error)
204 204 };
205 205 $.ajax(url, settings);
206 206 };
207 207
208 208 Contents.prototype.list_checkpoints = function(path, options) {
209 209 var url = this.api_url(path, 'checkpoints');
210 210 var settings = {
211 211 type : "GET",
212 212 success: options.success,
213 213 error : this.create_basic_error_handler(options.error)
214 214 };
215 215 $.ajax(url, settings);
216 216 };
217 217
218 218 Contents.prototype.restore_checkpoint = function(path, checkpoint_id, options) {
219 219 var url = this.api_url(path, 'checkpoints', checkpoint_id);
220 220 var settings = {
221 221 type : "POST",
222 222 success: options.success || function() {},
223 223 error : this.create_basic_error_handler(options.error)
224 224 };
225 225 $.ajax(url, settings);
226 226 };
227 227
228 228 Contents.prototype.delete_checkpoint = function(path, checkpoint_id, options) {
229 229 var url = this.api_url(path, 'checkpoints', checkpoint_id);
230 230 var settings = {
231 231 type : "DELETE",
232 232 success: options.success || function() {},
233 233 error : this.create_basic_error_handler(options.error)
234 234 };
235 235 $.ajax(url, settings);
236 236 };
237 237
238 238 /**
239 239 * File management functions
240 240 */
241 241
242 242 /**
243 243 * List notebooks and directories at a given path
244 244 *
245 245 * On success, load_callback is called with an array of dictionaries
246 246 * representing individual files or directories. Each dictionary has
247 247 * the keys:
248 248 * type: "notebook" or "directory"
249 249 * created: created date
250 250 * last_modified: last modified dat
251 251 * @method list_notebooks
252 252 * @param {String} path The path to list notebooks in
253 253 * @param {Function} load_callback called with list of notebooks on success
254 254 * @param {Function} error called with ajax results on error
255 255 */
256 256 Contents.prototype.list_contents = function(path, options) {
257 257 var settings = {
258 258 processData : false,
259 259 cache : false,
260 260 type : "GET",
261 261 dataType : "json",
262 262 success : options.success,
263 263 error : this.create_basic_error_handler(options.error)
264 264 };
265 265
266 266 $.ajax(this.api_url(path), settings);
267 267 };
268 268
269 269
270 270 IPython.Contents = Contents;
271 271
272 272 return {'Contents': Contents};
273 273 });
@@ -1,148 +1,148 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 require([
5 5 'jquery',
6 6 'base/js/namespace',
7 7 'base/js/dialog',
8 8 'base/js/events',
9 9 'base/js/page',
10 10 'base/js/utils',
11 11 'contents',
12 12 'tree/js/notebooklist',
13 13 'tree/js/clusterlist',
14 14 'tree/js/sessionlist',
15 15 'tree/js/kernellist',
16 16 'tree/js/terminallist',
17 17 'auth/js/loginwidget',
18 18 // only loaded, not used:
19 19 'jqueryui',
20 20 'bootstrap',
21 21 'custom/custom',
22 22 ], function(
23 23 $,
24 24 IPython,
25 25 dialog,
26 26 events,
27 27 page,
28 28 utils,
29 29 contents_service,
30 30 notebooklist,
31 31 clusterlist,
32 32 sesssionlist,
33 33 kernellist,
34 34 terminallist,
35 35 loginwidget){
36 36 "use strict";
37 37
38 38 page = new page.Page();
39 39
40 40 var common_options = {
41 41 base_url: utils.get_body_data("baseUrl"),
42 42 notebook_path: utils.get_body_data("notebookPath"),
43 43 };
44 44 var session_list = new sesssionlist.SesssionList($.extend({
45 45 events: events},
46 46 common_options));
47 47 var contents = new contents_service.Contents($.extend({
48 48 events: events},
49 49 common_options));
50 50 var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
51 51 contents: contents,
52 52 session_list: session_list},
53 53 common_options));
54 54 var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
55 55 var kernel_list = new kernellist.KernelList('#running_list', $.extend({
56 56 session_list: session_list},
57 57 common_options));
58 58
59 59 var terminal_list;
60 60 if (utils.get_body_data("terminalsAvailable") === "True") {
61 61 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
62 62 }
63 63
64 64 var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
65 65
66 66 $('#new_notebook').click(function (e) {
67 contents.new(common_options.notebook_path, {
67 contents.new_untitled(common_options.notebook_path, {
68 68 type: "notebook",
69 69 extra_settings: {async: false}, // So we can open a new window afterwards
70 70 success: function (data) {
71 71 window.open(
72 72 utils.url_join_encode(
73 73 common_options.base_url, 'notebooks',
74 74 data.path
75 75 ), '_blank');
76 76 },
77 77 error: function(error) {
78 78 dialog.modal({
79 79 title : 'Creating Notebook Failed',
80 80 body : "The error was: " + error.message,
81 81 buttons : {'OK' : {'class' : 'btn-primary'}}
82 82 });
83 83 }
84 84 });
85 85 });
86 86
87 87 var interval_id=0;
88 88 // auto refresh every xx secondes, no need to be fast,
89 89 // update is done at least when page get focus
90 90 var time_refresh = 60; // in sec
91 91
92 92 var enable_autorefresh = function(){
93 93 //refresh immediately , then start interval
94 94 session_list.load_sessions();
95 95 cluster_list.load_list();
96 96 if (!interval_id){
97 97 interval_id = setInterval(function(){
98 98 session_list.load_sessions();
99 99 cluster_list.load_list();
100 100 }, time_refresh*1000);
101 101 }
102 102 };
103 103
104 104 var disable_autorefresh = function(){
105 105 clearInterval(interval_id);
106 106 interval_id = 0;
107 107 };
108 108
109 109 // stop autorefresh when page lose focus
110 110 $(window).blur(function() {
111 111 disable_autorefresh();
112 112 });
113 113
114 114 //re-enable when page get focus back
115 115 $(window).focus(function() {
116 116 enable_autorefresh();
117 117 });
118 118
119 119 // finally start it, it will refresh immediately
120 120 enable_autorefresh();
121 121
122 122 page.show();
123 123
124 124 // For backwards compatability.
125 125 IPython.page = page;
126 126 IPython.notebook_list = notebook_list;
127 127 IPython.cluster_list = cluster_list;
128 128 IPython.session_list = session_list;
129 129 IPython.kernel_list = kernel_list;
130 130 IPython.login_widget = login_widget;
131 131
132 132 events.trigger('app_initialized.DashboardApp');
133 133
134 134 // bound the upload method to the on change of the file select list
135 135 $("#alternate_upload").change(function (event){
136 136 notebook_list.handleFilesUpload(event,'form');
137 137 });
138 138
139 139 // set hash on tab click
140 140 $("#tabs").find("a").click(function() {
141 141 window.location.hash = $(this).attr("href");
142 142 });
143 143
144 144 // load tab if url hash
145 145 if (window.location.hash) {
146 146 $("#tabs").find("a[href=" + window.location.hash + "]").click();
147 147 }
148 148 });
General Comments 0
You need to be logged in to leave comments. Login now