]> git.agnieray.net Git - galette.git/commitdiff
Enable HTML editor on dynamic fields information
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 19 Feb 2024 07:21:10 +0000 (08:21 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 19 Feb 2024 09:22:55 +0000 (10:22 +0100)
Factorize summernote activation

fixes #1774

galette/lib/Galette/Controllers/Crud/DynamicFieldsController.php
galette/templates/default/elements/js/modal_action.js.twig
galette/templates/default/elements/scripts.html.twig
galette/templates/default/pages/configuration_dynamic_field_form.html.twig
galette/templates/default/pages/configuration_dynamic_fields.html.twig

index 6814648387f8c25be5d5c7d5cba195080c6cbeff..e275bec0d2d218e5f8f573c54e4bbe8fcc548569 100644 (file)
@@ -235,7 +235,10 @@ class DynamicFieldsController extends CrudController
             'fields_list'       => $fields_list,
             'form_name'         => $form_name,
             'form_title'        => DynamicField::getFormTitle($form_name),
-            'page_title'        => _T("Dynamic fields configuration")
+            'page_title'        => _T("Dynamic fields configuration"),
+            'html_editor'       => true,
+            'html_editor_active' => $this->preferences->pref_editor_enabled
+
         ];
 
         $tpl = 'pages/configuration_dynamic_fields.html.twig';
@@ -429,7 +432,9 @@ class DynamicFieldsController extends CrudController
             'form_name'     => $form_name,
             'perm_names'    => DynamicField::getPermsNames(),
             'mode'          => (($request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest') ? 'ajax' : ''),
-            'df'            => $df
+            'df'            => $df,
+            'html_editor'   => true,
+            'html_editor_active' => $this->preferences->pref_editor_enabled
         ];
 
         // display page
index 97ef6e8e2eb8fd0b9dcd452e4403f355de2f2bea..ceaa0411182a4f36f9b83ae8bb18c2559658acd2 100644 (file)
@@ -52,6 +52,7 @@
  * - modal_approve_text: modal's approve button's text.
  * - modal_approve_icon: modal's approve button's icon.
  * - modal_cancel_text: modal's cancel button's text.
+ * - modal_action_onshow: additionnal code to execute on modal's onShow event.
  *
  * @see loader.js.twig
  * @see modal.js.twig
                     modal_cancel_text: modal_cancel_text,
                 } %}
             },
+            {# FIXME: variables modal.js.twig know and that are not explicitely redefined are autmatically passed! #}
             error: function() {
                 {% include "elements/js/modal.js.twig" with {
                     modal_title_twig: _T("An error occurred :(")|e("js"),
             inline: false,
             addTouchEvents: false,
         });
+{% if modal_action_onshow is defined %}
+        {{ modal_action_onshow|raw }}
+{% endif %}
     }
index 89c0ef72c98a477cd9574db2d87f48363a7646b5..ae17f43a83094d43dcf9fb078f4cfe6a1d0e5041 100644 (file)
         <script type="text/javascript" src="{{ base_path() }}/assets/js/formatting.js"></script>
         <script type="text/javascript" src="{{ base_path() }}/assets/js/summernote.min.js"></script>
         <script type="text/javascript" src="{{ base_path() }}/assets/js/lang/summernote-{{ i18n.getID()|replace({'_': '-'}) }}.min.js"></script>
-        <script language="javascript">
-            function activateMailingEditor() {
-                if(!$('#mailing_html').attr('checked')){
-                    $('#mailing_html').attr('checked', true);
-                }
-
-                $('input#html_editor_active').attr('value', '1');
-                $('#activate_editor').remove();
-                $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:deactivateMailingEditor();" id="deactivate_editor">{{ _T("Deactivate HTML editor") }}</a>');
-
-                $('#mailing_corps').summernote({
+        <script type="text/javascript">
+            function activateHtmlEditor(elt) {
+                elt.summernote({
                     lang: '{{ i18n.getID()|replace({'_': '-'}) }}',
                     disableDragAndDrop: true,
                     height: 240,
                         }
                     }
                 });
-                $('#mailing_corps').summernote('focus');
+                elt.summernote('focus');
+            }
+
+            function deactivateHtmlEditor(elt) {
+                elt.summernote('destroy');
+            }
+
+            function activateMailingEditor() {
+                if(!$('#mailing_html').attr('checked')){
+                    $('#mailing_html').attr('checked', true);
+                }
+
+                $('input#html_editor_active').attr('value', '1');
+                $('#activate_editor').remove();
+                $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:deactivateMailingEditor();" id="deactivate_editor">{{ _T("Deactivate HTML editor") }}</a>');
+
+                activateHtmlEditor($('#mailing_corps'));
             }
             function deactivateMailingEditor() {
-                $('#mailing_corps').summernote('destroy');
+                deactivateHtmlEditor($('#mailing_corps'));
                 $('#deactivate_editor').remove();
                 $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:activateMailingEditor();" id="activate_editor">{{ _T("Activate HTML editor") }}</a>');
             }
index fc0eeec77f1105b0751226619744ab4d9e48b2fb..0f3f53acf38778722e20a1f52175f810a79a9012 100644 (file)
 
 {% block javascripts %}
     <script>
-        $('#field_information').summernote({
-            lang: '{{ i18n.getID()|replace({'_': '-'}) }}',
-            height: 240,
-            toolbar: [
-                ['style', ['style']],
-                ['font', ['bold', 'italic', 'strikethrough', 'clear']],
-                ['para', ['ul', 'ol', 'paragraph']],
-                ['insert', ['link', 'picture']],
-                ['view', ['codeview', 'help']]
-            ],
-            styleTags: [
-                'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
-            ]
+        $(function() {
+            activateHtmlEditor($('#field_information'));
         });
-        $('#field_information').summernote('focus');
-
     </script>
 {% endblock %}
index bcc2b9aef8de3a151e7f377448a022544d74d51a..8eda4007e8e1c049faad60d69c5ec28548dda4c7 100644 (file)
@@ -96,7 +96,8 @@
                     modal_title_twig: _T("Edit field")|e("js"),
                     modal_class: "tiny",
                     modal_content_class: "scrolling",
-                    modal_onapprove: modal_onapprove
+                    modal_onapprove: modal_onapprove,
+                    modal_action_onshow: "activateHtmlEditor($('#field_information'));"
                 } %}
             }
             _editDynField();