From e7a55ef30b252a616f50c58f99a538e9b090037c Mon Sep 17 00:00:00 2001 From: Pavel Vomacka Date: Fri, 22 Apr 2016 10:45:49 +0200 Subject: Add Object adapter Object adapter changes data to more useful format. Single value is reachable as single value, property with more values is transformed to array. https://fedorahosted.org/freeipa/ticket/5381 Reviewed-By: Petr Vobornik --- install/ui/src/freeipa/field.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js index 12ef7f455..3f7e1d1b4 100644 --- a/install/ui/src/freeipa/field.js +++ b/install/ui/src/freeipa/field.js @@ -1266,6 +1266,45 @@ field.SshKeysAdapter = declare([field.Adapter], { } }); + +/** + * ObjectAdapter is basic adapter which converts object to more usable format. + * All properties which have only one value are tranformed this way: + * property1: {"__base64__": "value1"} => property1: "value1", + * property2: {"value2"} => property2: "value2", + * Works for __base64__ as well as for __datetime__ and __dns_name__ + * + * In case that the property has more values, then they are returned as array. + * + * @class + * @extends field.Adapter + */ +field.ObjectAdapter = declare([field.Adapter], { + + normalize_object: function(obj) { + for (var property in obj) { + if (obj.hasOwnProperty(property)) { + obj[property] = rpc.extract_objects([obj[property]]); + if (obj[property].length == 1) { + obj[property] = obj[property][0]; + } + } + } + }, + + load: function(data) { + + var record = this.get_record(data); + + for (var i=0; i