##// END OF EJS Templates
Cut out some superfluous events
Cut out some superfluous events

File last commit:

r18653:01ccf42b
r18654:a7fae757
Show More
contents.js
215 lines | 7.0 KiB | application/javascript | JavascriptLexer
jhemmelg
Initial interface for javascript contentmanagers...
r18618 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
KesterTong
Style and bug fixes
r18620 'base/js/utils',
KesterTong
Adds dialog on new_notebook failure...
r18623 'base/js/dialog',
], function(IPython, $, utils, dialog) {
Jeff Hemmelgarn
Move contentmanager to contents
r18643 var Contents = function(options) {
jhemmelg
Initial interface for javascript contentmanagers...
r18618 // Constructor
//
Jeff Hemmelgarn
Move contentmanager to contents
r18643 // A contents handles passing file operations
jhemmelg
Initial interface for javascript contentmanagers...
r18618 // to the back-end. This includes checkpointing
// with the normal file operations.
//
// Parameters:
KesterTong
Use IPython style constructor
r18621 // options: dictionary
// Dictionary of keyword arguments.
KesterTong
Make ContentManager stateless...
r18622 // events: $(Events) instance
KesterTong
Use IPython style constructor
r18621 // base_url: string
KesterTong
Make ContentManager stateless...
r18622 this.events = options.events;
KesterTong
Use IPython style constructor
r18621 this.base_url = options.base_url;
KesterTong
Style and bug fixes
r18620 };
Thomas Kluyver
Add Contents.api_url convenience function
r18650
Contents.prototype.api_url = function() {
var url_parts = [this.base_url, 'api/contents'].concat(
Array.prototype.slice.apply(arguments));
return utils.url_join_encode.apply(null, url_parts);
};
KesterTong
Make ContentManager stateless...
r18622 /**
Thomas Kluyver
Make contents JS API consistent
r18653 * File Functions (including notebook operations)
KesterTong
Moves list_notebooks to ContentManager
r18636 */
/**
Thomas Kluyver
Make contents JS API consistent
r18653 * Load a file.
KesterTong
Moves load_notebook to ContentManager and adds new_notebook to Google Drive version
r18638 *
Thomas Kluyver
Make contents JS API consistent
r18653 * Calls success_callback with file JSON model, or error_callback with error.
KesterTong
Moves load_notebook to ContentManager and adds new_notebook to Google Drive version
r18638 *
* @method load_notebook
* @param {String} path
* @param {String} name
* @param {Function} success_callback
* @param {Function} error_callback
*/
Thomas Kluyver
Make contents JS API consistent
r18653 Contents.prototype.load_file = function (path, name, options) {
KesterTong
Moves load_notebook to ContentManager and adds new_notebook to Google Drive version
r18638 // We do the call with settings so we can set cache to false.
var settings = {
processData : false,
cache : false,
type : "GET",
dataType : "json",
Thomas Kluyver
Make contents JS API consistent
r18653 success : options.success_callback,
error : options.error_callback || function() {}
KesterTong
Moves load_notebook to ContentManager and adds new_notebook to Google Drive version
r18638 };
this.events.trigger('notebook_loading.Notebook');
Thomas Kluyver
Add Contents.api_url convenience function
r18650 var url = this.api_url(path, name);
KesterTong
Moves load_notebook to ContentManager and adds new_notebook to Google Drive version
r18638 $.ajax(url, settings);
};
/**
Thomas Kluyver
Make contents JS API consistent
r18653 * Creates a new notebook file at the specified directory path.
KesterTong
Make ContentManager stateless...
r18622 *
* @method scroll_to_cell
* @param {String} path The path to create the new notebook at
*/
Thomas Kluyver
Don't do UI stuff in contents API module
r18649 Contents.prototype.new_notebook = function(path, options) {
Thomas Kluyver
Make contents JS API consistent
r18653 var error_callback = options.error_callback || function() {};
jhemmelg
ContentManager function signatures updated
r18619 var settings = {
processData : false,
cache : false,
type : "POST",
dataType : "json",
Thomas Kluyver
Make contents JS API consistent
r18653 success : options.success_callback || function() {},
error : options.error_callback || function() {}
jhemmelg
ContentManager function signatures updated
r18619 };
Thomas Kluyver
Add Contents.api_url convenience function
r18650 $.ajax(this.api_url(path), settings);
KesterTong
Style and bug fixes
r18620 };
jhemmelg
Initial interface for javascript contentmanagers...
r18618
Thomas Kluyver
Make contents JS API consistent
r18653 Contents.prototype.delete_file = function(name, path, options) {
var error_callback = options.error_callback || function() {};
var that = this;
jhemmelg
ContentManager function signatures updated
r18619 var settings = {
processData : false,
cache : false,
type : "DELETE",
KesterTong
Removes unnecessary parameter from ContentManager.delete_notebook
r18629 dataType : "json",
Thomas Kluyver
Make contents JS API consistent
r18653 success : options.success_callback || function() {},
error : function(xhr, status, error) {
utils.log_ajax_error(xhr, status, error);
error_callback(xhr, status, error);
}
jhemmelg
ContentManager function signatures updated
r18619 };
Thomas Kluyver
Add Contents.api_url convenience function
r18650 var url = this.api_url(path, name);
jhemmelg
ContentManager function signatures updated
r18619 $.ajax(url, settings);
KesterTong
Style and bug fixes
r18620 };
jhemmelg
Initial interface for javascript contentmanagers...
r18618
Thomas Kluyver
Make contents JS API consistent
r18653 Contents.prototype.rename_file = function(path, name, new_path, new_name, options) {
var data = {name: new_name, path: new_path};
jhemmelg
ContentManager function signatures updated
r18619 var settings = {
processData : false,
cache : false,
type : "PATCH",
data : JSON.stringify(data),
dataType: "json",
Jeff Hemmelgarn
Move notebook.rename to contentmanager...
r18627 contentType: 'application/json',
Thomas Kluyver
Make contents JS API consistent
r18653 success : options.success_callback || function() {},
error : options.error_callback || function() {}
jhemmelg
ContentManager function signatures updated
r18619 };
Thomas Kluyver
Add Contents.api_url convenience function
r18650 var url = this.api_url(path, name);
jhemmelg
ContentManager function signatures updated
r18619 $.ajax(url, settings);
KesterTong
Style and bug fixes
r18620 };
jhemmelg
Initial interface for javascript contentmanagers...
r18618
Thomas Kluyver
Make contents JS API consistent
r18653 Contents.prototype.save_file = function(path, name, model, options) {
jhemmelg
ContentManager function signatures updated
r18619 // 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),
Jeff Hemmelgarn
Move notebook.rename to contentmanager...
r18627 contentType: 'application/json',
Thomas Kluyver
Make contents JS API consistent
r18653 success : options.success_callback || function() {},
error : options.error_callback || function() {}
jhemmelg
ContentManager function signatures updated
r18619 };
Thomas Kluyver
Make contents JS API consistent
r18653 if (options.extra_settings) {
$.extend(settings, options.extra_settings);
jhemmelg
ContentManager function signatures updated
r18619 }
Thomas Kluyver
Add Contents.api_url convenience function
r18650 var url = this.api_url(path, name);
jhemmelg
ContentManager function signatures updated
r18619 $.ajax(url, settings);
};
jhemmelg
Initial interface for javascript contentmanagers...
r18618
KesterTong
Moves list_notebooks to ContentManager
r18636 /**
* Checkpointing Functions
*/
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 Contents.prototype.create_checkpoint = function(path, name, options) {
var url = this.api_url(path, name, 'checkpoints');
var settings = {
type : "POST",
Thomas Kluyver
Make contents JS API consistent
r18653 success: options.success_callback || function() {},
error: options.error_callback || function() {}
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 };
$.ajax(url, settings);
KesterTong
Style and bug fixes
r18620 };
jhemmelg
Initial interface for javascript contentmanagers...
r18618
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 Contents.prototype.list_checkpoints = function(path, name, options) {
var url = this.api_url(path, name, 'checkpoints');
var settings = {
type : "GET",
Thomas Kluyver
Make contents JS API consistent
r18653 success: options.success_callback,
error: options.error_callback || function() {}
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 };
$.ajax(url, settings);
KesterTong
Style and bug fixes
r18620 };
jhemmelg
Initial interface for javascript contentmanagers...
r18618
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 Contents.prototype.restore_checkpoint = function(path, name, checkpoint_id, options) {
var url = this.api_url(path, name, 'checkpoints', checkpoint_id);
var settings = {
type : "POST",
Thomas Kluyver
Make contents JS API consistent
r18653 success: options.success_callback || function() {},
error: options.error_callback || function() {}
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 };
$.ajax(url, settings);
};
Contents.prototype.delete_checkpoint = function(path, name, checkpoint_id, options) {
var url = this.api_url(path, name, 'checkpoints', checkpoint_id);
var settings = {
type : "DELETE",
Thomas Kluyver
Make contents JS API consistent
r18653 success: options.success_callback || function() {},
error: options.error_callback || function() {}
Thomas Kluyver
Standardise JS checkpointing API, use it for notebooks
r18652 };
$.ajax(url, settings);
KesterTong
Style and bug fixes
r18620 };
KesterTong
Moves list_notebooks to ContentManager
r18636 /**
* File management functions
*/
/**
* List notebooks and directories at a given path
*
* On success, load_callback is called with an array of dictionaries
* representing individual files or directories. Each dictionary has
* the keys:
* type: "notebook" or "directory"
* name: the name of the file or directory
* created: created date
* last_modified: last modified dat
* path: the path
* @method list_notebooks
* @param {String} path The path to list notebooks in
* @param {Function} load_callback called with list of notebooks on success
* @param {Function} error_callback called with ajax results on error
*/
Thomas Kluyver
Make contents JS API consistent
r18653 Contents.prototype.list_contents = function(path, options) {
KesterTong
Moves list_notebooks to ContentManager
r18636 var settings = {
processData : false,
cache : false,
type : "GET",
dataType : "json",
Thomas Kluyver
Make contents JS API consistent
r18653 success : options.success_callback,
error : options.error_callback || function() {}
KesterTong
Moves list_notebooks to ContentManager
r18636 };
Thomas Kluyver
Add Contents.api_url convenience function
r18650 $.ajax(this.api_url(path), settings);
Thomas Kluyver
Add missing semicolon
r18647 };
KesterTong
Moves list_notebooks to ContentManager
r18636
Jeff Hemmelgarn
Move contentmanager to contents
r18643 IPython.Contents = Contents;
jhemmelg
Initial interface for javascript contentmanagers...
r18618
Jeff Hemmelgarn
Move contentmanager to contents
r18643 return {'Contents': Contents};
jhemmelg
Initial interface for javascript contentmanagers...
r18618 });