diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index 2418195d..bfadc4dd 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -185,24 +185,14 @@ class APIModelObject extends ModelObject { * Get data of a distant model instance. It sends a GET HTTP request to * {@link Models.APIModelObject#url_read}. * @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; - + fromAPI(api_options) { api_options = api_options || {}; - on_success = on_success || $.noop; - on_error = on_error || $.noop; api_options['format'] = 'json'; - $.getJSON(this.url_read, api_options) - .done(function (json, textStatus, jqXHR) { - that.from(json); - on_success(json, textStatus, jqXHR); - }) - .fail(on_error); + return $.getJSON(this.url_read, api_options) + .done( (json) => this.from(json) ); } /** @@ -213,9 +203,9 @@ class APIModelObject extends ModelObject { * @param {jQueryAjaxError} [on_error] * @see {@link Models.APIModelObject#fromAPI|fromAPI} */ - get_by_apipk(api_pk, api_options, on_success, on_error) { + get_by_apipk(api_pk, api_options) { this.url_read = this.constructor.url_read_for(api_pk); - this.fromAPI(api_options, on_success, on_error); + return this.fromAPI(api_options); } /** diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 1917c53e..f9aa8e23 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -84,10 +84,9 @@ class AccountManager { trigramme = trigramme || this.selection.get(); if (trigramme.isValidTri()) { - this.account.get_by_apipk(trigramme, {}, - () => this._update_on_success(), - () => this.reset_data() - ); + this.account.get_by_apipk(trigramme) + .done( () => this._update_on_success() ) + .fail( () => this.reset_data() ); } else { this.reset_data(); } @@ -279,9 +278,9 @@ class CheckoutManager { 'last_statement': true, }; - this.checkout.get_by_apipk(id, api_options, - (data) => this._update_on_success(data), - () => this.reset_data()); + this.checkout.get_by_apipk(id, api_options) + .done( (data) => this._update_on_success(data) ) + .fail( () => this.reset_data() ); if (kpsul.account_manager.is_empty()) { kpsul.account_manager.focus();