|
|
|
|
@ -30,14 +30,13 @@ define([
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Notebook Functions
|
|
|
|
|
* File Functions (including notebook operations)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a notebook.
|
|
|
|
|
* Load a file.
|
|
|
|
|
*
|
|
|
|
|
* Calls success_callback with notebook JSON object (as string), or
|
|
|
|
|
* error_callback with error.
|
|
|
|
|
* Calls success_callback with file JSON model, or error_callback with error.
|
|
|
|
|
*
|
|
|
|
|
* @method load_notebook
|
|
|
|
|
* @param {String} path
|
|
|
|
|
@ -45,16 +44,15 @@ define([
|
|
|
|
|
* @param {Function} success_callback
|
|
|
|
|
* @param {Function} error_callback
|
|
|
|
|
*/
|
|
|
|
|
Contents.prototype.load_notebook = function (path, name, success_callback,
|
|
|
|
|
error_callback) {
|
|
|
|
|
Contents.prototype.load_file = function (path, name, options) {
|
|
|
|
|
// We do the call with settings so we can set cache to false.
|
|
|
|
|
var settings = {
|
|
|
|
|
processData : false,
|
|
|
|
|
cache : false,
|
|
|
|
|
type : "GET",
|
|
|
|
|
dataType : "json",
|
|
|
|
|
success : success_callback,
|
|
|
|
|
error : error_callback,
|
|
|
|
|
success : options.success_callback,
|
|
|
|
|
error : options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
this.events.trigger('notebook_loading.Notebook');
|
|
|
|
|
var url = this.api_url(path, name);
|
|
|
|
|
@ -63,52 +61,44 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new notebook file at the specified path, and
|
|
|
|
|
* opens that notebook in a new window.
|
|
|
|
|
* Creates a new notebook file at the specified directory path.
|
|
|
|
|
*
|
|
|
|
|
* @method scroll_to_cell
|
|
|
|
|
* @param {String} path The path to create the new notebook at
|
|
|
|
|
*/
|
|
|
|
|
Contents.prototype.new_notebook = function(path, options) {
|
|
|
|
|
var base_url = this.base_url;
|
|
|
|
|
var success_callback = options.success_callback || function(data, status, xhr) {};
|
|
|
|
|
var error_callback = options.error_callback || function(xhr, status, error) {};
|
|
|
|
|
var error_callback = options.error_callback || function() {};
|
|
|
|
|
var settings = {
|
|
|
|
|
processData : false,
|
|
|
|
|
cache : false,
|
|
|
|
|
type : "POST",
|
|
|
|
|
dataType : "json",
|
|
|
|
|
async : false,
|
|
|
|
|
success : success_callback,
|
|
|
|
|
error : function(xhr, status, error) {
|
|
|
|
|
utils.log_ajax_error(xhr, status, error);
|
|
|
|
|
error_callback(xhr, status, error);
|
|
|
|
|
}
|
|
|
|
|
success : options.success_callback || function() {},
|
|
|
|
|
error : options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
$.ajax(this.api_url(path), settings);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Contents.prototype.delete_notebook = function(name, path) {
|
|
|
|
|
Contents.prototype.delete_file = function(name, path, options) {
|
|
|
|
|
var error_callback = options.error_callback || function() {};
|
|
|
|
|
var that = this;
|
|
|
|
|
var settings = {
|
|
|
|
|
processData : false,
|
|
|
|
|
cache : false,
|
|
|
|
|
type : "DELETE",
|
|
|
|
|
dataType : "json",
|
|
|
|
|
success : $.proxy(this.events.trigger, this.events,
|
|
|
|
|
'notebook_deleted.Contents',
|
|
|
|
|
{
|
|
|
|
|
name: name,
|
|
|
|
|
path: path
|
|
|
|
|
}),
|
|
|
|
|
error : utils.log_ajax_error
|
|
|
|
|
success : options.success_callback || function() {},
|
|
|
|
|
error : function(xhr, status, error) {
|
|
|
|
|
utils.log_ajax_error(xhr, status, error);
|
|
|
|
|
error_callback(xhr, status, error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var url = this.api_url(path, name);
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Contents.prototype.rename_notebook = function(path, name, new_name) {
|
|
|
|
|
var that = this;
|
|
|
|
|
var data = {name: new_name};
|
|
|
|
|
Contents.prototype.rename_file = function(path, name, new_path, new_name, options) {
|
|
|
|
|
var data = {name: new_name, path: new_path};
|
|
|
|
|
var settings = {
|
|
|
|
|
processData : false,
|
|
|
|
|
cache : false,
|
|
|
|
|
@ -116,31 +106,14 @@ define([
|
|
|
|
|
data : JSON.stringify(data),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
success : function (json, status, xhr) {
|
|
|
|
|
that.events.trigger('notebook_rename_success.Contents',
|
|
|
|
|
json);
|
|
|
|
|
},
|
|
|
|
|
error : function (xhr, status, error) {
|
|
|
|
|
that.events.trigger('notebook_rename_error.Contents',
|
|
|
|
|
[xhr, status, error]);
|
|
|
|
|
}
|
|
|
|
|
success : options.success_callback || function() {},
|
|
|
|
|
error : options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
var url = this.api_url(path, name);
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Contents.prototype.save_notebook = function(path, name, content,
|
|
|
|
|
extra_settings) {
|
|
|
|
|
var that = content;
|
|
|
|
|
// Create a JSON model to be sent to the server.
|
|
|
|
|
var model = {
|
|
|
|
|
name : name,
|
|
|
|
|
path : path,
|
|
|
|
|
type : "notebook",
|
|
|
|
|
content : content
|
|
|
|
|
};
|
|
|
|
|
// time the ajax call for autosave tuning purposes.
|
|
|
|
|
var start = new Date().getTime();
|
|
|
|
|
Contents.prototype.save_file = function(path, name, model, options) {
|
|
|
|
|
// We do the call with settings so we can set cache to false.
|
|
|
|
|
var settings = {
|
|
|
|
|
processData : false,
|
|
|
|
|
@ -148,18 +121,11 @@ define([
|
|
|
|
|
type : "PUT",
|
|
|
|
|
data : JSON.stringify(model),
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
success : $.proxy(this.events.trigger, this.events,
|
|
|
|
|
'notebook_save_success.Contents',
|
|
|
|
|
$.extend(model, { start : start })),
|
|
|
|
|
error : function (xhr, status, error) {
|
|
|
|
|
that.events.trigger('notebook_save_error.Contents',
|
|
|
|
|
[xhr, status, error, model]);
|
|
|
|
|
}
|
|
|
|
|
success : options.success_callback || function() {},
|
|
|
|
|
error : options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
if (extra_settings) {
|
|
|
|
|
for (var key in extra_settings) {
|
|
|
|
|
settings[key] = extra_settings[key];
|
|
|
|
|
}
|
|
|
|
|
if (options.extra_settings) {
|
|
|
|
|
$.extend(settings, options.extra_settings);
|
|
|
|
|
}
|
|
|
|
|
var url = this.api_url(path, name);
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
@ -173,8 +139,8 @@ define([
|
|
|
|
|
var url = this.api_url(path, name, 'checkpoints');
|
|
|
|
|
var settings = {
|
|
|
|
|
type : "POST",
|
|
|
|
|
success: options.success_callback || function(data, status, xhr) {},
|
|
|
|
|
error: options.error_callback || function(xhr, status, error_msg) {}
|
|
|
|
|
success: options.success_callback || function() {},
|
|
|
|
|
error: options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
};
|
|
|
|
|
@ -183,8 +149,8 @@ define([
|
|
|
|
|
var url = this.api_url(path, name, 'checkpoints');
|
|
|
|
|
var settings = {
|
|
|
|
|
type : "GET",
|
|
|
|
|
success: options.success_callback || function(data, status, xhr) {},
|
|
|
|
|
error: options.error_callback || function(xhr, status, error_msg) {}
|
|
|
|
|
success: options.success_callback,
|
|
|
|
|
error: options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
};
|
|
|
|
|
@ -193,8 +159,8 @@ define([
|
|
|
|
|
var url = this.api_url(path, name, 'checkpoints', checkpoint_id);
|
|
|
|
|
var settings = {
|
|
|
|
|
type : "POST",
|
|
|
|
|
success: options.success_callback || function(data, status, xhr) {},
|
|
|
|
|
error: options.error_callback || function(xhr, status, error_msg) {}
|
|
|
|
|
success: options.success_callback || function() {},
|
|
|
|
|
error: options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
};
|
|
|
|
|
@ -203,8 +169,8 @@ define([
|
|
|
|
|
var url = this.api_url(path, name, 'checkpoints', checkpoint_id);
|
|
|
|
|
var settings = {
|
|
|
|
|
type : "DELETE",
|
|
|
|
|
success: options.success_callback || function(data, status, xhr) {},
|
|
|
|
|
error: options.error_callback || function(xhr, status, error_msg) {}
|
|
|
|
|
success: options.success_callback || function() {},
|
|
|
|
|
error: options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
$.ajax(url, settings);
|
|
|
|
|
};
|
|
|
|
|
@ -229,15 +195,14 @@ define([
|
|
|
|
|
* @param {Function} load_callback called with list of notebooks on success
|
|
|
|
|
* @param {Function} error_callback called with ajax results on error
|
|
|
|
|
*/
|
|
|
|
|
Contents.prototype.list_contents = function(path, load_callback,
|
|
|
|
|
error_callback) {
|
|
|
|
|
Contents.prototype.list_contents = function(path, options) {
|
|
|
|
|
var settings = {
|
|
|
|
|
processData : false,
|
|
|
|
|
cache : false,
|
|
|
|
|
type : "GET",
|
|
|
|
|
dataType : "json",
|
|
|
|
|
success : load_callback,
|
|
|
|
|
error : error_callback
|
|
|
|
|
success : options.success_callback,
|
|
|
|
|
error : options.error_callback || function() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$.ajax(this.api_url(path), settings);
|
|
|
|
|
|