[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Tracker item editing with comment: Save permanently until the comment is...

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69a99e7a3a0fd_3b1887d8916eb@gitlab-sidekiq-low-urgency-cpu-bound-v2-76fc67c497-ssxv5.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
4dd9be4c by Merci Jacob at 2026-03-05T15:00:36+00:00
[ENH] Tracker item editing with comment: Save permanently until the comment is ready, and allow going back to edit changes before saving
---
* add client interactions between tracker item and comment form & link up the comment action_post to tracker controller

* WIP: show comment form inline with tracker edit form

* [FIX] 'Save and comment' button in modal

* Revert "3 old commits in favor of a new implementation"

* cleanup: remove unecessary controller method

* Implement the "back to edit" button, allowing users to make changes to the modifications

- Ensure that dirtyCheck isn't mistakenly triggered when switching between item edit form -> comment form -> item edit form -> comment form -> save
- Ensure that the page is still refreshed on a newly posted comment but not when redirecting back to the item edit form
- Ensure that the updated form state is preserved when going from comment form -> back on the item edit form

* Tracker item editing with comment: Save permanently until the comment is ready and allow going back to edit changes before saving

See merge request tikiwiki/tiki!9309

- - - - -


5 changed files:

- lib/core/Services/Tracker/Controller.php
- lib/jquery_tiki/tiki-jquery.js
- templates/comment/post.tpl
- + templates/comment/post_form_content.tpl
- templates/tracker/update_item.tpl


Changes:

=====================================
lib/core/Services/Tracker/Controller.php
=====================================
@@ -1405,22 +1405,24 @@ class Services_Tracker_Controller
                     $redirect = smarty_modifier_sefurl($itemId, 'trackeritem');
                 }
 
-                if ($input->saveAndComment->int()) {
+                if ($input->addComment->bool()) {
+                    $comment = new Services_Comment_Controller();
+
                     $version = TikiLib::lib('trk')->last_log_version($itemId);
 
-                    return [
-                        'FORWARD' => [
-                            'controller' => 'comment',
-                            'action' => 'post',
-                            'type' => 'trackeritem',
-                            'objectId' => $itemId,
-                            'parentId' => 0,
-                            'version' => $version,
-                            'return_url' => $redirect,
-                            'title' => tr('Comment for edit #%0', $version),
-                        ],
-                    ];
+                    $comment->action_post(new JitFilter([
+                        'post' => 1,
+                        'anonymous_name' => $input->comment_anonymous_name->text(),
+                        'comment' => $input->comment->text(),
+                        'objectId' => $itemId,
+                        'type' => 'trackeritem',
+                        'title' => tr('Comment for edit #%0', $version),
+                        'data' => $input->data->wikicontent(),
+                        'return_url' => $input->redirect->none(),
+                        'version' => $version,
+                    ]));
                 }
+
                 //return to page
                 if ($skipRedirect === 1 || ! $redirect) {
                     // Return item data and refresh info
@@ -1528,6 +1530,7 @@ class Services_Tracker_Controller
             'save_return' => $input->save_return->alpha() ?? 'n',
             'can_remove' => $itemObject->canRemove(),
             'skipRefresh' => $input->skipRefresh->bool(),
+            'MAX_COMMENT_DATA_LENGTH' => TikiLib::lib('comments')::MAX_COMMENT_DATA_LENGTH,
         ];
     }
 


