From 4047d5fd5be826ccd1e3f9fb734797aa81b56775 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 6 Feb 2025 16:07:40 +0100 Subject: [PATCH] WIP Allow for comment content to be submitted to backend --- .../Controller/ActivityController.php | 1 + .../ChillActivityBundle/Form/ActivityType.php | 22 +++++++------------ .../Resources/views/Activity/new.html.twig | 17 +++++++------- .../public/vuejs/CommentEditor/App.vue | 13 +++++++++-- .../CommentEditor/component/CommentEditor.vue | 9 +++++++- .../public/vuejs/CommentEditor/index.js | 6 +++-- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index f248c6559..9c9c9128d 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -447,6 +447,7 @@ final class ActivityController extends AbstractController } if (\array_key_exists('comment', $activityData) && $activityType->getCommentVisible() > 0) { + dump($activityData['comment']); $comment = new CommentEmbeddable(); $comment->setComment($activityData['comment']); $comment->setUserId($this->security->getUser()->getId()); diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index ae1be5ded..6eb74e4fa 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -20,9 +20,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\ChillDateType; -use Chill\MainBundle\Form\Type\CommentType; use Chill\MainBundle\Form\Type\PickUserDynamicType; -use Chill\MainBundle\Form\Type\PrivateCommentType; use Chill\MainBundle\Form\Type\ScopePickerType; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Templating\TranslatableStringHelper; @@ -207,21 +205,17 @@ class ActivityType extends AbstractType ]); } -/* if ($activityType->isVisible('comment')) { - $builder->add('comment', CommentType::class, [ -// 'disable_editor' => true, - 'label' => empty($activityType->getLabel('comment')) - ? 'activity.comment' : $activityType->getLabel('comment'), - 'required' => $activityType->isRequired('comment'), + if ($activityType->isVisible('comment')) { + $builder->add('comment', HiddenType::class, [ + 'data' => '', ]); - }*/ + } -/* if ($activityType->isVisible('privateComment')) { - $builder->add('privateComment', PrivateCommentType::class, [ - 'label' => '' === $activityType->getLabel('privateComment') ? 'private comment' : $activityType->getPrivateCommentLabel(), - 'required' => false, + if ($activityType->isVisible('privateComment')) { + $builder->add('privateComment', HiddenType::class, [ + 'data' => '', ]); - }*/ + } if ($activityType->isVisible('persons')) { $builder->add('persons', HiddenType::class); diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig index 8117ec0ce..52c3da56d 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig @@ -80,22 +80,23 @@ {{ form_row(form.travelTime) }} {% endif %} -{#{%- if form.comment is defined -%}#} -{# {{ form_row(form.comment) }}#} -{#{% endif %}#} +{%- if form.comment is defined -%} + {{ form_row(form.comment) }} +{% endif %}
-
+
-
+
-{#{%- if form.privateComment is defined -%}#} -{# {{ form_row(form.privateComment) }}#} -{#{% endif %}#} + +{%- if form.privateComment is defined -%} + {{ form_row(form.privateComment) }} +{% endif %} {%- if form.attendee is defined -%} {{ form_row(form.attendee) }} diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue index dfec5af1b..4a42427d8 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/App.vue @@ -1,7 +1,7 @@ @@ -15,14 +15,23 @@ export default defineComponent({ components: { CommentEditor }, setup() { const globalState = inject('globalState'); + const fieldName = inject('fieldName') const toggleEditorMode = () => { globalState.isSimple = !globalState.isSimple; localStorage.setItem('editorMode', globalState.isSimple ? 'simple' : 'rich'); }; + const handleChange = (newContent) => { + const hiddenField = document.querySelector(`input[name="${fieldName}"]`); + if (hiddenField) { + hiddenField.value = newContent || ''; + } + }; + return { globalState, - toggleEditorMode + toggleEditorMode, + handleChange }; } }); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue index 9e6b3400f..427883eb4 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/component/CommentEditor.vue @@ -7,6 +7,7 @@ :config="editorConfig" v-model="content" tag-name="textarea" + @input="emitChange" />
@@ -14,6 +15,7 @@ v-model="content" name="content" class="form-control" + @input="emitChange" >
{{ isSimple ? $t("mode.rich") : $t("mode.simple") }} @@ -45,12 +47,17 @@ export default defineComponent({ emit("toggle"); }; + const emitChange = () => { + emit("change", content.value); + }; + return { isSimple, content, classicEditor, editorConfig, - toggleSimpleEditor + toggleSimpleEditor, + emitChange }; } }); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js index 033d3cd41..f543a27fb 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/CommentEditor/index.js @@ -21,9 +21,11 @@ commentWidgets.forEach((commentContainer) => { template: `` }); - // Pass the global state to each app instance + const fieldName = commentContainer.dataset.fieldname; + app.use(i18n) - .provide('globalState', globalState) // Provide global state to components + .provide('globalState', globalState) + .provide( 'fieldName', fieldName) .component("app", App) .mount(commentContainer); });