enhance EntityRef to show create new link when contact listing is filtered by multipl...
authorKurund Jalmi <kurund.jalmi@gmail.com>
Fri, 25 Feb 2022 11:48:01 +0000 (11:48 +0000)
committerGitHub <noreply@github.com>
Fri, 25 Feb 2022 11:48:01 +0000 (11:48 +0000)
js/Common.js

index fb9d0c3d8af55d7cfb770590f55daa21d661bcfd..07eb96b84ad1b56746ef52260818c29eadaddff7 100644 (file)
@@ -809,7 +809,20 @@ if (!CRM.vars) CRM.vars = {};
       return '';
     }
     if (createLinks === true) {
-      createLinks = params.contact_type ? _.where(CRM.config.entityRef.links[entity], {type: params.contact_type}) : CRM.config.entityRef.links[entity];
+      if (!params.contact_type) {
+        createLinks = CRM.config.entityRef.links[entity];
+      }
+      else if (typeof params.contact_type === 'string') {
+        createLinks = _.where(CRM.config.entityRef.links[entity], {type: params.contact_type});
+      } else {
+        // lets assume it's an array with filters such as IN etc
+        createLinks = [];
+        _.each(params.contact_type, function(types) {
+          _.each(types, function(type) {
+            createLinks.push(_.findWhere(CRM.config.entityRef.links[entity], {type: type}));
+          });
+        });
+      }
     }
     _.each(createLinks, function(link) {
       markup += ' <a class="crm-add-entity crm-hover-button" href="' + link.url + '">' +