Add copy_file to contents JS API

pull/37/head
Thomas Kluyver 11 years ago
parent 1ae6be218d
commit a2f3e23fd8

@ -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) {

@ -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

Loading…
Cancel
Save