}
}
+ // 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);
'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);
}
/**
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);
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) {
{* 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($) {
+--------------------------------------------------------------------+
*}// 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});