projects
/
civicrm-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
CRM-16142 - Variable scope fixes
[civicrm-core.git]
/
js
/
angular-crm-util.js
diff --git
a/js/angular-crm-util.js
b/js/angular-crm-util.js
index 2349fcff97c472730b277d5b6fe75d44ca104b1f..3a1a8fd54ff177827d12d023028c6dbe7c0deb58 100644
(file)
--- 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) {
// 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 = {
var cache = {}; // cache[entityName+'::'+action][fieldName].title
var deferreds = {}; // deferreds[cacheKey].push($q.defer())
var crmMetadata = {
@@
-87,13
+97,18
@@
deferreds[cacheKey].push(deferred);
if (needFetch) {
deferreds[cacheKey].push(deferred);
if (needFetch) {
- crmApi(entity, 'getfields', {action: action, options: {get_options: 'all'}})
+ crmApi(entity, 'getfields', {action: action,
sequential: 1,
options: {get_options: 'all'}})
.then(
// on success:
function(fields) {
.then(
// on success:
function(fields) {
- cache[cacheKey] = fields.values;
+ 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) {
angular.forEach(deferreds[cacheKey], function(dfr) {
- dfr.resolve(
fields.values
);
+ dfr.resolve(
cache[cacheKey]
);
});
delete deferreds[cacheKey];
},
});
delete deferreds[cacheKey];
},