[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Trackers: ensure that the modified auto-assign user field is updated...

"Merci Jacob \(@mercihabam\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6983393ba6b6a_3b18430458339@gitlab-sidekiq-low-urgency-cpu-bound-v2-65d8676567-5dvl9.mail>

Merci Jacob pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
0b2d34a2 by Merci Jacob at 2026-02-04T12:08:01+00:00
[FIX] Trackers: ensure that the modified auto-assign user field is updated when editing a tracker field inline, and refresh all cells of the row to reflect changes
---
* remove incorrect imports

* fix linter

* refactor to interface instead and address design issue

* fix phpcs

* enhance clarity by refactoring the UserSelector field to the abstraction of 'AbstractAutoChangeItemField' & using constants for the 'autoassign' param options

* explain the modification with some comments in the code

* [FIX] ensure that the modified auto-assign user field is updated when editing a tracker field inline, and refresh all cells of the row to reflect changes

See merge request tikiwiki/tiki!8860

- - - - -


4 changed files:

- + lib/core/Tracker/Field/AutoSyncableInterface.php
- lib/core/Tracker/Field/UserSelector.php
- lib/core/Tracker/Item.php
- lib/jquery_tiki/inline_edit.js


Changes:

=====================================
lib/core/Tracker/Field/AutoSyncableInterface.php
=====================================
@@ -0,0 +1,20 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+namespace Tracker\Field;
+
+/**
+ * Interface for fields whose state may change in response to updates in other fields’ values.
+ */
+interface AutoSyncableInterface
+{
+    /**
+     * Defines how the field’s state should be updated in response to inline changes in related fields.
+     *
+     * @param array $requestData The data submitted in the inline edit request
+     */
+    public function getAutoSyncInlineEditFieldData(array $requestData = []): array;
+}


=====================================
lib/core/Tracker/Field/UserSelector.php
=====================================
@@ -4,13 +4,22 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+use Tracker\Field\AutoSyncableInterface;
+
+const AUTO_ASSIGN_OPTIONS = [
+    'None' => 0,
+    'Creator' => 1,
+    'Modifier' => 2,
+];
+
 /**
  * Handler class for UserSelector
  *
  * Letter key: ~u~
  *
  */
-class Tracker_Field_UserSelector extends \Tracker\Field\AbstractItemField implements \Tracker\Field\SynchronizableInterface, \Tracker\Field\ExportableInterface, \Tracker\Field\FilterableInterface, Search_FacetProvider_Interface, \Tracker\Field\EnumerableInterface
+class Tracker_Field_UserSelector extends \Tracker\Field\AbstractItemField implements \Tracker\Field\SynchronizableInterface, \Tracker\Field\ExportableInterface, \Tracker\Field\FilterableInterface, Search_FacetProvider_Interface, \Tracker\Field\EnumerableInterface, AutoSyncableInterface
 {
     public static function getManagedTypesInfo(): array
     {
@@ -35,11 +44,11 @@ class Tracker_Field_UserSelector extends \Tracker\Field\AbstractItemField implem
                         'name' => tr('Auto-Assign'),
                         'description' => tr('Assign the value based on the creator or modifier.'),
                         'filter' => 'int',
-                        'default' => 0,
+                        'default' => AUTO_ASSIGN_OPTIONS['None'],
                         'options' => [
-                            0 => tr('None'),
-                            1 => tr('Creator'),
-                            2 => tr('Modifier'),
+                            AUTO_ASSIGN_OPTIONS['None'] => tr('None'),
+                            AUTO_ASSIGN_OPTIONS['Creator'] => tr('Creator'),
+                            AUTO_ASSIGN_OPTIONS['Modifier'] => tr('Modifier'),
                         ],
                         'legacy_index' => 0,
                     ],
@@ -232,7 +241,7 @@ class Tracker_Field_UserSelector extends \Tracker\Field\AbstractItemField implem
         $autoassign = (int) $this->getOption('autoassign');
 
         if (isset($requestData[$ins_id])) {
-            if ($autoassign == 0 || $this->canChangeValue()) {
+            if ($autoassign == AUTO_ASSIGN_OPTIONS['None'] || $this->canChangeValue()) {
                 $ausers = $requestData[$ins_id];
                 $realnames_check = $prefs['user_selector_realnames_tracker'] == 'y' && $this->getOption('showRealname');
                 $users = TikiLib::lib('user')->extract_users($ausers, $realnames_check);
@@ -244,26 +253,7 @@ class Tracker_Field_UserSelector extends \Tracker\Field\AbstractItemField implem
                     $data['value'] = '';
                 }
             } else {
-                if ($autoassign == 2) {
-                    if ($this->getOption('multiple')) {
-                        $data['value'] = TikiLib::lib('trk')->parse_user_field($this->getValue());
-                        if (! in_array($user, $data['value'])) {
-                            $data['value'][] = $user;
-                        }
-                        $data['value'] = TikiLib::lib('tiki')->str_putcsv($data['value']);
-                    } else {
-                        $data['value'] = $user;
-                    }
-                } elseif ($autoassign == 1) {
-                    if (! $this->getItemId() || ($this->getTrackerDefinition()->getConfiguration('userCanTakeOwnership') == 'y' && ! $this->getValue())) {
-                        $data['value'] = $user; // the user appropiate the item
-                    } else {
-                        $data['value'] = $this->getValue();
-                        // unset($data['fieldId']); hmm?
-                    }
-                } else {
-                    $data['value'] = '';
-                }
+                $data['value'] = $this->getAutoAssignValue();
             }
         } else {
             $data['value'] = $this->getValue(false);
@@ -272,6 +262,42 @@ class Tracker_Field_UserSelector extends \Tracker\Field\AbstractItemField implem
         return $data;
     }
 
+    public function getAutoSyncInlineEditFieldData(array $requestData = []): array
+    {
+        if (! isset($requestData['edit']) || $requestData['edit'] != 'inline' || isset($requestData[$this->getInsertId()])) {
+            return [];
+        }
+        return ['value' => $this->getAutoAssignValue()];
+    }
+
+    private function getAutoAssignValue()
+    {
+        global $user;
+        $autoassign = (int) $this->getOption('autoassign');
+
+        $out = '';
+
+        if ($autoassign == AUTO_ASSIGN_OPTIONS['Modifier']) {
+            if ($this->getOption('multiple')) {
+                $out = TikiLib::lib('trk')->parse_user_field($this->getValue());
+                if (! in_array($user, $out)) {
+                    $out[] = $user;
+                }
+                $out = TikiLib::lib('tiki')->str_putcsv($out);
+            } else {
+                $out = $user;
+            }
+        } elseif ($autoassign == AUTO_ASSIGN_OPTIONS['Creator']) {
+            if (! $this->getItemId() || ($this->getTrackerDefinition()->getConfiguration('userCanTakeOwnership') == 'y' && ! $this->getValue())) {
+                $out = $user; // the user appropiate the item
+            } else {
+                $out = $this->getValue();
+            }
+        }
+
+        return $out;
+    }
+
     public function addValue($user)
     {
         $value = $this->getValue();


=====================================
lib/core/Tracker/Item.php
=====================================
@@ -533,7 +533,14 @@ class Tracker_Item
                 // getFieldData expects the value to be in $input['ins_xx']
                 $input[$field['ins_id']] = $input['fields'][$field['permName']];
             }
-            return array_merge($field, $handler->getFieldData($input));
+
+            $out = array_merge($field, $handler->getFieldData($input));
+
+            if (method_exists($handler, 'getAutoSyncInlineEditFieldData')) {
+                $out = array_merge($out, $handler->getAutoSyncInlineEditFieldData($input));
+            }
+
+            return $out;
         }
     }
 


