[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Webmail: Show a tracker field selector when choosing an item in which to move a sent email

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68e9663ff906_2c428c0b888c9@gitlab-sidekiq-low-urgency-cpu-bound-v2-6c768f58c5-c4sf8.mail>

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


Commits:
430d6ad1 by Merci Jacob at 2025-10-10T19:53:23+00:00
[ENH] Webmail: Show a tracker field selector when choosing an item in which to move a sent email
---
* [ENH] Webmail: Show a tracker field selector when choosing an item in which to move a sent email

See merge request tikiwiki/tiki!8755

- - - - -


8 changed files:

- lib/cypht/modules/tiki/functions.php
- lib/cypht/modules/tiki/general_modules.php
- lib/cypht/modules/tiki/js_modules/getSentMsgTrackerItems.js
- lib/cypht/modules/tiki/js_modules/moveToTracker.js
- lib/cypht/modules/tiki/js_modules/utils/moveToTracker.utils.js
- lib/cypht/modules/tiki/js_modules/utils/moveToTrackerSearch.utils.js
- lib/cypht/modules/tiki/setup.php
- vendor_bundled/composer.lock


Changes:

=====================================
lib/cypht/modules/tiki/functions.php
=====================================
@@ -371,7 +371,6 @@ if (! hm_exists('tiki_move_to_tracker_dropdown')) {
             return;
         }
         $field_list = [];
-        $fields_without_folders = [];
         foreach ($fields as $field) {
             $tracker = $trk->get_tracker($field['trackerId']);
             $handler = $trk->get_field_handler($field);
@@ -385,7 +384,6 @@ if (! hm_exists('tiki_move_to_tracker_dropdown')) {
             } else {
                 $field_list[] = "<a href='#' class='object_selector_trigger dropdown-item' data-tracker='{$field['trackerId']}' data-field='{$field['fieldId']}' data-folder='inbox'>{$tracker['name']} - {$field['name']}</a>";
             }
-            $fields_without_folders[] = ['tracker_id' => $field['trackerId'], 'field_id' => $field['fieldId'], 'title' => "{$tracker['name']} - {$field['name']}"];
         }
         $res = "<div class=\"" . ($class != 'move_to_trackers' ? 'dropdown ' : '') . "d-inline-block\">";
         if ($class != 'move_to_trackers') {
@@ -393,7 +391,6 @@ if (! hm_exists('tiki_move_to_tracker_dropdown')) {
             $res .= "<div class='" . $class . " dropdown-menu' aria-labelledby='$class'><div class='move_to_title'>" . $mod->trans($dropdown_title) . "</div>" . implode("<br>\n", $field_list) . "</div>";
         } else {
             $res .= "<a class=\"hlink text-decoration-none btn btn-sm btn-outline-secondary ms-2" . (! $message_view ? ' btn btn-sm btn-light border text-black-50' : '') . "\" id=\"{$class}\" href=\"#\" >" . $mod->trans($dropdown_title) . "</a>";
-            $res .= '<script type="text/javascript">var tiki_tracker_fields = ' . json_encode($fields_without_folders) . '</script>';
         }
         $res .= "</div>";
 


=====================================
lib/cypht/modules/tiki/general_modules.php
=====================================
@@ -480,6 +480,17 @@ class Hm_Handler_get_msg_tracker_items extends Hm_Handler_Module
         $this->session->set('msg_uid', '');
         $this->session->set('imap_server_id', '');
 
+        $fields = TikiLib::lib('trk')->get_fields_by_type('EF');
+        $fields = array_map(function ($field) {
+            $tracker = TikiLib::lib('trk')->get_tracker($field['trackerId']);
+            return [
+                'tracker_id' => $field['trackerId'],
+                'field_id' => $field['fieldId'],
+                'title' => "{$tracker['name']} - {$field['name']}",
+            ];
+        }, $fields);
+        $this->out('tracker_fields', $fields);
+
         if (isset($this->request->post['lookup'])) {
             $searchArgs = [];
             if (isset($this->request->post['sort_mode'])) {


=====================================
lib/cypht/modules/tiki/js_modules/getSentMsgTrackerItems.js
=====================================
@@ -1,11 +1,11 @@
 function getSentMsgTrackerItems() {
-    const [searchMarkup, searchHandler] = moveToTrackerItemSearchHandler();
-
     Hm_Ajax.request([
         {name: 'hm_ajax_hook', value: 'ajax_tiki_msg_tracker_items'},
     ], (globalRes) => {
         if (globalRes.error) return;
-        const trackerItems = unserializeTrackerItems(globalRes);
+        const trackerItems = unserializeResponseValue(globalRes);
+
+        const [searchMarkup, searchHandler] = moveToTrackerItemSearchHandler(null, unserializeResponseValue(globalRes, 'tracker_fields'));
 
         $.openModal({
             title: tr("Move to tracker item"),


=====================================
lib/cypht/modules/tiki/js_modules/moveToTracker.js
=====================================
@@ -1,6 +1,4 @@
 function showMoveToTrackerModal(onSuccess) {
-    const [searchMarkup, searchHandler] = moveToTrackerItemSearchHandler(onSuccess);
-
     $.openModal({
         title: tr("Move to tracker item"),
         variants: ["scrollable"],
@@ -9,11 +7,10 @@ function showMoveToTrackerModal(onSuccess) {
             <div class="d-flex flex-column gap-2 mt-3 suggested-items">
                 ${$.IMPORT_LOADER_MARKUP}
             </div>
-            ${searchMarkup}
+            <div id="search-markup"></div>
         `,
         open: function () {
             const modal = $(this);
-            searchHandler(modal, getMsgUid(), getListPathParam(), true);
 
             Hm_Ajax.request([
                 {name: 'hm_ajax_hook', value: 'ajax_tiki_msg_tracker_items'},
@@ -21,7 +18,12 @@ function showMoveToTrackerModal(onSuccess) {
                 {name: 'limit', value: 5},
                 {name: 'sort_mode', value: 'score_desc'},
             ], (res) => {
-                const items = unserializeTrackerItems(res);
+                const [searchMarkup, searchHandler] = moveToTrackerItemSearchHandler(onSuccess, unserializeResponseValue(res, 'tracker_fields'));
+
+                modal.find('#search-markup').html(searchMarkup);
+                searchHandler(modal, getMsgUid(), getListPathParam(), true);
+
+                const items = unserializeResponseValue(res);
                 const suggestedItems = $(".suggested-items", this);
                 suggestedItems.empty();
 


=====================================
lib/cypht/modules/tiki/js_modules/utils/moveToTracker.utils.js
=====================================
@@ -1,11 +1,11 @@
-function unserializeTrackerItems(response) {
-    const trackerItems = [];
-    if (response.tracker_items) {
-        for (const [_, item] of Object.entries(response.tracker_items)) {
-            trackerItems.push(item);
+function unserializeResponseValue(response, key = 'tracker_items') {
+    const value = [];
+    if (response[key]) {
+        for (const [_, item] of Object.entries(response[key])) {
+            value.push(item);
         }
     }
-    return trackerItems;
+    return value;
 }
 
 function getItemHtml(item) {


=====================================
lib/cypht/modules/tiki/js_modules/utils/moveToTrackerSearch.utils.js
=====================================
@@ -1,8 +1,15 @@
-function moveToTrackerItemSearchHandler(onSuccess) {
-    let markup = `
+function moveToTrackerItemSearchHandler(onSuccess, trackerFields = []) {
+
+    const fieldSelectoptions = trackerFields.map(function(field) {
+        return `<option value="${field.tracker_id}-${field.field_id}">${field.title}</option>`;
+    });
+
+    const markup = `
     <p class="mt-4 fw-bold">Looking for more?</p>
     <p class="fw-lighter fst-italic">${tr("Enter a keyword and/or choose a tracker/field below to find more items")}.</p>
-    <span id="tracker-field"></span>
+    <div class="input-group mt-3">
+        <select class="form-control tracker_field"><option value="">${tr('All available trackers/fields')}</option>${fieldSelectoptions}</select>
+    </div>
     <div class="input-group mt-3">
         <input type="text" class="form-control lookup" placeholder="${tr("Search for more items")}" />
         <button class="btn btn-sm btn-primary lookup-btn">${$.fn.getIcon("search").prop("outerHTML")}</button>
@@ -10,15 +17,6 @@ function moveToTrackerItemSearchHandler(onSuccess) {
     <div class="d-flex flex-column gap-2 mt-3 lookup-results"></div>
     `;
 
-    if (typeof tiki_tracker_fields != 'undefined') {
-        let options = tiki_tracker_fields.map(function(field) {
-            return `<option value="${field.tracker_id}-${field.field_id}">${field.title}</option>`;
-        });
-        markup = markup.replace('<span id="tracker-field"></span>', `<div class="input-group mt-3">
-            <select class="form-control tracker_field"><option value="">${tr('All available trackers/fields')}</option>${options}</select>
-        </div> `);
-    }
-
     const handler = (modal, msgUid, listPath, chooseFolder = false) => {
         modal.find('.lookup-btn').on('click', function () {
             const input = modal.find('.lookup');
@@ -42,7 +40,7 @@ function moveToTrackerItemSearchHandler(onSuccess) {
                 {name: 'limit', value: 100},
                 {name: 'sort_mode', value: 'score_desc'},
             ], (res) => {
-                const items = unserializeTrackerItems(res);
+                const items = unserializeResponseValue(res);
                 const resultsContainer = modal.find('.lookup-results');
                 resultsContainer.empty();
 


=====================================
lib/cypht/modules/tiki/setup.php
=====================================
@@ -280,6 +280,7 @@ return [
     'auto_move' => [FILTER_VALIDATE_BOOLEAN, false],
     'item_id' => [FILTER_SANITIZE_FULL_SPECIAL_CHARS, false],
     'field_id' => [FILTER_SANITIZE_FULL_SPECIAL_CHARS, false],
+    'tracker_fields' => [FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY],
   ],
   'allowed_post' => [
     'imap_server_id' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,


=====================================
vendor_bundled/composer.lock
=====================================
@@ -3009,12 +3009,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/cypht-org/cypht.git",
-                "reference": "49d6f048b2dc5758853cb4d548edc5b39645d4ea"
+                "reference": "2db47598969771da66632fc1be6ce47a453ddddb"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/cypht-org/cypht/zipball/49d6f048b2dc5758853cb4d548edc5b39645d4ea",
-                "reference": "49d6f048b2dc5758853cb4d548edc5b39645d4ea",
+                "url": "https://api.github.com/repos/cypht-org/cypht/zipball/2db47598969771da66632fc1be6ce47a453ddddb",
+                "reference": "2db47598969771da66632fc1be6ce47a453ddddb",
                 "shasum": ""
             },
             "require": {
@@ -3090,7 +3090,7 @@
                 "source": "https://github.com/cypht-org/cypht/",
                 "wiki": "https://github.com/cypht-org/cypht/wiki"
             },
-            "time": "2025-09-24T14:08:35+00:00"
+            "time": "2025-10-09T14:33:06+00:00"
         },
         {
             "name": "jean85/pretty-package-versions",



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/430d6ad1a14ba069a38b0865c7304664f5840af1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/430d6ad1a14ba069a38b0865c7304664f5840af1
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.