From: Coleman Watts Date: Sun, 6 Jul 2014 20:17:30 +0000 (+0100) Subject: CRM-14949 - Move more stuff into dynamic js tpl X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4e56e743a9691a785eaf97590e68388c671e0a49;p=civicrm-core.git CRM-14949 - Move more stuff into dynamic js tpl --- diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 66332cf1af..2ccf22d734 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -467,22 +467,18 @@ class CRM_Core_Resources { } } + // Dynamic localization script + $this->addScriptUrl(CRM_Utils_System::url('civicrm/ajax/localizationjs/' . $config->lcMessages), $jsWeight++, $region); + // Add global settings - $settings = array( - 'userFramework' => $config->userFramework, - 'resourceBase' => $config->resourceBase, - 'lcMessages' => $config->lcMessages, + $settings = array('config' => array( 'ajaxPopupsEnabled' => $this->ajaxPopupsEnabled, - ); - $this->addSetting(array('config' => $settings)); - - // Contact create profiles with localized names - if (CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts')) { - $this->addSetting(array('profile' => array('contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks()))); + )); + // Disable profile creation if user lacks permission + if (!CRM_Core_Permission::check('edit all contacts') && !CRM_Core_Permission::check('add contacts')) { + $settings['profileCreate'] = FALSE; } - - // Add dynamic localization script - $this->addScriptUrl(CRM_Utils_System::url('civicrm/ajax/localizationjs/' . $config->lcMessages), $jsWeight++, $region); + $this->addSetting($settings); // Give control of jQuery and _ back to the CMS - this loads last $this->addScriptFile('civicrm', 'js/noconflict.js', 9999, $region, FALSE); @@ -559,8 +555,9 @@ class CRM_Core_Resources { 'moneyFormat' => json_encode(CRM_Utils_Money::format(1234.56)), 'contactSearch' => json_encode($config->includeEmailInName ? ts('Start typing a name or email...') : ts('Start typing a name...')), 'otherSearch' => json_encode(ts('Enter search term...')), + 'contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks(), ); - CRM_Core_Page_AJAX::returnDynamicJS('CRM/Form/validate.js.tpl', $vars); + CRM_Core_Page_AJAX::returnDynamicJS('CRM/common/localization.js.tpl', $vars); } /** diff --git a/js/Common.js b/js/Common.js index 3f8beae757..028875f9f2 100644 --- a/js/Common.js +++ b/js/Common.js @@ -375,14 +375,14 @@ CRM.strings = CRM.strings || {}; if ($el.data('create-links') && entity.toLowerCase() === 'contact') { selectParams.formatInputTooShort = function() { var txt = $el.data('select-params').formatInputTooShort || $.fn.select2.defaults.formatInputTooShort.call(this); - if ($el.data('create-links')) { + if ($el.data('create-links') && CRM.profileCreate) { txt += ' ' + ts('or') + '
' + formatSelect2CreateLinks($el); } return txt; }; selectParams.formatNoMatches = function() { var txt = $el.data('select-params').formatNoMatches || $.fn.select2.defaults.formatNoMatches; - return txt + '
' + formatSelect2CreateLinks($el); + return txt + (CRM.profileCreate ? ('
' + formatSelect2CreateLinks($el)) : ''); }; $el.on('select2-open.crmEntity', function() { var $el = $(this); @@ -464,7 +464,7 @@ CRM.strings = CRM.strings || {}; api = $el.data('api-params') || {}, type = api.params ? api.params.contact_type : null; if (createLinks === true) { - createLinks = type ? _.where(CRM.profile.contactCreate, {type: type}) : CRM.profile.contactCreate; + createLinks = type ? _.where(CRM.profileCreate, {type: type}) : CRM.profileCreate; } var markup = ''; _.each(createLinks, function(link) { diff --git a/templates/CRM/Form/validate.tpl b/templates/CRM/Form/validate.tpl index 42204c30b0..824106828d 100644 --- a/templates/CRM/Form/validate.tpl +++ b/templates/CRM/Form/validate.tpl @@ -27,7 +27,6 @@ {* Extra params and functions may be added to the CRM.validate object before this template is loaded *} {if !$crm_form_validate_included and $smarty.get.snippet neq 'json' and $form and $form.formName} {assign var=crm_form_validate_included value=1} - {literal}