CRM-15233 - Fixes for i18n popups
authorColeman Watts <coleman@civicrm.org>
Sun, 7 Sep 2014 13:31:22 +0000 (09:31 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 7 Sep 2014 13:31:22 +0000 (09:31 -0400)
CRM/Core/I18n/Form.php
CRM/Core/Resources.php
js/crm.multilingual.js [new file with mode: 0644]
templates/CRM/Core/I18n/Dialog.tpl
templates/CRM/Core/I18n/Form.tpl

index a03725abba7d9d172784de43289cd2fdb9f628bf..bd0abd5859e669a1f9050890aec7b0a80038dcca 100644 (file)
@@ -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();
   }
 }
 
index e7bcf5046ce6dfd5f9a1dd53d43b464c581cb069..5825a8ce74961ba7ef39070edec6c6525bc00ef3 100644 (file)
@@ -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 (file)
index 0000000..4de9929
--- /dev/null
@@ -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();
+  });
+});
index 5519f4531c2c1b72c79e146f26ef3c5c5569a23b..1c0fcf3ece94f24e3ab338c617322a83f3b1a9de 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {if $config->languageLimit|@count >= 2 and $translatePermission }
-<a href="#" onclick="loadDialog('{crmURL p='civicrm/i18n' q="reset=1&table=$table&field=$field&id=$id&snippet=1&context=dialog" h=0}', '{$field}'); return false;"><img src="{$config->resourceBase}i/langs.png" /></a><div id="locale-dialog_{$field}" style="display:none"></div>
-
-{literal}
-<script type="text/javascript">
-function loadDialog( url, fieldName ) {
- cj.ajax({
-         url: url,
-         success: function( content ) {
-             cj("#locale-dialog_" +fieldName ).show( ).html( content ).dialog({
-                 modal       : true,
-      width       : 290,
-      height      : 290,
-      resizable   : true,
-      beforeclose : function(event, ui) {
-                     cj(this).dialog("destroy");
-                       }
-             });
-         }
-      });
-}
-</script>
-{/literal}
+  <a href="{crmURL p='civicrm/i18n' q="reset=1&table=$table&field=$field&id=$id"}" data-field="{$field}" class="crm-hover-button crm-multilingual-edit-button" title="{ts}Languages{/ts}">
+    <img src="{$config->resourceBase}i/langs.png" style="position:relative; top: 2px;"/>
+  </a>
 {/if}
index 161672e01af57c6df219727323aca3887274a6a5..f863f62f08535c428167f5fd443fb786972a7f01 100644 (file)
       <dt>{$form.$elem.label}</dt><dd>{$form.$elem.html}</dd>
     {/foreach}
   </dl>
-  {if $context == 'dialog'}
-    <input type="submit" value="Save"/>
-  {else}
-    {$form.buttons.html}
-  {/if}
 </fieldset>
-{$form.action}
-{literal}
-<script type="text/javascript">
-var fieldName = "{/literal}{$field}{literal}";
-var tsLocale = "{/literal}{$tsLocale}{literal}";
-var $form = cj('form.{/literal}{$form.formClass}{literal}');
-cj($form).submit(function() {
-      cj(this).ajaxSubmit({
-                            beforeSubmit: function (formData, jqForm, options) {
-                                                    var queryString = cj.param(formData);
-                                                    var postUrl     = cj($form).attr('action');
-                                                    cj.ajax({
-                                                             type   : "POST",
-                                                             url    : postUrl,
-                                                             async  : false,
-                                                             data   : queryString,
-                                                             success: function( response ) {
-                                    cj('#' + fieldName).val( cj('#' + fieldName +'_' + tsLocale ).val() );
-                                                                      cj("#locale-dialog_"+fieldName).dialog("close");
-                                                                     }
-                                                    });
-                                                return false;
-                                            }});
-          return false;
-});
-</script>
-{/literal}
+<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>