X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2FCommon.js;h=ce8546c5708edf2e4cf03397d9332f54a00665ee;hb=0a1c80afc6e291e9b44581dfc0e40e1b1df09adc;hp=01bc7572bafafb6584569009a525cefb8c61c8a1;hpb=09bb2ac426187ff428dcca34f768494952d4c1e4;p=civicrm-core.git diff --git a/js/Common.js b/js/Common.js index 01bc7572ba..ce8546c570 100644 --- a/js/Common.js +++ b/js/Common.js @@ -238,9 +238,13 @@ if (!CRM.vars) CRM.vars = {}; }; var scriptsLoaded = {}; - CRM.loadScript = function(url) { + CRM.loadScript = function(url, appendCacheCode) { if (!scriptsLoaded[url]) { - var script = document.createElement('script'); + var script = document.createElement('script'), + src = url; + if (appendCacheCode !== false) { + src += (_.includes(url, '?') ? '&r=' : '?r=') + CRM.config.resourceCacheCode; + } scriptsLoaded[url] = $.Deferred(); script.onload = function () { // Give the script time to execute @@ -256,7 +260,7 @@ if (!CRM.vars) CRM.vars = {}; CRM.CMSjQuery = window.jQuery; window.jQuery = CRM.$; } - script.src = url + (_.includes(url, '?') ? '&r=' : '?r=') + CRM.config.resourceCacheCode; + script.src = src; document.getElementsByTagName("head")[0].appendChild(script); } return scriptsLoaded[url]; @@ -466,7 +470,7 @@ if (!CRM.vars) CRM.vars = {}; var entity = $(this).data('api-entity') || ''; $(this) .off('.crmEntity') - .removeClass('crm-form-entityref crm-' + entity.toLowerCase() + '-ref') + .removeClass('crm-form-entityref crm-' + _.kebabCase(entity) + '-ref') .crmSelect2('destroy'); }); } @@ -475,13 +479,17 @@ if (!CRM.vars) CRM.vars = {}; return $(this).each(function() { var $el = $(this).off('.crmEntity'), - entity = options.entity || $el.data('api-entity') || 'contact', + entity = options.entity || $el.data('api-entity') || 'Contact', selectParams = {}; + // Legacy: fix entity name if passed in as snake case + if (entity.charAt(0).toUpperCase() !== entity.charAt(0)) { + entity = _.capitalize(_.camelCase(entity)); + } $el.data('api-entity', entity); $el.data('select-params', $.extend({}, $el.data('select-params') || {}, options.select)); $el.data('api-params', $.extend(true, {}, $el.data('api-params') || {}, options.api)); $el.data('create-links', options.create || $el.data('create-links')); - $el.addClass('crm-form-entityref crm-' + entity.toLowerCase() + '-ref'); + $el.addClass('crm-form-entityref crm-' + _.kebabCase(entity) + '-ref'); var settings = { // Use select2 ajax helper instead of CRM.api3 because it provides more value ajax: { @@ -527,7 +535,7 @@ if (!CRM.vars) CRM.vars = {}; } }; // Create new items inline - works for tags - if ($el.data('create-links') && entity.toLowerCase() === 'tag') { + if ($el.data('create-links') && entity === 'Tag') { selectParams.createSearchChoice = function(term, data) { if (!_.findKey(data, {label: term})) { return {id: "0", term: term, label: term + ' (' + ts('new tag') + ')'}; @@ -685,12 +693,13 @@ if (!CRM.vars) CRM.vars = {}; var createLinks = $el.data('create-links'), params = getEntityRefApiParams($el).params, + entity = $el.data('api-entity'), markup = '