From 1d6cc35c03669ea67d9e9ee9ca0ff62401d1b157 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka Date: Tue, 7 Mar 2017 21:30:00 +0100 Subject: WebUI: Possibility to choose object when API call returns list of objects In case that API call returns array of objects which contains data, using 'object_index' attribute in adapter specification we can set which object should be used. It is possible to choose only one object specified by its index in array. Part of: https://pagure.io/freeipa/issue/6601 Reviewed-By: Petr Vobornik --- install/ui/src/freeipa/field.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'install') diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js index 3c027bc43..ea548c033 100644 --- a/install/ui/src/freeipa/field.js +++ b/install/ui/src/freeipa/field.js @@ -818,6 +818,15 @@ field.Adapter = declare(null, { */ result_index: 0, + /** + * When result of API call is an array of object this object index + * allows to specify exact object in array according to its position. + * Default value is null which means do not use object_index. + * + * @type {Number|null} + */ + object_index: null, + /** * Name of the record which we want to extract from the result. * Used in dnslocations. @@ -849,6 +858,10 @@ field.Adapter = declare(null, { else if (dr.results) { var result = dr.results[this.result_index]; if (result) record = result[this.result_name]; + var res_type = typeof record; + var obj_in_type = typeof this.object_index; + if (res_type === 'object' && obj_in_type === 'number') + record = record[this.object_index]; } } return record; -- cgit