Merge pull request #19307 from eileenmcnaughton/534
[civicrm-core.git] / ext / search / ang / crmSearchActions.module.js
index 912d2e54ff26c5e32dab9618ebc2e098174cad8d..341e341287cf302abcbf70266338f8e89fef82ff 100644 (file)
@@ -2,6 +2,20 @@
   "use strict";
 
   // Declare module
-  angular.module('crmSearchActions', CRM.angRequires('crmSearchActions'));
+  angular.module('crmSearchActions', CRM.angRequires('crmSearchActions'))
+
+    // Reformat an array of objects for compatibility with select2
+    // Todo this probably belongs in core
+    .factory('formatForSelect2', function() {
+      return function(input, key, label, extra) {
+        return _.transform(input, function(result, item) {
+          var formatted = {id: item[key], text: item[label]};
+          if (extra) {
+            _.merge(formatted, _.pick(item, extra));
+          }
+          result.push(formatted);
+        }, []);
+      };
+    });
 
 })(angular, CRM.$, CRM._);