Fix auto-refresh of CKEditor configurator form
authorColeman Watts <coleman@civicrm.org>
Fri, 3 Jul 2020 02:37:03 +0000 (22:37 -0400)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 19 Aug 2020 06:16:57 +0000 (16:16 +1000)
CRM/Admin/Form/CKEditorConfig.php
js/wysiwyg/admin.ckeditor-configurator.js

index 7a65a9537a618d7f9b02b126e73e58c7276520a6..6de81d37ca4ace08b0a37fed8ce7c73b2d5bb00a 100644 (file)
@@ -48,6 +48,25 @@ class CRM_Admin_Form_CKEditorConfig extends CRM_Core_Form {
   public function preProcess() {
     CRM_Utils_Request::retrieve('preset', 'String', $this, FALSE, 'default', 'GET');
 
+    CRM_Utils_System::appendBreadCrumb([
+      [
+        'url' => CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1'),
+        'title' => ts('Display Preferences'),
+      ],
+    ]);
+
+    // Initial build
+    if (empty($_POST['qfKey'])) {
+      $this->addResources();
+    }
+  }
+
+  /**
+   * Add resources during initial build or rebuild
+   *
+   * @throws CRM_Core_Exception
+   */
+  public function addResources() {
     $settings = $this->getConfigSettings();
 
     CRM_Core_Resources::singleton()
@@ -72,13 +91,6 @@ class CRM_Admin_Form_CKEditorConfig extends CRM_Core_Form {
     $this->assign('skin', CRM_Utils_Array::value('skin', $settings));
     $this->assign('extraPlugins', CRM_Utils_Array::value('extraPlugins', $settings));
     $this->assign('configUrl', $configUrl);
-
-    CRM_Utils_System::appendBreadCrumb([
-      [
-        'url' => CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1'),
-        'title' => ts('Display Preferences'),
-      ],
-    ]);
   }
 
   /**
@@ -91,6 +103,12 @@ class CRM_Admin_Form_CKEditorConfig extends CRM_Core_Form {
         'type' => 'next',
         'name' => ts('Save'),
       ],
+      // Hidden button used to refresh form
+      [
+        'type' => 'submit',
+        'class' => 'hiddenElement',
+        'name' => ts('Save'),
+      ],
       [
         'type' => 'cancel',
         'name' => ts('Cancel'),
@@ -115,8 +133,16 @@ class CRM_Admin_Form_CKEditorConfig extends CRM_Core_Form {
     else {
       if (!empty($_POST[$this->getButtonName('next')])) {
         $this->save($_POST);
+        CRM_Core_Session::setStatus(ts("You may need to clear your browser's cache to see the changes in CiviCRM."), ts('CKEditor Saved'), 'success');
+      }
+      // The "submit" hidden button saves but does not redirect
+      if (!empty($_POST[$this->getButtonName('submit')])) {
+        $this->save($_POST);
+        $this->addResources();
+      }
+      else {
+        CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/ckeditor', ['reset' => 1]));
       }
-      CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/setting/preferences/display', ['reset' => 1]));
     }
   }
 
@@ -157,7 +183,6 @@ class CRM_Admin_Form_CKEditorConfig extends CRM_Core_Form {
       }
     }
     self::saveConfigFile($this->get('preset'), $config);
-    CRM_Core_Session::setStatus(ts("You may need to clear your browser's cache to see the changes in CiviCRM."), ts('CKEditor Saved'), 'success');
   }
 
   /**
index f46c48fce9b0e22a53792ce40a3d1295a7749569..9d87afc0dc20b02d6edf80a7fad86be336bec3d1 100644 (file)
       .on('change', '.config-param', function(e) {
         changedWhileOpen = true;
         if (!selectorOpen) {
-          $('#CKEditorConfig').submit().block();
+          $('#_qf_CKEditorConfig_submit-bottom').click();
+          $('#CKEditorConfig').block();
         }
       })
       .on('change', 'input.crm-config-option-name', changeOptionName)