From 8a941d14cbb3c6258cee7f842e4a2e738f45324b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 26 Feb 2015 18:08:39 -0700 Subject: [PATCH] crmMetadata - Provide both options and optionsMap --- js/angular-crm-util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/angular-crm-util.js b/js/angular-crm-util.js index 02708afe1b..3a1a8fd54f 100644 --- a/js/angular-crm-util.js +++ b/js/angular-crm-util.js @@ -56,6 +56,16 @@ // console.log('The fields are:', options); // }); angular.module('crmUtil').factory('crmMetadata', function($q, crmApi) { + + // Convert {key:$,value:$} sequence to unordered {$key: $value} map. + function convertOptionsToMap(options) { + var result = {}; + angular.forEach(options, function(o) { + result[o.key] = o.value; + }); + return result; + } + var cache = {}; // cache[entityName+'::'+action][fieldName].title var deferreds = {}; // deferreds[cacheKey].push($q.defer()) var crmMetadata = { @@ -92,6 +102,11 @@ // on success: function(fields) { cache[cacheKey] = _.indexBy(fields.values, 'name'); + angular.forEach(cache[cacheKey],function (field){ + if (field.options) { + field.optionsMap = convertOptionsToMap(field.options); + } + }); angular.forEach(deferreds[cacheKey], function(dfr) { dfr.resolve(cache[cacheKey]); }); -- 2.25.1