From d606fff7f77e088ef6d437041b108a6baca8e0ca Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 7 Sep 2014 09:31:22 -0400 Subject: [PATCH] CRM-15233 - Fixes for i18n popups --- CRM/Core/I18n/Form.php | 12 +++++------ CRM/Core/Resources.php | 5 +++++ js/crm.multilingual.js | 23 +++++++++++++++++++++ templates/CRM/Core/I18n/Dialog.tpl | 25 +++------------------- templates/CRM/Core/I18n/Form.tpl | 33 +----------------------------- 5 files changed, 37 insertions(+), 61 deletions(-) create mode 100644 js/crm.multilingual.js diff --git a/CRM/Core/I18n/Form.php b/CRM/Core/I18n/Form.php index a03725abba..bd0abd5859 100644 --- a/CRM/Core/I18n/Form.php +++ b/CRM/Core/I18n/Form.php @@ -35,6 +35,7 @@ class CRM_Core_I18n_Form extends CRM_Core_Form { function buildQuickForm() { $config = CRM_Core_Config::singleton(); + global $tsLocale; $this->_locales = array_keys($config->languageLimit); // get the part of the database we want to edit and validate it @@ -65,17 +66,16 @@ class CRM_Core_I18n_Form extends CRM_Core_Form { $languages = CRM_Core_I18n::languages(TRUE); foreach ($this->_locales as $locale) { - $this->addElement($type, "{$field}_{$locale}", $languages[$locale], array('cols' => 60, 'rows' => 3)); + $this->addElement($type, "{$field}_{$locale}", $languages[$locale], array('class' => 'huge huge12' . ($locale == $tsLocale ? ' default-lang' : ''))); $this->_defaults["{$field}_{$locale}"] = $dao->$locale; } - $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE))); + $this->addDefaultButtons(ts('Save'), 'next', NULL); + + CRM_Utils_System::setTitle(ts('Languages')); - global $tsLocale; - $this->assign('tsLocale', $tsLocale); $this->assign('locales', $this->_locales); $this->assign('field', $field); - $this->assign('context', CRM_Utils_Request::retrieve('context', 'String', $this)); } /** @@ -113,8 +113,6 @@ class CRM_Core_I18n_Form extends CRM_Core_Form { $dao = new CRM_Core_DAO(); $query = CRM_Core_DAO::composeQuery($query, $params, TRUE); $dao->query($query, FALSE); - - CRM_Utils_System::civiExit(); } } diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index e7bcf5046c..5825a8ce74 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -634,6 +634,11 @@ class CRM_Core_Resources { $items[] = "js/jquery/jquery.crmeditable.js"; } + // JS for multilingual installations + if (!empty($config->languageLimit) && count($config->languageLimit) > 1 && CRM_Core_Permission::check('translate CiviCRM')) { + $items[] = "js/crm.multilingual.js"; + } + // Enable administrators to edit option lists in a dialog if (CRM_Core_Permission::check('administer CiviCRM') && $this->ajaxPopupsEnabled) { $items[] = "js/crm.optionEdit.js"; diff --git a/js/crm.multilingual.js b/js/crm.multilingual.js new file mode 100644 index 0000000000..4de9929f0e --- /dev/null +++ b/js/crm.multilingual.js @@ -0,0 +1,23 @@ +// http://civicrm.org/licensing +// JS needed for multilingual installations +CRM.$(function($) { + // This is largely redundant with what the CRM.popup function would do, + // with the difference that this loads unconditionally regardless of ajaxPopupsEnabled setting + $('body').on('click', 'a.crm-multilingual-edit-button', function(e) { + var $el = $(this), + $form = $el.closest('form'), + $field = $('#' + $el.data('field'), $form); + + CRM.loadForm($el.attr('href'), { + dialog: {width: '50%', height: '50%'} + }) + .on('crmFormLoad', function() { + $('.default-lang', this).val($field.val()); + }) + .on('crmFormSubmit', function() { + $field.val($('.default-lang', this).val()); + $el.trigger('crmPopupFormSuccess'); + }); + e.preventDefault(); + }); +}); diff --git a/templates/CRM/Core/I18n/Dialog.tpl b/templates/CRM/Core/I18n/Dialog.tpl index 5519f4531c..1c0fcf3ece 100644 --- a/templates/CRM/Core/I18n/Dialog.tpl +++ b/templates/CRM/Core/I18n/Dialog.tpl @@ -24,26 +24,7 @@ +--------------------------------------------------------------------+ *} {if $config->languageLimit|@count >= 2 and $translatePermission } - - -{literal} - -{/literal} + + + {/if} diff --git a/templates/CRM/Core/I18n/Form.tpl b/templates/CRM/Core/I18n/Form.tpl index 161672e01a..f863f62f08 100644 --- a/templates/CRM/Core/I18n/Form.tpl +++ b/templates/CRM/Core/I18n/Form.tpl @@ -30,36 +30,5 @@
{$form.$elem.label}
{$form.$elem.html}
{/foreach} - {if $context == 'dialog'} - - {else} - {$form.buttons.html} - {/if} -{$form.action} -{literal} - -{/literal} +
{include file="CRM/common/formButtons.tpl" location="bottom"}
-- 2.25.1