CRM-14949 - Move more stuff into dynamic js tpl
authorColeman Watts <coleman@civicrm.org>
Sun, 6 Jul 2014 20:17:30 +0000 (21:17 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 9 Jul 2014 14:08:35 +0000 (15:08 +0100)
CRM/Core/Resources.php
js/Common.js
templates/CRM/Form/validate.tpl
templates/CRM/common/localization.js.tpl [moved from templates/CRM/Form/validate.js.tpl with 91% similarity]

index 66332cf1afe7765036598daee434842e4fb79e48..2ccf22d7349e5b9a5e03dc86d76dab30b7795cad 100644 (file)
@@ -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);
   }
 
   /**
index 3f8beae7571e7a814d167f9160c0706be98ecbb2..028875f9f224645b4690b26a11fe2eaf69e46e09 100644 (file)
@@ -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') + '<br />' + formatSelect2CreateLinks($el);
           }
           return txt;
         };
         selectParams.formatNoMatches = function() {
           var txt = $el.data('select-params').formatNoMatches || $.fn.select2.defaults.formatNoMatches;
-          return txt + '<br />' + formatSelect2CreateLinks($el);
+          return txt + (CRM.profileCreate ? ('<br />' + 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) {
index 42204c30b063edc1c5225190724f5b6b3cdf2237..824106828d2d585b2075ed50f610dc9563b30f5f 100644 (file)
@@ -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}
   <script type="text/javascript">
     CRM.$(function($) {
similarity index 91%
rename from templates/CRM/Form/validate.js.tpl
rename to templates/CRM/common/localization.js.tpl
index 0fde36f85f3b5c1221b91381808f5ce6adba8135..4f5982cc190cf828a469f4eb324e3aa55b00cff7 100644 (file)
  +--------------------------------------------------------------------+
 *}// http://civicrm.org/licensing
 // <script> Generated {$timeGenerated}
+{* This file should only contain strings and settings which rarely change *}
 (function($) {ldelim}
+  // Config settings
+  CRM.config.userFramework = {$config->userFramework|@json_encode};
+  CRM.config.resourceBase = {$config->resourceBase|@json_encode};
+  CRM.config.lcMessages = {$config->lcMessages|@json_encode};
+
+  // Contact create links
+  if (CRM.profileCreate !== false) {ldelim}
+    CRM.profileCreate = {$contactCreate|@json_encode};
+  {rdelim}
+  
   // Initialize CRM.url and CRM.formatMoney
   CRM.url('init', '{crmURL p="civicrm/example" q="placeholder" h=0}');
   CRM.formatMoney('init', {$moneyFormat});