Use promises for GET requests

This commit is contained in:
Thomas Kluyver 2014-11-13 11:42:52 -08:00
parent 9b2dac3fc1
commit 11cfcc40d4
3 changed files with 11 additions and 15 deletions

View File

@ -2103,11 +2103,10 @@ define([
this.notebook_path = notebook_path;
this.notebook_name = utils.url_path_split(this.notebook_path)[1];
this.events.trigger('notebook_loading.Notebook');
this.contents.get(notebook_path, {
type: 'notebook',
success: $.proxy(this.load_notebook_success, this),
error: $.proxy(this.load_notebook_error, this)
});
this.contents.get(notebook_path, {type: 'notebook'}).then(
$.proxy(this.load_notebook_success, this),
$.proxy(this.load_notebook_error, this)
);
};
/**

View File

@ -83,14 +83,12 @@ define([
cache : false,
type : "GET",
dataType : "json",
success : options.success,
error : this.create_basic_error_handler(options.error)
};
var url = this.api_url(path);
params = {};
if (options.type) { params.type = options.type; }
if (options.format) { params.format = options.format; }
$.ajax(url + '?' + $.param(params), settings);
return utils.promising_ajax(url + '?' + $.param(params), settings);
};
@ -246,9 +244,8 @@ define([
* @param {String} path The path to list notebooks in
* @param {Object} options including success and error callbacks
*/
Contents.prototype.list_contents = function(path, options) {
options.type = 'directory';
this.get(path, options);
Contents.prototype.list_contents = function(path) {
return this.get(path, {type: 'directory'});
};

View File

@ -142,12 +142,12 @@ define([
NotebookList.prototype.load_list = function () {
var that = this;
this.contents.list_contents(that.notebook_path, {
success: $.proxy(this.draw_notebook_list, this),
error: function(error) {
this.contents.list_contents(that.notebook_path).then(
$.proxy(this.draw_notebook_list, this),
function(error) {
that.draw_notebook_list({content: []}, "Server error: " + error.message);
}
});
);
};
/**