From 1761c5f1bdca39de20707b9034369ad867899847 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 5 Apr 2017 09:13:00 -0300 Subject: [PATCH] Change fromAPI logic --- kfet/static/kfet/js/kfet.api.js | 18 ++++-------------- kfet/static/kfet/js/kpsul.js | 3 ++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index ab6cc7ab..9d805fdc 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -754,24 +754,14 @@ class APIModelForest extends ModelForest { * Fills the instance with distant data. It sends a GET HTTP request to * {@link Models.APIModelForest#url_model}. * @param {object} [api_options] Additional data appended to the request. - * @param {jQueryAjaxSuccess} [on_success] A function to be called if the request succeeds. - * @param {jQueryAjaxError} [on_error] A function to be called if the request fails. */ - fromAPI(api_options, on_success, on_error) { - var that = this; - - api_options = api_options || {} - on_success = on_success || $.noop; - on_error = on_error || $.noop; + fromAPI(api_options) { + api_options = api_options || {}; api_options['format'] = 'json'; - $.getJSON(this.constructor.url_model, api_options) - .done(function(json, textStatus, jqXHR) { - that.from(json); - on_success(json, textStatus, jqXHR); - }) - .fail(on_error); + return $.getJSON(this.constructor.url_model, api_options) + .done( (json) => this.from(json) ); } } diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 703b15b2..e6784f7e 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -451,7 +451,8 @@ class ArticleManager { reset_data() { this._$container.html(''); this.list.clear(); - this.list.fromAPI({}, this.display_list.bind(this), $.noop) ; + this.list.fromAPI() + .done( () => this.display_list() ); } get_article(id) {