##// END OF EJS Templates
update frontend with path/name changes...
Min RK -
Show More
@@ -272,11 +272,11 b' define(['
272 } else {
272 } else {
273 line = "background-color: ";
273 line = "background-color: ";
274 }
274 }
275 line = line + "rgb(" + r + "," + g + "," + b + ");"
275 line = line + "rgb(" + r + "," + g + "," + b + ");";
276 if ( !attrs["style"] ) {
276 if ( !attrs.style ) {
277 attrs["style"] = line;
277 attrs.style = line;
278 } else {
278 } else {
279 attrs["style"] += " " + line;
279 attrs.style += " " + line;
280 }
280 }
281 }
281 }
282 }
282 }
@@ -285,7 +285,7 b' define(['
285 function ansispan(str) {
285 function ansispan(str) {
286 // ansispan function adapted from github.com/mmalecki/ansispan (MIT License)
286 // ansispan function adapted from github.com/mmalecki/ansispan (MIT License)
287 // regular ansi escapes (using the table above)
287 // regular ansi escapes (using the table above)
288 var is_open = false
288 var is_open = false;
289 return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) {
289 return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) {
290 if (!pattern) {
290 if (!pattern) {
291 // [(01|22|39|)m close spans
291 // [(01|22|39|)m close spans
@@ -313,7 +313,7 b' define(['
313 return span + ">";
313 return span + ">";
314 }
314 }
315 });
315 });
316 };
316 }
317
317
318 // Transform ANSI color escape codes into HTML <span> tags with css
318 // Transform ANSI color escape codes into HTML <span> tags with css
319 // classes listed in the above ansi_colormap object. The actual color used
319 // classes listed in the above ansi_colormap object. The actual color used
@@ -392,6 +392,18 b' define(['
392 return url;
392 return url;
393 };
393 };
394
394
395 var url_path_split = function (path) {
396 // Like os.path.split for URLs.
397 // Always returns two strings, the directory path and the base filename
398
399 var idx = path.lastIndexOf('/');
400 if (idx === -1) {
401 return ['', path];
402 } else {
403 return [ path.slice(0, idx), path.slice(idx + 1) ];
404 }
405 };
406
395 var parse_url = function (url) {
407 var parse_url = function (url) {
396 // an `a` element with an href allows attr-access to the parsed segments of a URL
408 // an `a` element with an href allows attr-access to the parsed segments of a URL
397 // a = parse_url("http://localhost:8888/path/name#hash")
409 // a = parse_url("http://localhost:8888/path/name#hash")
@@ -577,7 +589,7 b' define(['
577 wrapped_error.xhr_status = status;
589 wrapped_error.xhr_status = status;
578 wrapped_error.xhr_error = error;
590 wrapped_error.xhr_error = error;
579 return wrapped_error;
591 return wrapped_error;
580 }
592 };
581
593
582 var utils = {
594 var utils = {
583 regex_split : regex_split,
595 regex_split : regex_split,
@@ -588,6 +600,7 b' define(['
588 points_to_pixels : points_to_pixels,
600 points_to_pixels : points_to_pixels,
589 get_body_data : get_body_data,
601 get_body_data : get_body_data,
590 parse_url : parse_url,
602 parse_url : parse_url,
603 url_path_split : url_path_split,
591 url_path_join : url_path_join,
604 url_path_join : url_path_join,
592 url_join_encode : url_join_encode,
605 url_join_encode : url_join_encode,
593 encode_uri_components : encode_uri_components,
606 encode_uri_components : encode_uri_components,
@@ -151,6 +151,6 b' require(['
151 IPython.tooltip = notebook.tooltip;
151 IPython.tooltip = notebook.tooltip;
152
152
153 events.trigger('app_initialized.NotebookApp');
153 events.trigger('app_initialized.NotebookApp');
154 notebook.load_notebook(common_options.notebook_name, common_options.notebook_path);
154 notebook.load_notebook(common_options.notebook_path);
155
155
156 });
156 });
@@ -2,13 +2,14 b''
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 define([
4 define([
5 'base/js/namespace',
6 'jquery',
5 'jquery',
6 'base/js/namespace',
7 'base/js/dialog',
7 'base/js/utils',
8 'base/js/utils',
8 'notebook/js/tour',
9 'notebook/js/tour',
9 'bootstrap',
10 'bootstrap',
10 'moment',
11 'moment',
11 ], function(IPython, $, utils, tour, bootstrap, moment) {
12 ], function($, IPython, dialog, utils, tour, bootstrap, moment) {
12 "use strict";
13 "use strict";
13
14
14 var MenuBar = function (selector, options) {
15 var MenuBar = function (selector, options) {
@@ -89,14 +90,14 b' define(['
89 this.element.find('#new_notebook').click(function () {
90 this.element.find('#new_notebook').click(function () {
90 // Create a new notebook in the same path as the current
91 // Create a new notebook in the same path as the current
91 // notebook's path.
92 // notebook's path.
92 that.contents.new(that.notebook.notebook_path, null, {
93 var parent = utils.url_path_split(this.notebook_path)[0];
94 that.contents.new(parent, {
93 ext: ".ipynb",
95 ext: ".ipynb",
94 extra_settings: {async: false}, // So we can open a new window afterwards
96 extra_settings: {async: false}, // So we can open a new window afterwards
95 success: function (data) {
97 success: function (data) {
96 window.open(
98 window.open(
97 utils.url_join_encode(
99 utils.url_join_encode(
98 that.base_url, 'notebooks',
100 that.base_url, 'notebooks', data.path
99 data.path, data.name
100 ), '_blank');
101 ), '_blank');
101 },
102 },
102 error: function(error) {
103 error: function(error) {
@@ -212,13 +212,13 b' define(['
212 });
212 });
213
213
214 this.events.on('kernel_ready.Kernel', function(event, data) {
214 this.events.on('kernel_ready.Kernel', function(event, data) {
215 var kinfo = data.kernel.info_reply
215 var kinfo = data.kernel.info_reply;
216 var langinfo = kinfo.language_info || {};
216 var langinfo = kinfo.language_info || {};
217 if (!langinfo.name) langinfo.name = kinfo.language;
217 if (!langinfo.name) langinfo.name = kinfo.language;
218
218
219 that.metadata.language_info = langinfo;
219 that.metadata.language_info = langinfo;
220 // Mode 'null' should be plain, unhighlighted text.
220 // Mode 'null' should be plain, unhighlighted text.
221 var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null'
221 var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null';
222 that.set_codemirror_mode(cm_mode);
222 that.set_codemirror_mode(cm_mode);
223 });
223 });
224
224
@@ -1029,7 +1029,7 b' define(['
1029 text = '';
1029 text = '';
1030 }
1030 }
1031 // metadata
1031 // metadata
1032 target_cell.metadata = source_cell.metadata
1032 target_cell.metadata = source_cell.metadata;
1033 // We must show the editor before setting its contents
1033 // We must show the editor before setting its contents
1034 target_cell.unrender();
1034 target_cell.unrender();
1035 target_cell.set_text(text);
1035 target_cell.set_text(text);
@@ -1231,8 +1231,6 b' define(['
1231 * @method split_cell
1231 * @method split_cell
1232 */
1232 */
1233 Notebook.prototype.split_cell = function () {
1233 Notebook.prototype.split_cell = function () {
1234 var mdc = textcell.MarkdownCell;
1235 var rc = textcell.RawCell;
1236 var cell = this.get_selected_cell();
1234 var cell = this.get_selected_cell();
1237 if (cell.is_splittable()) {
1235 if (cell.is_splittable()) {
1238 var texta = cell.get_pre_cursor();
1236 var texta = cell.get_pre_cursor();
@@ -1251,8 +1249,6 b' define(['
1251 * @method merge_cell_above
1249 * @method merge_cell_above
1252 */
1250 */
1253 Notebook.prototype.merge_cell_above = function () {
1251 Notebook.prototype.merge_cell_above = function () {
1254 var mdc = textcell.MarkdownCell;
1255 var rc = textcell.RawCell;
1256 var index = this.get_selected_index();
1252 var index = this.get_selected_index();
1257 var cell = this.get_cell(index);
1253 var cell = this.get_cell(index);
1258 var render = cell.rendered;
1254 var render = cell.rendered;
@@ -1288,8 +1284,6 b' define(['
1288 * @method merge_cell_below
1284 * @method merge_cell_below
1289 */
1285 */
1290 Notebook.prototype.merge_cell_below = function () {
1286 Notebook.prototype.merge_cell_below = function () {
1291 var mdc = textcell.MarkdownCell;
1292 var rc = textcell.RawCell;
1293 var index = this.get_selected_index();
1287 var index = this.get_selected_index();
1294 var cell = this.get_cell(index);
1288 var cell = this.get_cell(index);
1295 var render = cell.rendered;
1289 var render = cell.rendered;
@@ -1523,9 +1517,9 b' define(['
1523 }
1517 }
1524 this.codemirror_mode = newmode;
1518 this.codemirror_mode = newmode;
1525 codecell.CodeCell.options_default.cm_config.mode = newmode;
1519 codecell.CodeCell.options_default.cm_config.mode = newmode;
1526 modename = newmode.mode || newmode.name || newmode;
1520 var modename = newmode.mode || newmode.name || newmode;
1527
1521
1528 that = this;
1522 var that = this;
1529 utils.requireCodeMirrorMode(modename, function () {
1523 utils.requireCodeMirrorMode(modename, function () {
1530 $.map(that.get_cells(), function(cell, i) {
1524 $.map(that.get_cells(), function(cell, i) {
1531 if (cell.cell_type === 'code'){
1525 if (cell.cell_type === 'code'){
@@ -1547,7 +1541,6 b' define(['
1547 * @method start_session
1541 * @method start_session
1548 */
1542 */
1549 Notebook.prototype.start_session = function (kernel_name) {
1543 Notebook.prototype.start_session = function (kernel_name) {
1550 var that = this;
1551 if (this._session_starting) {
1544 if (this._session_starting) {
1552 throw new session.SessionAlreadyStarting();
1545 throw new session.SessionAlreadyStarting();
1553 }
1546 }
@@ -1629,7 +1622,6 b' define(['
1629 Notebook.prototype.execute_cell = function () {
1622 Notebook.prototype.execute_cell = function () {
1630 // mode = shift, ctrl, alt
1623 // mode = shift, ctrl, alt
1631 var cell = this.get_selected_cell();
1624 var cell = this.get_selected_cell();
1632 var cell_index = this.find_cell_index(cell);
1633
1625
1634 cell.execute();
1626 cell.execute();
1635 this.command_mode();
1627 this.command_mode();
@@ -1758,7 +1750,9 b' define(['
1758 * @param {String} name A new name for this notebook
1750 * @param {String} name A new name for this notebook
1759 */
1751 */
1760 Notebook.prototype.set_notebook_name = function (name) {
1752 Notebook.prototype.set_notebook_name = function (name) {
1753 var parent = utils.url_path_split(this.notebook_path)[0];
1761 this.notebook_name = name;
1754 this.notebook_name = name;
1755 this.notebook_path = utils.url_path_join(parent, name);
1762 };
1756 };
1763
1757
1764 /**
1758 /**
@@ -1795,6 +1789,7 b' define(['
1795 // Save the metadata and name.
1789 // Save the metadata and name.
1796 this.metadata = content.metadata;
1790 this.metadata = content.metadata;
1797 this.notebook_name = data.name;
1791 this.notebook_name = data.name;
1792 this.notebook_path = data.path;
1798 var trusted = true;
1793 var trusted = true;
1799
1794
1800 // Trigger an event changing the kernel spec - this will set the default
1795 // Trigger an event changing the kernel spec - this will set the default
@@ -1807,7 +1802,7 b' define(['
1807 if (this.metadata.language_info !== undefined) {
1802 if (this.metadata.language_info !== undefined) {
1808 var langinfo = this.metadata.language_info;
1803 var langinfo = this.metadata.language_info;
1809 // Mode 'null' should be plain, unhighlighted text.
1804 // Mode 'null' should be plain, unhighlighted text.
1810 var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null'
1805 var cm_mode = langinfo.codemirror_mode || langinfo.language || 'null';
1811 this.set_codemirror_mode(cm_mode);
1806 this.set_codemirror_mode(cm_mode);
1812 }
1807 }
1813
1808
@@ -1900,8 +1895,6 b' define(['
1900 Notebook.prototype.save_notebook = function (extra_settings) {
1895 Notebook.prototype.save_notebook = function (extra_settings) {
1901 // Create a JSON model to be sent to the server.
1896 // Create a JSON model to be sent to the server.
1902 var model = {
1897 var model = {
1903 name : this.notebook_name,
1904 path : this.notebook_path,
1905 type : "notebook",
1898 type : "notebook",
1906 content : this.toJSON()
1899 content : this.toJSON()
1907 };
1900 };
@@ -1909,11 +1902,11 b' define(['
1909 var start = new Date().getTime();
1902 var start = new Date().getTime();
1910
1903
1911 var that = this;
1904 var that = this;
1912 this.contents.save(this.notebook_path, this.notebook_name, model, {
1905 this.contents.save(this.notebook_path, model, {
1913 extra_settings: extra_settings,
1906 extra_settings: extra_settings,
1914 success: $.proxy(this.save_notebook_success, this, start),
1907 success: $.proxy(this.save_notebook_success, this, start),
1915 error: function (error) {
1908 error: function (error) {
1916 that.events.trigger('notebook_save_failed.Notebook');
1909 that.events.trigger('notebook_save_failed.Notebook', error);
1917 }
1910 }
1918 });
1911 });
1919 };
1912 };
@@ -2031,15 +2024,15 b' define(['
2031
2024
2032 Notebook.prototype.copy_notebook = function(){
2025 Notebook.prototype.copy_notebook = function(){
2033 var base_url = this.base_url;
2026 var base_url = this.base_url;
2034 this.contents.copy(this.notebook_path, null, this.notebook_name, {
2027 var parent = utils.url_path_split(this.notebook_path)[0];
2028 this.contents.copy(this.notebook_path, parent, {
2035 // synchronous so we can open a new window on success
2029 // synchronous so we can open a new window on success
2036 extra_settings: {async: false},
2030 extra_settings: {async: false},
2037 success: function (data) {
2031 success: function (data) {
2038 window.open(utils.url_join_encode(
2032 window.open(utils.url_join_encode(
2039 base_url, 'notebooks', data.path, data.name
2033 base_url, 'notebooks', data.path
2040 ), '_blank');
2034 ), '_blank');
2041 },
2035 }
2042 error : utils.log_ajax_error
2043 });
2036 });
2044 };
2037 };
2045
2038
@@ -2049,11 +2042,13 b' define(['
2049 }
2042 }
2050
2043
2051 var that = this;
2044 var that = this;
2052 this.contents.rename(this.notebook_path, this.notebook_name,
2045 var parent = utils.url_path_split(this.notebook_path)[0];
2053 this.notebook_path, new_name, {
2046 var new_path = utils.url_path_join(parent, new_name);
2047 this.contents.rename(this.notebook_path, new_path, {
2054 success: function (json) {
2048 success: function (json) {
2055 var name = that.notebook_name = json.name;
2049 that.notebook_name = json.name;
2056 that.session.rename_notebook(name, json.path);
2050 that.notebook_path = json.path;
2051 that.session.rename_notebook(json.path);
2057 that.events.trigger('notebook_renamed.Notebook', json);
2052 that.events.trigger('notebook_renamed.Notebook', json);
2058 },
2053 },
2059 error: $.proxy(this.rename_error, this)
2054 error: $.proxy(this.rename_error, this)
@@ -2061,7 +2056,7 b' define(['
2061 };
2056 };
2062
2057
2063 Notebook.prototype.delete = function () {
2058 Notebook.prototype.delete = function () {
2064 this.contents.delete(this.notebook_name, this.notebook_path);
2059 this.contents.delete(this.notebook_path);
2065 };
2060 };
2066
2061
2067 Notebook.prototype.rename_error = function (error) {
2062 Notebook.prototype.rename_error = function (error) {
@@ -2100,13 +2095,13 b' define(['
2100 * Request a notebook's data from the server.
2095 * Request a notebook's data from the server.
2101 *
2096 *
2102 * @method load_notebook
2097 * @method load_notebook
2103 * @param {String} notebook_name and path A notebook to load
2098 * @param {String} notebook_path A notebook to load
2104 */
2099 */
2105 Notebook.prototype.load_notebook = function (notebook_name, notebook_path) {
2100 Notebook.prototype.load_notebook = function (notebook_path) {
2106 this.notebook_name = notebook_name;
2107 this.notebook_path = notebook_path;
2101 this.notebook_path = notebook_path;
2102 this.notebook_name = utils.url_path_split(this.notebook_path)[1];
2108 this.events.trigger('notebook_loading.Notebook');
2103 this.events.trigger('notebook_loading.Notebook');
2109 this.contents.load(notebook_path, notebook_name, {
2104 this.contents.get(notebook_path, {
2110 success: $.proxy(this.load_notebook_success, this),
2105 success: $.proxy(this.load_notebook_success, this),
2111 error: $.proxy(this.load_notebook_error, this)
2106 error: $.proxy(this.load_notebook_error, this)
2112 });
2107 });
@@ -2121,7 +2116,7 b' define(['
2121 * @param {Object} data JSON representation of a notebook
2116 * @param {Object} data JSON representation of a notebook
2122 */
2117 */
2123 Notebook.prototype.load_notebook_success = function (data) {
2118 Notebook.prototype.load_notebook_success = function (data) {
2124 var failed;
2119 var failed, msg;
2125 try {
2120 try {
2126 this.fromJSON(data);
2121 this.fromJSON(data);
2127 } catch (e) {
2122 } catch (e) {
@@ -2146,12 +2141,11 b' define(['
2146 }
2141 }
2147
2142
2148 if (data.message) {
2143 if (data.message) {
2149 var msg;
2150 if (failed) {
2144 if (failed) {
2151 msg = "The notebook also failed validation:"
2145 msg = "The notebook also failed validation:";
2152 } else {
2146 } else {
2153 msg = "An invalid notebook may not function properly." +
2147 msg = "An invalid notebook may not function properly." +
2154 " The validation error was:"
2148 " The validation error was:";
2155 }
2149 }
2156 body.append($("<p>").text(
2150 body.append($("<p>").text(
2157 msg
2151 msg
@@ -2192,7 +2186,7 b' define(['
2192 src = " a newer notebook format ";
2186 src = " a newer notebook format ";
2193 }
2187 }
2194
2188
2195 var msg = "This notebook has been converted from" + src +
2189 msg = "This notebook has been converted from" + src +
2196 "(v"+orig_nbformat+") to the current notebook " +
2190 "(v"+orig_nbformat+") to the current notebook " +
2197 "format (v"+nbmodel.nbformat+"). The next time you save this notebook, the " +
2191 "format (v"+nbmodel.nbformat+"). The next time you save this notebook, the " +
2198 "current notebook format will be used.";
2192 "current notebook format will be used.";
@@ -2219,7 +2213,7 b' define(['
2219 var that = this;
2213 var that = this;
2220 var orig_vs = 'v' + nbmodel.nbformat + '.' + orig_nbformat_minor;
2214 var orig_vs = 'v' + nbmodel.nbformat + '.' + orig_nbformat_minor;
2221 var this_vs = 'v' + nbmodel.nbformat + '.' + this.nbformat_minor;
2215 var this_vs = 'v' + nbmodel.nbformat + '.' + this.nbformat_minor;
2222 var msg = "This notebook is version " + orig_vs + ", but we only fully support up to " +
2216 msg = "This notebook is version " + orig_vs + ", but we only fully support up to " +
2223 this_vs + ". You can still work with this notebook, but some features " +
2217 this_vs + ". You can still work with this notebook, but some features " +
2224 "introduced in later notebook versions may not be available.";
2218 "introduced in later notebook versions may not be available.";
2225
2219
@@ -2270,7 +2264,7 b' define(['
2270 Notebook.prototype.load_notebook_error = function (error) {
2264 Notebook.prototype.load_notebook_error = function (error) {
2271 this.events.trigger('notebook_load_failed.Notebook', error);
2265 this.events.trigger('notebook_load_failed.Notebook', error);
2272 var msg;
2266 var msg;
2273 if (error.name = utils.XHR_ERROR && error.xhr.status === 500) {
2267 if (error.name === utils.XHR_ERROR && error.xhr.status === 500) {
2274 utils.log_ajax_error(error.xhr, error.xhr_status, error.xhr_error);
2268 utils.log_ajax_error(error.xhr, error.xhr_status, error.xhr_error);
2275 msg = "An unknown error occurred while loading this notebook. " +
2269 msg = "An unknown error occurred while loading this notebook. " +
2276 "This version can load notebook formats " +
2270 "This version can load notebook formats " +
@@ -2330,10 +2324,10 b' define(['
2330 */
2324 */
2331 Notebook.prototype.list_checkpoints = function () {
2325 Notebook.prototype.list_checkpoints = function () {
2332 var that = this;
2326 var that = this;
2333 this.contents.list_checkpoints(this.notebook_path, this.notebook_name, {
2327 this.contents.list_checkpoints(this.notebook_path, {
2334 success: $.proxy(this.list_checkpoints_success, this),
2328 success: $.proxy(this.list_checkpoints_success, this),
2335 error: function(error) {
2329 error: function(error) {
2336 that.events.trigger('list_checkpoints_failed.Notebook');
2330 that.events.trigger('list_checkpoints_failed.Notebook', error);
2337 }
2331 }
2338 });
2332 });
2339 };
2333 };
@@ -2362,10 +2356,10 b' define(['
2362 */
2356 */
2363 Notebook.prototype.create_checkpoint = function () {
2357 Notebook.prototype.create_checkpoint = function () {
2364 var that = this;
2358 var that = this;
2365 this.contents.create_checkpoint(this.notebook_path, this.notebook_name, {
2359 this.contents.create_checkpoint(this.notebook_path, {
2366 success: $.proxy(this.create_checkpoint_success, this),
2360 success: $.proxy(this.create_checkpoint_success, this),
2367 error: function (error) {
2361 error: function (error) {
2368 that.events.trigger('checkpoint_failed.Notebook');
2362 that.events.trigger('checkpoint_failed.Notebook', error);
2369 }
2363 }
2370 });
2364 });
2371 };
2365 };
@@ -2432,11 +2426,11 b' define(['
2432 Notebook.prototype.restore_checkpoint = function (checkpoint) {
2426 Notebook.prototype.restore_checkpoint = function (checkpoint) {
2433 this.events.trigger('notebook_restoring.Notebook', checkpoint);
2427 this.events.trigger('notebook_restoring.Notebook', checkpoint);
2434 var that = this;
2428 var that = this;
2435 this.contents.restore_checkpoint(this.notebook_path, this.notebook_name,
2429 this.contents.restore_checkpoint(this.notebook_path,
2436 checkpoint, {
2430 checkpoint, {
2437 success: $.proxy(this.restore_checkpoint_success, this),
2431 success: $.proxy(this.restore_checkpoint_success, this),
2438 error: function (error) {
2432 error: function (error) {
2439 that.events.trigger('checkpoint_restore_failed.Notebook');
2433 that.events.trigger('checkpoint_restore_failed.Notebook', error);
2440 }
2434 }
2441 });
2435 });
2442 };
2436 };
@@ -2448,7 +2442,7 b' define(['
2448 */
2442 */
2449 Notebook.prototype.restore_checkpoint_success = function () {
2443 Notebook.prototype.restore_checkpoint_success = function () {
2450 this.events.trigger('checkpoint_restored.Notebook');
2444 this.events.trigger('checkpoint_restored.Notebook');
2451 this.load_notebook(this.notebook_name, this.notebook_path);
2445 this.load_notebook(this.notebook_path);
2452 };
2446 };
2453
2447
2454 /**
2448 /**
@@ -2460,7 +2454,7 b' define(['
2460 Notebook.prototype.delete_checkpoint = function (checkpoint) {
2454 Notebook.prototype.delete_checkpoint = function (checkpoint) {
2461 this.events.trigger('notebook_restoring.Notebook', checkpoint);
2455 this.events.trigger('notebook_restoring.Notebook', checkpoint);
2462 var that = this;
2456 var that = this;
2463 this.contents.delete_checkpoint(this.notebook_path, this.notebook_name,
2457 this.contents.delete_checkpoint(this.notebook_path,
2464 checkpoint, {
2458 checkpoint, {
2465 success: $.proxy(this.delete_checkpoint_success, this),
2459 success: $.proxy(this.delete_checkpoint_success, this),
2466 error: function (error) {
2460 error: function (error) {
@@ -2476,7 +2470,7 b' define(['
2476 */
2470 */
2477 Notebook.prototype.delete_checkpoint_success = function () {
2471 Notebook.prototype.delete_checkpoint_success = function () {
2478 this.events.trigger('checkpoint_deleted.Notebook');
2472 this.events.trigger('checkpoint_deleted.Notebook');
2479 this.load_notebook(this.notebook_name, this.notebook_path);
2473 this.load_notebook(this.notebook_path);
2480 };
2474 };
2481
2475
2482
2476
@@ -122,14 +122,12 b' define(['
122
122
123 SaveWidget.prototype.update_address_bar = function(){
123 SaveWidget.prototype.update_address_bar = function(){
124 var base_url = this.notebook.base_url;
124 var base_url = this.notebook.base_url;
125 var nbname = this.notebook.notebook_name;
126 var path = this.notebook.notebook_path;
125 var path = this.notebook.notebook_path;
127 var state = {path : path, name: nbname};
126 var state = {path : path};
128 window.history.replaceState(state, "", utils.url_join_encode(
127 window.history.replaceState(state, "", utils.url_join_encode(
129 base_url,
128 base_url,
130 "notebooks",
129 "notebooks",
131 path,
130 path)
132 nbname)
133 );
131 );
134 };
132 };
135
133
@@ -199,7 +197,7 b' define(['
199 $.proxy(that._regularly_update_checkpoint_date, that),
197 $.proxy(that._regularly_update_checkpoint_date, that),
200 t + 1000
198 t + 1000
201 );
199 );
202 }
200 };
203 var tdelta = Math.ceil(new Date()-this._checkpoint_date);
201 var tdelta = Math.ceil(new Date()-this._checkpoint_date);
204
202
205 // update regularly for the first 6hours and show
203 // update regularly for the first 6hours and show
@@ -29,8 +29,9 b' define(['
29 // An error representing the result of attempting to delete a non-empty
29 // An error representing the result of attempting to delete a non-empty
30 // directory.
30 // directory.
31 this.message = 'A directory must be empty before being deleted.';
31 this.message = 'A directory must be empty before being deleted.';
32 }
32 };
33 Contents.DirectoryNotEmptyError.prototype = new Error;
33
34 Contents.DirectoryNotEmptyError.prototype = Object.create(Error.prototype);
34 Contents.DirectoryNotEmptyError.prototype.name =
35 Contents.DirectoryNotEmptyError.prototype.name =
35 Contents.DIRECTORY_NOT_EMPTY_ERROR;
36 Contents.DIRECTORY_NOT_EMPTY_ERROR;
36
37
@@ -54,29 +55,28 b' define(['
54 */
55 */
55 Contents.prototype.create_basic_error_handler = function(callback) {
56 Contents.prototype.create_basic_error_handler = function(callback) {
56 if (!callback) {
57 if (!callback) {
57 return function(xhr, status, error) { };
58 return utils.log_ajax_error;
58 }
59 }
59 return function(xhr, status, error) {
60 return function(xhr, status, error) {
60 callback(utils.wrap_ajax_error(xhr, status, error));
61 callback(utils.wrap_ajax_error(xhr, status, error));
61 };
62 };
62 }
63 };
63
64
64 /**
65 /**
65 * File Functions (including notebook operations)
66 * File Functions (including notebook operations)
66 */
67 */
67
68
68 /**
69 /**
69 * Load a file.
70 * Get a file.
70 *
71 *
71 * Calls success with file JSON model, or error with error.
72 * Calls success with file JSON model, or error with error.
72 *
73 *
73 * @method load_notebook
74 * @method get
74 * @param {String} path
75 * @param {String} path
75 * @param {String} name
76 * @param {Function} success
76 * @param {Function} success
77 * @param {Function} error
77 * @param {Function} error
78 */
78 */
79 Contents.prototype.load = function (path, name, options) {
79 Contents.prototype.get = function (path, options) {
80 // We do the call with settings so we can set cache to false.
80 // We do the call with settings so we can set cache to false.
81 var settings = {
81 var settings = {
82 processData : false,
82 processData : false,
@@ -86,32 +86,25 b' define(['
86 success : options.success,
86 success : options.success,
87 error : this.create_basic_error_handler(options.error)
87 error : this.create_basic_error_handler(options.error)
88 };
88 };
89 var url = this.api_url(path, name);
89 var url = this.api_url(path);
90 $.ajax(url, settings);
90 $.ajax(url, settings);
91 };
91 };
92
92
93
93
94 /**
94 /**
95 * Creates a new notebook file at the specified directory path.
95 * Creates a new file at the specified directory path.
96 *
96 *
97 * @method scroll_to_cell
97 * @method new
98 * @param {String} path The path to create the new notebook at
98 * @param {String} path The path to create the new notebook at
99 * @param {String} name Name for new file. Chosen by server if unspecified.
100 * @param {Object} options:
99 * @param {Object} options:
101 * ext: file extension to use if name unspecified
100 * ext: file extension to use
102 */
101 */
103 Contents.prototype.new = function(path, name, options) {
102 Contents.prototype.new = function(path, options) {
104 var method, data;
103 var data = JSON.stringify({ext: options.ext || ".ipynb"});
105 if (name) {
106 method = "PUT";
107 } else {
108 method = "POST";
109 data = JSON.stringify({ext: options.ext || ".ipynb"});
110 }
111
104
112 var settings = {
105 var settings = {
113 processData : false,
106 processData : false,
114 type : method,
107 type : "POST",
115 data: data,
108 data: data,
116 dataType : "json",
109 dataType : "json",
117 success : options.success || function() {},
110 success : options.success || function() {},
@@ -123,9 +116,8 b' define(['
123 $.ajax(this.api_url(path), settings);
116 $.ajax(this.api_url(path), settings);
124 };
117 };
125
118
126 Contents.prototype.delete = function(name, path, options) {
119 Contents.prototype.delete = function(path, options) {
127 var error_callback = options.error || function() {};
120 var error_callback = options.error || function() {};
128 var that = this;
129 var settings = {
121 var settings = {
130 processData : false,
122 processData : false,
131 type : "DELETE",
123 type : "DELETE",
@@ -140,12 +132,12 b' define(['
140 error_callback(utils.wrap_ajax_error(xhr, status, error));
132 error_callback(utils.wrap_ajax_error(xhr, status, error));
141 }
133 }
142 };
134 };
143 var url = this.api_url(path, name);
135 var url = this.api_url(path);
144 $.ajax(url, settings);
136 $.ajax(url, settings);
145 };
137 };
146
138
147 Contents.prototype.rename = function(path, name, new_path, new_name, options) {
139 Contents.prototype.rename = function(path, new_path, options) {
148 var data = {name: new_name, path: new_path};
140 var data = {path: new_path};
149 var settings = {
141 var settings = {
150 processData : false,
142 processData : false,
151 type : "PATCH",
143 type : "PATCH",
@@ -155,11 +147,11 b' define(['
155 success : options.success || function() {},
147 success : options.success || function() {},
156 error : this.create_basic_error_handler(options.error)
148 error : this.create_basic_error_handler(options.error)
157 };
149 };
158 var url = this.api_url(path, name);
150 var url = this.api_url(path);
159 $.ajax(url, settings);
151 $.ajax(url, settings);
160 };
152 };
161
153
162 Contents.prototype.save = function(path, name, model, options) {
154 Contents.prototype.save = function(path, model, options) {
163 // We do the call with settings so we can set cache to false.
155 // We do the call with settings so we can set cache to false.
164 var settings = {
156 var settings = {
165 processData : false,
157 processData : false,
@@ -172,24 +164,19 b' define(['
172 if (options.extra_settings) {
164 if (options.extra_settings) {
173 $.extend(settings, options.extra_settings);
165 $.extend(settings, options.extra_settings);
174 }
166 }
175 var url = this.api_url(path, name);
167 var url = this.api_url(path);
176 $.ajax(url, settings);
168 $.ajax(url, settings);
177 };
169 };
178
170
179 Contents.prototype.copy = function(to_path, to_name, from, options) {
171 Contents.prototype.copy = function(from_file, to_dir, options) {
180 var url, method;
172 // Copy a file into a given directory via POST
181 if (to_name) {
173 // The server will select the name of the copied file
182 url = this.api_url(to_path, to_name);
174 var url = this.api_url(to_dir);
183 method = "PUT";
184 } else {
185 url = this.api_url(to_path);
186 method = "POST";
187 }
188
175
189 var settings = {
176 var settings = {
190 processData : false,
177 processData : false,
191 type: method,
178 type: "POST",
192 data: JSON.stringify({copy_from: from}),
179 data: JSON.stringify({copy_from: from_file}),
193 dataType : "json",
180 dataType : "json",
194 success: options.success || function() {},
181 success: options.success || function() {},
195 error: this.create_basic_error_handler(options.error)
182 error: this.create_basic_error_handler(options.error)
@@ -204,8 +191,8 b' define(['
204 * Checkpointing Functions
191 * Checkpointing Functions
205 */
192 */
206
193
207 Contents.prototype.create_checkpoint = function(path, name, options) {
194 Contents.prototype.create_checkpoint = function(path, options) {
208 var url = this.api_url(path, name, 'checkpoints');
195 var url = this.api_url(path, 'checkpoints');
209 var settings = {
196 var settings = {
210 type : "POST",
197 type : "POST",
211 success: options.success || function() {},
198 success: options.success || function() {},
@@ -214,8 +201,8 b' define(['
214 $.ajax(url, settings);
201 $.ajax(url, settings);
215 };
202 };
216
203
217 Contents.prototype.list_checkpoints = function(path, name, options) {
204 Contents.prototype.list_checkpoints = function(path, options) {
218 var url = this.api_url(path, name, 'checkpoints');
205 var url = this.api_url(path, 'checkpoints');
219 var settings = {
206 var settings = {
220 type : "GET",
207 type : "GET",
221 success: options.success,
208 success: options.success,
@@ -224,8 +211,8 b' define(['
224 $.ajax(url, settings);
211 $.ajax(url, settings);
225 };
212 };
226
213
227 Contents.prototype.restore_checkpoint = function(path, name, checkpoint_id, options) {
214 Contents.prototype.restore_checkpoint = function(path, checkpoint_id, options) {
228 var url = this.api_url(path, name, 'checkpoints', checkpoint_id);
215 var url = this.api_url(path, 'checkpoints', checkpoint_id);
229 var settings = {
216 var settings = {
230 type : "POST",
217 type : "POST",
231 success: options.success || function() {},
218 success: options.success || function() {},
@@ -234,8 +221,8 b' define(['
234 $.ajax(url, settings);
221 $.ajax(url, settings);
235 };
222 };
236
223
237 Contents.prototype.delete_checkpoint = function(path, name, checkpoint_id, options) {
224 Contents.prototype.delete_checkpoint = function(path, checkpoint_id, options) {
238 var url = this.api_url(path, name, 'checkpoints', checkpoint_id);
225 var url = this.api_url(path, 'checkpoints', checkpoint_id);
239 var settings = {
226 var settings = {
240 type : "DELETE",
227 type : "DELETE",
241 success: options.success || function() {},
228 success: options.success || function() {},
@@ -255,10 +242,8 b' define(['
255 * representing individual files or directories. Each dictionary has
242 * representing individual files or directories. Each dictionary has
256 * the keys:
243 * the keys:
257 * type: "notebook" or "directory"
244 * type: "notebook" or "directory"
258 * name: the name of the file or directory
259 * created: created date
245 * created: created date
260 * last_modified: last modified dat
246 * last_modified: last modified dat
261 * path: the path
262 * @method list_notebooks
247 * @method list_notebooks
263 * @param {String} path The path to list notebooks in
248 * @param {String} path The path to list notebooks in
264 * @param {Function} load_callback called with list of notebooks on success
249 * @param {Function} load_callback called with list of notebooks on success
@@ -15,7 +15,6 b' define(['
15 * all other operations, the kernel object should be used.
15 * all other operations, the kernel object should be used.
16 *
16 *
17 * Options should include:
17 * Options should include:
18 * - notebook_name: the notebook name
19 * - notebook_path: the path (not including name) to the notebook
18 * - notebook_path: the path (not including name) to the notebook
20 * - kernel_name: the type of kernel (e.g. python3)
19 * - kernel_name: the type of kernel (e.g. python3)
21 * - base_url: the root url of the notebook server
20 * - base_url: the root url of the notebook server
@@ -28,7 +27,6 b' define(['
28 var Session = function (options) {
27 var Session = function (options) {
29 this.id = null;
28 this.id = null;
30 this.notebook_model = {
29 this.notebook_model = {
31 name: options.notebook_name,
32 path: options.notebook_path
30 path: options.notebook_path
33 };
31 };
34 this.kernel_model = {
32 this.kernel_model = {
@@ -154,15 +152,11 b' define(['
154 * undefined, then they will not be changed.
152 * undefined, then they will not be changed.
155 *
153 *
156 * @function rename_notebook
154 * @function rename_notebook
157 * @param {string} [name] - new notebook name
155 * @param {string} [path] - new notebook path
158 * @param {string} [path] - new path to notebook
159 * @param {function} [success] - function executed on ajax success
156 * @param {function} [success] - function executed on ajax success
160 * @param {function} [error] - functon executed on ajax error
157 * @param {function} [error] - functon executed on ajax error
161 */
158 */
162 Session.prototype.rename_notebook = function (name, path, success, error) {
159 Session.prototype.rename_notebook = function (path, success, error) {
163 if (name !== undefined) {
164 this.notebook_model.name = name;
165 }
166 if (path !== undefined) {
160 if (path !== undefined) {
167 this.notebook_model.path = path;
161 this.notebook_model.path = path;
168 }
162 }
@@ -208,7 +202,6 b' define(['
208 * fresh. If options are given, they can include any of the
202 * fresh. If options are given, they can include any of the
209 * following:
203 * following:
210 *
204 *
211 * - notebook_name - the name of the notebook
212 * - notebook_path - the path to the notebook
205 * - notebook_path - the path to the notebook
213 * - kernel_name - the name (type) of the kernel
206 * - kernel_name - the name (type) of the kernel
214 *
207 *
@@ -220,9 +213,6 b' define(['
220 Session.prototype.restart = function (options, success, error) {
213 Session.prototype.restart = function (options, success, error) {
221 var that = this;
214 var that = this;
222 var start = function () {
215 var start = function () {
223 if (options && options.notebook_name) {
224 that.notebook_model.name = options.notebook_name;
225 }
226 if (options && options.notebook_path) {
216 if (options && options.notebook_path) {
227 that.notebook_model.path = options.notebook_path;
217 that.notebook_model.path = options.notebook_path;
228 }
218 }
@@ -238,8 +228,8 b' define(['
238 // Helper functions
228 // Helper functions
239
229
240 /**
230 /**
241 * Get the data model for the session, which includes the notebook
231 * Get the data model for the session, which includes the notebook path
242 * (name and path) and kernel (name and id).
232 * and kernel (name and id).
243 *
233 *
244 * @function _get_model
234 * @function _get_model
245 * @returns {Object} - the data model
235 * @returns {Object} - the data model
@@ -266,7 +256,6 b' define(['
266 this.session_url = utils.url_join_encode(this.session_service_url, this.id);
256 this.session_url = utils.url_join_encode(this.session_service_url, this.id);
267 }
257 }
268 if (data && data.notebook) {
258 if (data && data.notebook) {
269 this.notebook_model.name = data.notebook.name;
270 this.notebook_model.path = data.notebook.path;
259 this.notebook_model.path = data.notebook.path;
271 }
260 }
272 if (data && data.kernel) {
261 if (data && data.kernel) {
@@ -2,8 +2,9 b''
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 require([
4 require([
5 'base/js/namespace',
6 'jquery',
5 'jquery',
6 'base/js/namespace',
7 'base/js/dialog',
7 'base/js/events',
8 'base/js/events',
8 'base/js/page',
9 'base/js/page',
9 'base/js/utils',
10 'base/js/utils',
@@ -19,18 +20,20 b' require(['
19 'bootstrap',
20 'bootstrap',
20 'custom/custom',
21 'custom/custom',
21 ], function(
22 ], function(
22 IPython,
23 $,
23 $,
24 IPython,
25 dialog,
24 events,
26 events,
25 page,
27 page,
26 utils,
28 utils,
27 contents,
29 contents_service,
28 notebooklist,
30 notebooklist,
29 clusterlist,
31 clusterlist,
30 sesssionlist,
32 sesssionlist,
31 kernellist,
33 kernellist,
32 terminallist,
34 terminallist,
33 loginwidget){
35 loginwidget){
36 "use strict";
34
37
35 page = new page.Page();
38 page = new page.Page();
36
39
@@ -38,36 +41,37 b' require(['
38 base_url: utils.get_body_data("baseUrl"),
41 base_url: utils.get_body_data("baseUrl"),
39 notebook_path: utils.get_body_data("notebookPath"),
42 notebook_path: utils.get_body_data("notebookPath"),
40 };
43 };
41 session_list = new sesssionlist.SesssionList($.extend({
44 var session_list = new sesssionlist.SesssionList($.extend({
42 events: events},
45 events: events},
43 common_options));
46 common_options));
44 contents = new contents.Contents($.extend({
47 var contents = new contents_service.Contents($.extend({
45 events: events},
48 events: events},
46 common_options));
49 common_options));
47 notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
50 var notebook_list = new notebooklist.NotebookList('#notebook_list', $.extend({
48 contents: contents,
51 contents: contents,
49 session_list: session_list},
52 session_list: session_list},
50 common_options));
53 common_options));
51 cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
54 var cluster_list = new clusterlist.ClusterList('#cluster_list', common_options);
52 kernel_list = new kernellist.KernelList('#running_list', $.extend({
55 var kernel_list = new kernellist.KernelList('#running_list', $.extend({
53 session_list: session_list},
56 session_list: session_list},
54 common_options));
57 common_options));
55
58
59 var terminal_list;
56 if (utils.get_body_data("terminalsAvailable") === "True") {
60 if (utils.get_body_data("terminalsAvailable") === "True") {
57 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
61 terminal_list = new terminallist.TerminalList('#terminal_list', common_options);
58 }
62 }
59
63
60 login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
64 var login_widget = new loginwidget.LoginWidget('#login_widget', common_options);
61
65
62 $('#new_notebook').click(function (e) {
66 $('#new_notebook').click(function (e) {
63 contents.new(common_options.notebook_path, null, {
67 contents.new(common_options.notebook_path, {
64 ext: ".ipynb",
68 ext: ".ipynb",
65 extra_settings: {async: false}, // So we can open a new window afterwards
69 extra_settings: {async: false}, // So we can open a new window afterwards
66 success: function (data) {
70 success: function (data) {
67 window.open(
71 window.open(
68 utils.url_join_encode(
72 utils.url_join_encode(
69 common_options.base_url, 'notebooks',
73 common_options.base_url, 'notebooks',
70 data.path, data.name
74 data.path
71 ), '_blank');
75 ), '_blank');
72 },
76 },
73 error: function(error) {
77 error: function(error) {
@@ -100,7 +100,7 b' define(['
100 };
100 };
101 reader.onerror = function (event) {
101 reader.onerror = function (event) {
102 var item = $(event.target).data('item');
102 var item = $(event.target).data('item');
103 var name = item.data('name')
103 var name = item.data('name');
104 item.remove();
104 item.remove();
105 dialog.modal({
105 dialog.modal({
106 title : 'Failed to read file',
106 title : 'Failed to read file',
@@ -141,7 +141,7 b' define(['
141 };
141 };
142
142
143 NotebookList.prototype.load_list = function () {
143 NotebookList.prototype.load_list = function () {
144 var that = this
144 var that = this;
145 this.contents.list_contents(that.notebook_path, {
145 this.contents.list_contents(that.notebook_path, {
146 success: $.proxy(this.draw_notebook_list, this),
146 success: $.proxy(this.draw_notebook_list, this),
147 error: function(error) {
147 error: function(error) {
@@ -177,7 +177,7 b' define(['
177 model = {
177 model = {
178 type: 'directory',
178 type: 'directory',
179 name: '..',
179 name: '..',
180 path: path,
180 path: utils.url_path_split(path)[0],
181 };
181 };
182 this.add_link(model, item);
182 this.add_link(model, item);
183 offset += 1;
183 offset += 1;
@@ -240,8 +240,7 b' define(['
240 utils.url_join_encode(
240 utils.url_join_encode(
241 this.base_url,
241 this.base_url,
242 uri_prefix,
242 uri_prefix,
243 path,
243 path
244 name
245 )
244 )
246 );
245 );
247 // directory nav doesn't open new tabs
246 // directory nav doesn't open new tabs
@@ -311,7 +310,6 b' define(['
311 };
310 };
312
311
313 NotebookList.prototype.add_delete_button = function (item) {
312 NotebookList.prototype.add_delete_button = function (item) {
314 var new_buttons = $('<span/>').addClass("btn-group pull-right");
315 var notebooklist = this;
313 var notebooklist = this;
316 var delete_button = $("<button/>").text("Delete").addClass("btn btn-default btn-xs").
314 var delete_button = $("<button/>").text("Delete").addClass("btn btn-default btn-xs").
317 click(function (e) {
315 click(function (e) {
@@ -322,7 +320,7 b' define(['
322 var parent_item = that.parents('div.list_item');
320 var parent_item = that.parents('div.list_item');
323 var name = parent_item.data('nbname');
321 var name = parent_item.data('nbname');
324 var path = parent_item.data('path');
322 var path = parent_item.data('path');
325 var message = 'Are you sure you want to permanently delete the file: ' + nbname + '?';
323 var message = 'Are you sure you want to permanently delete the file: ' + name + '?';
326 dialog.modal({
324 dialog.modal({
327 title : "Delete file",
325 title : "Delete file",
328 body : message,
326 body : message,
@@ -330,9 +328,9 b' define(['
330 Delete : {
328 Delete : {
331 class: "btn-danger",
329 class: "btn-danger",
332 click: function() {
330 click: function() {
333 notebooklist.contents.delete(name, path, {
331 notebooklist.contents.delete(path, {
334 success: function() {
332 success: function() {
335 notebooklist.notebook_deleted(path, name);
333 notebooklist.notebook_deleted(path);
336 }
334 }
337 });
335 });
338 }
336 }
@@ -345,25 +343,24 b' define(['
345 item.find(".item_buttons").text("").append(delete_button);
343 item.find(".item_buttons").text("").append(delete_button);
346 };
344 };
347
345
348 NotebookList.prototype.notebook_deleted = function(path, name) {
346 NotebookList.prototype.notebook_deleted = function(path) {
349 // Remove the deleted notebook.
347 // Remove the deleted notebook.
350 $( ":data(nbname)" ).each(function() {
348 $( ":data(nbname)" ).each(function() {
351 var element = $( this );
349 var element = $(this);
352 if (element.data( "nbname" ) == d.name &&
350 if (element.data("path") == path) {
353 element.data( "path" ) == d.path) {
354 element.remove();
351 element.remove();
355 }
352 }
356 });
353 });
357 }
354 };
358
355
359
356
360 NotebookList.prototype.add_upload_button = function (item, type) {
357 NotebookList.prototype.add_upload_button = function (item) {
361 var that = this;
358 var that = this;
362 var upload_button = $('<button/>').text("Upload")
359 var upload_button = $('<button/>').text("Upload")
363 .addClass('btn btn-primary btn-xs upload_button')
360 .addClass('btn btn-primary btn-xs upload_button')
364 .click(function (e) {
361 .click(function (e) {
365 var path = that.notebook_path;
366 var filename = item.find('.item_name > input').val();
362 var filename = item.find('.item_name > input').val();
363 var path = utils.url_path_join(that.notebook_path, filename);
367 var filedata = item.data('filedata');
364 var filedata = item.data('filedata');
368 var format = 'text';
365 var format = 'text';
369 if (filename.length === 0 || filename[0] === '.') {
366 if (filename.length === 0 || filename[0] === '.') {
@@ -385,10 +382,7 b' define(['
385 filedata = btoa(bytes);
382 filedata = btoa(bytes);
386 format = 'base64';
383 format = 'base64';
387 }
384 }
388 var model = {
385 var model = {};
389 path: path,
390 name: filename
391 };
392
386
393 var name_and_ext = utils.splitext(filename);
387 var name_and_ext = utils.splitext(filename);
394 var file_ext = name_and_ext[1];
388 var file_ext = name_and_ext[1];
@@ -418,34 +412,22 b' define(['
418 model.content = filedata;
412 model.content = filedata;
419 content_type = 'application/octet-stream';
413 content_type = 'application/octet-stream';
420 }
414 }
421 var filedata = item.data('filedata');
415 filedata = item.data('filedata');
422
416
423 var settings = {
417 var settings = {
424 processData : false,
418 success : function () {
425 cache : false,
426 type : 'PUT',
427 data : JSON.stringify(model),
428 contentType: content_type,
429 success : function (data, status, xhr) {
430 item.removeClass('new-file');
419 item.removeClass('new-file');
431 that.add_link(model, item);
420 that.add_link(model, item);
432 that.add_delete_button(item);
421 that.add_delete_button(item);
433 that.session_list.load_sessions();
422 that.session_list.load_sessions();
434 },
423 },
435 error : utils.log_ajax_error,
436 };
424 };
437
438 var url = utils.url_join_encode(
439 that.base_url,
440 'api/contents',
441 that.notebook_path,
442 filename
443 );
444
425
445 var exists = false;
426 var exists = false;
446 $.each(that.element.find('.list_item:not(.new-file)'), function(k,v){
427 $.each(that.element.find('.list_item:not(.new-file)'), function(k,v){
447 if ($(v).data('name') === filename) { exists = true; return false; }
428 if ($(v).data('name') === filename) { exists = true; return false; }
448 });
429 });
430
449 if (exists) {
431 if (exists) {
450 dialog.modal({
432 dialog.modal({
451 title : "Replace file",
433 title : "Replace file",
@@ -453,7 +435,9 b' define(['
453 buttons : {
435 buttons : {
454 Overwrite : {
436 Overwrite : {
455 class: "btn-danger",
437 class: "btn-danger",
456 click: function() { $.ajax(url, settings); }
438 click: function () {
439 that.contents.save(path, model, settings);
440 }
457 },
441 },
458 Cancel : {
442 Cancel : {
459 click: function() { item.remove(); }
443 click: function() { item.remove(); }
@@ -461,7 +445,7 b' define(['
461 }
445 }
462 });
446 });
463 } else {
447 } else {
464 $.ajax(url, settings);
448 that.contents.save(path, model, settings);
465 }
449 }
466
450
467 return false;
451 return false;
@@ -478,7 +462,7 b' define(['
478 };
462 };
479
463
480
464
481 // Backwards compatability.
465 // Backwards compatability.
482 IPython.NotebookList = NotebookList;
466 IPython.NotebookList = NotebookList;
483
467
484 return {'NotebookList': NotebookList};
468 return {'NotebookList': NotebookList};
General Comments 0
You need to be logged in to leave comments. Login now