Commit | Line | Data |
---|---|---|
493f83d4 CW |
1 | (function(angular, $, _) { |
2 | "use strict"; | |
3 | ||
4 | // Declare module | |
5 | angular.module('crmSearchKit', CRM.angRequires('crmSearchKit')) | |
6 | ||
7 | // Reformat an array of objects for compatibility with select2 | |
8 | // Todo this probably belongs in core | |
9 | .factory('formatForSelect2', function() { | |
10 | return function(input, key, label, extra) { | |
11 | return _.transform(input, function(result, item) { | |
12 | var formatted = {id: item[key], text: item[label]}; | |
13 | if (extra) { | |
14 | _.merge(formatted, _.pick(item, extra)); | |
15 | } | |
16 | result.push(formatted); | |
17 | }, []); | |
18 | }; | |
19 | }); | |
20 | ||
21 | })(angular, CRM.$, CRM._); |