Change fromAPI logic

This commit is contained in:
Ludovic Stephan 2017-04-05 09:13:00 -03:00
parent 840010b63f
commit 1761c5f1bd
2 changed files with 6 additions and 15 deletions

View file

@ -754,24 +754,14 @@ class APIModelForest extends ModelForest {
* Fills the instance with distant data. It sends a GET HTTP request to * Fills the instance with distant data. It sends a GET HTTP request to
* {@link Models.APIModelForest#url_model}. * {@link Models.APIModelForest#url_model}.
* @param {object} [api_options] Additional data appended to the request. * @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) { fromAPI(api_options) {
var that = this; api_options = api_options || {};
api_options = api_options || {}
on_success = on_success || $.noop;
on_error = on_error || $.noop;
api_options['format'] = 'json'; api_options['format'] = 'json';
$.getJSON(this.constructor.url_model, api_options) return $.getJSON(this.constructor.url_model, api_options)
.done(function(json, textStatus, jqXHR) { .done( (json) => this.from(json) );
that.from(json);
on_success(json, textStatus, jqXHR);
})
.fail(on_error);
} }
} }

View file

@ -451,7 +451,8 @@ class ArticleManager {
reset_data() { reset_data() {
this._$container.html(''); this._$container.html('');
this.list.clear(); this.list.clear();
this.list.fromAPI({}, this.display_list.bind(this), $.noop) ; this.list.fromAPI()
.done( () => this.display_list() );
} }
get_article(id) { get_article(id) {