=====================================
lib/jquery_tiki/inline_edit.js
=====================================
@@ -57,23 +57,26 @@
                             return $(this).data('field-fetch-url');
                         }).
                         each(function () {
-                            var $this = $(this),
-                                obj = $.extend($(this).data('field-fetch-url'), { mode: "output" });    // use the url for the field input in output mode
-
-                            $.get($.serviceUrl(obj))
-                                .done(function (data) {
-                                    $this.removeClass("loaded")
-                                        .tikiModal()
-                                        .html(data.replace("<!DOCTYPE html>", "").trim())
-                                        .attr("title", $(this).data("saved_title") || "")
-                                        .removeData("saved_title");
-                                    if( $this.data('saved_overflow') ) {
-                                        $this.closest('td').css('overflow', $this.data('saved_overflow'));
-                                    }
-                                    var editIcon = $.fn.getIcon('edit');
-                                    $(editIcon).addClass('ml-2');
-                                    $this.append(editIcon);
-                                });
+                            const $parentRow = $(this).closest('tr');
+                            $parentRow.find(".editable-inline").each(function() {
+                                const $this = $(this),
+                                    obj = $.extend($(this).data('field-fetch-url'), { mode: "output" });    // use the url for the field input in output mode
+
+                                $.get($.serviceUrl(obj))
+                                    .done(function (data) {
+                                        $this.removeClass("loaded")
+                                            .tikiModal()
+                                            .html(data.replace("<!DOCTYPE html>", "").trim())
+                                            .attr("title", $(this).data("saved_title") || "")
+                                            .removeData("saved_title");
+                                        if( $this.data('saved_overflow') ) {
+                                            $this.closest('td').css('overflow', $this.data('saved_overflow'));
+                                        }
+                                        var editIcon = $.fn.getIcon('edit');
+                                        $(editIcon).addClass('ml-2');
+                                        $this.append(editIcon);
+                                    });
+                            });
                         });
                 })
                 .fail(function () {



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0b2d34a2932919ecfc8b158e1a3c749fd186e06b

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0b2d34a2932919ecfc8b158e1a3c749fd186e06b
You're receiving this email because of your account on gitlab.com.

_______________________________________________
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.