=====================================
lib/jquery_tiki/tiki-jquery.js
=====================================
@@ -3282,6 +3282,7 @@ $(document).on('tiki.modal.redraw', '.modal.fade', function () {
     // On Modal show, find all buttons part of a .submit block and create
     // proxies of them in the modal footer
     $('.modal-footer .auto-btn', modal).remove();
+    $('.modal-footer', modal).find('*').not('[data-bs-dismiss], .cleanable-false').remove();
     $('div.submit .btn', modal).each(function () {
         var $submit = $(this);
         if ($submit.hasClass('dropdown-toggle') && $submit.parent().hasClass('dropdown')) {
@@ -3335,6 +3336,7 @@ $(document).on('tiki.modal.redraw', '.modal.fade', function () {
                     }
                 });
         }
+
         $('.modal-footer', modal).append($button);
     });
 


=====================================
templates/comment/post.tpl
=====================================
@@ -17,49 +17,7 @@
     {else}
         <form method="post" action="{service controller=comment action=post}">
             <div class="card">
-                {if ! $user or $prefs.feature_comments_post_as_anonymous eq 'y'}
-                    <div class="card-header">
-                        {if $user}
-                            {remarksbox type=warning title="{tr}Anonymous posting{/tr}"}
-                                {tr}You are currently registered on this site. This section is optional. By filling it, you will not link this post to your account and preserve your anonymity.{/tr}
-                            {/remarksbox}
-                        {/if}
-                        <div class="d-flex flex-row flex-wrap align-items-center">
-                            <div class="mb-3">
-                                <label class="clearfix" for="comment-anonymous_name">{tr}Name{/tr}</label>
-                                <input type="text" name="anonymous_name" id="comment-anonymous_name" value="{$anonymous_name|escape}"/>
-                            </div>
-                            <div class="mb-3">
-                                <label class="clearfix" for="comment-anonymous_email">{tr}Email{/tr}</label>
-                                <input type="email" id="comment-anonymous_email" name="anonymous_email" value="{$anonymous_email|escape}"/>
-                            </div>
-                            <div class="mb-3">
-                                <label class="clearfix" for="comment-anonymous_website">{tr}Website{/tr}</label>
-                                <input type="url" id="comment-anonymous_website" name="anonymous_website" value="{$anonymous_website|escape}"/>
-                            </div>
-                        </div>
-                    </div>
-                {/if}
-                <div class="card-body">
-                    <input type="hidden" name="type" value="{$type|escape}"/>
-                    <input type="hidden" name="objectId" value="{$objectId|escape}"/>
-                    <input type="hidden" name="parentId" value="{$parentId|escape}"/>
-                    <input type="hidden" name="post" value="1"/>
-                    {if $prefs.comments_notitle neq 'y'}
-                        <div class="mb-3">
-                            <label for="comment-title" class="clearfix comment-title">{tr}Title{/tr}</label>
-                            <input type="text" id="comment-title" name="title" value="{$title|escape}" class="form-control" placeholder="{tr}Comment title{/tr}" maxlength="{$MAX_COMMENT_TITLE_LENGTH}">
-                        </div>
-                    {/if}
-                    {capture name=rows}{if $type eq 'forum'}{$prefs.default_rows_textarea_forum}{else}{$prefs.default_rows_textarea_comment}{/if}{/capture}
-                    {textarea codemirror='true' name="data" comments="y" maxlength="{$MAX_COMMENT_DATA_LENGTH}" section=$type objectId=$objectId _wysiwyg="n" rows=$smarty.capture.rows class="form-control wikiedit" placeholder="{tr}Post new comment{/tr}..." _preview=$prefs.ajax_edit_previews}{$data|escape}{/textarea}
-                    {if  $user and $prefs.feature_user_watches eq 'y'}
-                        <div class="form-check">
-                            <input id="watch_thread" type="checkbox" class="form-check-input" name="watch" value="y"{if $smarty.request.watch eq 'y'} checked="checked"{/if}>
-                            <label for="watch_thread" class="form-check-label">{tr}Send me an email when someone replies{/tr}</label>
-                        </div>
-                    {/if}
-                </div>
+                {include file="post_form_content.tpl"}
                 <div class="card-footer">
                     {if $prefs.feature_antibot eq 'y'}
                         {$showmandatory='y'}


=====================================
templates/comment/post_form_content.tpl
=====================================
@@ -0,0 +1,43 @@
+{if ! $user or $prefs.feature_comments_post_as_anonymous eq 'y'}
+    <div class="card-header">
+        {if $user}
+            {remarksbox type=warning title="{tr}Anonymous posting{/tr}"}
+                {tr}You are currently registered on this site. This section is optional. By filling it, you will not link this post to your account and preserve your anonymity.{/tr}
+            {/remarksbox}
+        {/if}
+        <div class="d-flex flex-row flex-wrap align-items-center">
+            <div class="mb-3">
+                <label class="clearfix" for="comment-anonymous_name">{tr}Name{/tr}</label>
+                <input type="text" name="anonymous_name" id="comment-anonymous_name" value="{$anonymous_name|escape}"/>
+            </div>
+            <div class="mb-3">
+                <label class="clearfix" for="comment-anonymous_email">{tr}Email{/tr}</label>
+                <input type="email" id="comment-anonymous_email" name="anonymous_email" value="{$anonymous_email|escape}"/>
+            </div>
+            <div class="mb-3">
+                <label class="clearfix" for="comment-anonymous_website">{tr}Website{/tr}</label>
+                <input type="url" id="comment-anonymous_website" name="anonymous_website" value="{$anonymous_website|escape}"/>
+            </div>
+        </div>
+    </div>
+{/if}
+<div class="card-body">
+    <input type="hidden" name="type" value="{$type|escape}"/>
+    <input type="hidden" name="objectId" value="{$objectId|escape}"/>
+    <input type="hidden" name="parentId" value="{$parentId|escape}"/>
+    <input type="hidden" name="post" value="1"/>
+    {if $prefs.comments_notitle neq 'y'}
+        <div class="mb-3">
+            <label for="comment-title" class="clearfix comment-title">{tr}Title{/tr}</label>
+            <input type="text" id="comment-title" name="title" value="{$title|escape}" class="form-control" placeholder="{tr}Comment title{/tr}" maxlength="{$MAX_COMMENT_TITLE_LENGTH}">
+        </div>
+    {/if}
+    {capture name=rows}{if $type eq 'forum'}{$prefs.default_rows_textarea_forum}{else}{$prefs.default_rows_textarea_comment}{/if}{/capture}
+    {textarea codemirror='true' name="data" comments="y" maxlength="{$MAX_COMMENT_DATA_LENGTH}" section=$type objectId=$objectId _wysiwyg="n" rows=$smarty.capture.rows class="form-control wikiedit" placeholder="{tr}Post new comment{/tr}..." _preview=$prefs.ajax_edit_previews}{$data|escape}{/textarea}
+    {if  $user and $prefs.feature_user_watches eq 'y'}
+        <div class="form-check">
+            <input id="watch_thread" type="checkbox" class="form-check-input" name="watch" value="y"{if $smarty.request.watch eq 'y'} checked="checked"{/if}>
+            <label for="watch_thread" class="form-check-label">{tr}Send me an email when someone replies{/tr}</label>
+        </div>
+    {/if}
+</div>


=====================================
templates/tracker/update_item.tpl
=====================================
@@ -34,8 +34,7 @@
     {else}
         <form method="post" action="{service controller=tracker action=update_item format=$format editItemPretty=$editItemPretty suppressFeedback=$suppressFeedback}" id="updateItemForm{$trackerId|escape}">
             {trackerfields trackerId=$trackerId fields=$fields status=$status itemId=$itemId format=$format editItemPretty=$editItemPretty}
-            <hr>
-            <div class="form-check form-switch alert alert-warning">
+            <div class="form-check form-switch alert alert-warning mt-5">
                 <input type="checkbox"
                     class="form-check-input tracker-notify-switch"
                     id="notify_watchers"
@@ -46,14 +45,21 @@
                     {tr}Notify users following this item{/tr}
                 </label>
             </div>
+            {if not empty($saveAndComment) and $saveAndComment neq 'n'}
+                <div class="form-check form-switch mb-4 mt-5">
+                    <input type="checkbox" class="form-check-input" name="addComment" id="add-comment"/>
+                    <label class="form-check-label" for="add-comment">
+                        {tr}Add a comment{/tr}
+                    </label>
+                </div>
+                <div class="comment-form d-none">
+                    {include file="comment/post_form_content.tpl" type='trackeritem' objectId=$itemId}
+                </div>
+            {/if}
             <div class="submit">
                 {if $skip_preview neq 'y'}
                     <input type="button" class="btn btn-secondary previewItemBtn" title="{tr}Preview your changes.{/tr}" name="preview" value="{tr}Preview{/tr}">
                 {/if}
-                {if not empty($saveAndComment) and $saveAndComment neq 'n'}
-                    <input type="hidden" name="saveAndComment" id="saveAndComment" value="">
-                    <input type="submit" class="btn btn-primary" onclick="$('#saveAndComment').val(1);" value="{tr}Save and Comment{/tr}">
-                {/if}
                 {if $save_return eq 'y'}
                     <input type="submit" class="btn btn-primary" name="save_return" value="{tr}Save Returning to Item List{/tr}" onclick="$('input[name=redirect]').val('{$trackerId|sefurl:'tracker'}'); needToConfirm=false">
                 {/if}
@@ -73,7 +79,21 @@
                 {/if}
             </div>
         </form>
-        {* Don't warn on leaving page if the modal is closed without saving *}
-        {jq}$(".modal.fade.show").one("hide.bs.modal", function () {window.needToConfirm=false;});{/jq}
+        {jq}
+            {* Don't warn on leaving page if the modal is closed without saving *}
+            $(".modal.fade.show").one("hide.bs.modal", function () {window.needToConfirm=false;});
+
+            {* Disable the comment editor textarea, so it doesn't interfere with form validation when it's hidden *}
+            $(".comment-form").find("textarea").prop("disabled", true);
+            $("#add-comment").on("change", function() {
+                if ($(this).is(":checked")) {
+                    $(".comment-form").removeClass("d-none");
+                    $(".comment-form").find("textarea").prop("disabled", false);
+                } else {
+                    $(".comment-form").addClass("d-none");
+                    $(".comment-form").find("textarea").prop("disabled", true);
+                }
+            });
+        {/jq}
     {/if}
 {/block}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/4dd9be4cc12eb4db8bdc46715a75e985fe9784d1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/4dd9be4cc12eb4db8bdc46715a75e985fe9784d1
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.