From 260ebcebcfac6c4a139dc31215b041a0360b162c Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 4 Nov 2014 11:08:00 -0800 Subject: [PATCH 1/4] Open window before creating new notebook Avoids the need for synchronous requests. --- IPython/html/static/notebook/js/menubar.js | 8 ++++---- IPython/html/static/tree/js/main.js | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 0b54e9008..1ac758c33 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -88,19 +88,19 @@ define([ // File var that = this; this.element.find('#new_notebook').click(function () { + var w = window.open(); // Create a new notebook in the same path as the current // notebook's path. var parent = utils.url_path_split(that.notebook.notebook_path)[0]; that.contents.new_untitled(parent, { type: "notebook", - extra_settings: {async: false}, // So we can open a new window afterwards success: function (data) { - window.open( - utils.url_join_encode( + w.location = utils.url_join_encode( that.base_url, 'notebooks', data.path - ), '_blank'); + ); }, error: function(error) { + w.close(); dialog.modal({ title : 'Creating Notebook Failed', body : "The error was: " + error.message, diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 25ce90510..53d2ca937 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -64,17 +64,16 @@ require([ var login_widget = new loginwidget.LoginWidget('#login_widget', common_options); $('#new_notebook').click(function (e) { + var w = window.open(); contents.new_untitled(common_options.notebook_path, { type: "notebook", - extra_settings: {async: false}, // So we can open a new window afterwards success: function (data) { - window.open( - utils.url_join_encode( - common_options.base_url, 'notebooks', - data.path - ), '_blank'); + w.location = utils.url_join_encode( + common_options.base_url, 'notebooks', data.path + ); }, error: function(error) { + w.close(); dialog.modal({ title : 'Creating Notebook Failed', body : "The error was: " + error.message, From b046af083c09833d7e2fd2ceddaed1e03d17f1f2 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 4 Nov 2014 11:08:16 -0800 Subject: [PATCH 2/4] Fix some bugs in deleting notebooks from the dashboard --- IPython/html/static/tree/js/notebooklist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index 678fceb5a..fbc0091a3 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -318,7 +318,7 @@ define([ // We use the filename from the parent list_item element's // data because the outer scope's values change as we iterate through the loop. var parent_item = that.parents('div.list_item'); - var name = parent_item.data('nbname'); + var name = parent_item.data('name'); var path = parent_item.data('path'); var message = 'Are you sure you want to permanently delete the file: ' + name + '?'; dialog.modal({ @@ -345,7 +345,7 @@ define([ NotebookList.prototype.notebook_deleted = function(path) { // Remove the deleted notebook. - $( ":data(nbname)" ).each(function() { + $( ":data(path)" ).each(function() { var element = $(this); if (element.data("path") == path) { element.remove(); From ef98d489210b677ef739d00ff532414002b099d3 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 4 Nov 2014 11:08:52 -0800 Subject: [PATCH 3/4] Disable passing extra AJAX settings to Contents.new() --- IPython/html/static/services/contents.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/IPython/html/static/services/contents.js b/IPython/html/static/services/contents.js index 481015c42..6be2e4939 100644 --- a/IPython/html/static/services/contents.js +++ b/IPython/html/static/services/contents.js @@ -114,9 +114,6 @@ define([ success : options.success || function() {}, error : this.create_basic_error_handler(options.error) }; - if (options.extra_settings) { - $.extend(settings, options.extra_settings); - } $.ajax(this.api_url(path), settings); }; From c7529c53ebdc4e8045dd4d513e2b38a8e016a319 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 4 Nov 2014 11:17:34 -0800 Subject: [PATCH 4/4] Eliminate remaining uses of extra_settings --- IPython/html/static/notebook/js/notebook.js | 18 ++++++++++-------- IPython/html/static/services/contents.js | 6 ------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 21bcba24b..ace59fda7 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1892,7 +1892,7 @@ define([ * * @method save_notebook */ - Notebook.prototype.save_notebook = function (extra_settings) { + Notebook.prototype.save_notebook = function () { // Create a JSON model to be sent to the server. var model = { type : "notebook", @@ -1903,7 +1903,6 @@ define([ var that = this; this.contents.save(this.notebook_path, model, { - extra_settings: extra_settings, success: $.proxy(this.save_notebook_success, this, start), error: function (error) { that.events.trigger('notebook_save_failed.Notebook', error); @@ -1977,7 +1976,7 @@ define([ * * @method trust_notebook */ - Notebook.prototype.trust_notebook = function (extra_settings) { + Notebook.prototype.trust_notebook = function () { var body = $("
").append($("

") .text("A trusted IPython notebook may execute hidden malicious code ") .append($("") @@ -2024,15 +2023,18 @@ define([ Notebook.prototype.copy_notebook = function(){ var base_url = this.base_url; + var w = window.open(); var parent = utils.url_path_split(this.notebook_path)[0]; this.contents.copy(this.notebook_path, parent, { - // synchronous so we can open a new window on success - extra_settings: {async: false}, success: function (data) { - window.open(utils.url_join_encode( + w.location = utils.url_join_encode( base_url, 'notebooks', data.path - ), '_blank'); - } + ); + }, + error : function(error) { + w.close(); + console.log(error); + }, }); }; diff --git a/IPython/html/static/services/contents.js b/IPython/html/static/services/contents.js index 6be2e4939..b1ebfb81b 100644 --- a/IPython/html/static/services/contents.js +++ b/IPython/html/static/services/contents.js @@ -162,9 +162,6 @@ define([ success : options.success || function() {}, error : this.create_basic_error_handler(options.error) }; - if (options.extra_settings) { - $.extend(settings, options.extra_settings); - } var url = this.api_url(path); $.ajax(url, settings); }; @@ -182,9 +179,6 @@ define([ success: options.success || function() {}, error: this.create_basic_error_handler(options.error) }; - if (options.extra_settings) { - $.extend(settings, options.extra_settings); - } $.ajax(url, settings); };