diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 05d1c06..5ef66c3 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -2041,31 +2041,17 @@ define([
};
Notebook.prototype.copy_notebook = function(){
- var path = this.notebook_path;
var base_url = this.base_url;
- var settings = {
- processData : false,
- cache : false,
- type : "POST",
- dataType : "json",
- data : JSON.stringify({copy_from : this.notebook_name}),
- async : false,
- success : function (data, status, xhr) {
+ this.contents.copy_file(this.notebook_path, null, this.notebook_name, {
+ // synchronous so we can open a new window on success
+ extra_settings: {async: false},
+ success: function (data) {
window.open(utils.url_join_encode(
- base_url,
- 'notebooks',
- data.path,
- data.name
+ base_url, 'notebooks', data.path, data.name
), '_blank');
},
- error : utils.log_ajax_error,
- };
- var url = utils.url_join_encode(
- base_url,
- 'api/contents',
- path
- );
- $.ajax(url,settings);
+ error : utils.log_ajax_error
+ });
};
Notebook.prototype.rename = function (new_name) {
diff --git a/IPython/html/static/services/contents.js b/IPython/html/static/services/contents.js
index aeff6af..8494e2a 100644
--- a/IPython/html/static/services/contents.js
+++ b/IPython/html/static/services/contents.js
@@ -153,7 +153,6 @@ define([
// We do the call with settings so we can set cache to false.
var settings = {
processData : false,
- cache : false,
type : "PUT",
data : JSON.stringify(model),
contentType: 'application/json',
@@ -166,6 +165,31 @@ define([
var url = this.api_url(path, name);
$.ajax(url, settings);
};
+
+ Contents.prototype.copy_file = function(to_path, to_name, from, options) {
+ var url, method;
+ if (to_name) {
+ url = this.api_url(to_path, to_name);
+ method = "PUT";
+ } else {
+ url = this.api_url(to_path);
+ method = "POST";
+ }
+
+ var settings = {
+ processData : false,
+ cache : false,
+ type: method,
+ data: JSON.stringify({copy_from: from}),
+ dataType : "json",
+ success: options.success || function() {},
+ error: this.create_basic_error_handler(options.error)
+ };
+ if (options.extra_settings) {
+ $.extend(settings, options.extra_settings);
+ }
+ $.ajax(url, settings);
+ };
/**
* Checkpointing Functions