[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][ENH] Trackers: After drag and dropping a files to the Files Tracker...

"Adrien Mbuya Maloba \(@adrienmaloba\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68a763fba8226_2cd6e2070571@gitlab-sidekiq-low-urgency-cpu-bound-v2-5546c8c99c-fgb27.mail>

Adrien Mbuya Maloba pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
98344a0d by Adrien Mbuya Maloba at 2025-08-21T21:15:59+03:00
[BP][ENH] Trackers: After drag and dropping a files to the Files Tracker Field, add a way to rename file before selection
---
* [ENH] Trackers: After drag and dropping a files to the Files Tracker Field, add a way to rename file before selection
---
* [ENH] Trackers: After drag and dropping a files to the Files Tracker Field, add a way to rename file before selection

See merge request tikiwiki/tiki!7317

See merge request tikiwiki/tiki!8144

- - - - -


6 changed files:

- lib/core/Services/File/Controller.php
- lib/core/Tracker/Field/Files.php
- lib/filegals/filegallib.php
- lib/jquery_tiki/files.js
- templates/file/uploader.tpl
- templates/trackerinput/files.tpl


Changes:

=====================================
lib/core/Services/File/Controller.php
=====================================
@@ -49,13 +49,19 @@ class Services_File_Controller
 
         $util = new Services_Utilities();
         if ($util->isActionPost()) {
-            if ($input->offsetExists('description')) {
+            if ($input->offsetExists('description') || $input->offsetExists('newfilename')) {
                 $files = $input->asArray('file');
                 $descriptions = $input->asArray('description');
-
+                $newfilenames = $input->asArray('newfilename');
                 foreach ($files as $c => $file) {
                     $fileInfo = $filegallib->get_file_info($file);
-
+                    if (isset($newfilenames[$c])) {
+                        $filegallib->update_file($fileInfo['fileId'], [
+                            'newfilename' => $newfilenames[$c],
+                            'filename' => $fileInfo['filename'],
+                            'lastModifUser' => $fileInfo['asuser'],
+                        ]);
+                    }
                     if (isset($descriptions[$c])) {
                         $filegallib->update_file($fileInfo['fileId'], [
                             'name' => $fileInfo['filename'],
@@ -78,6 +84,7 @@ class Services_File_Controller
             'addDecriptionOnUpload' => $input->addDecriptionOnUpload->int(),
             'admin_trackers'        => $perms->admin_trackers,
             'requireTitle'          => $input->requireTitle->text(),
+            'changeFileNameOnUpload' => $input->changeFileNameOnUpload->int(),
             'directoryPattern'      => $input->directoryPattern->text(),
         ];
 


=====================================
lib/core/Tracker/Field/Files.php
=====================================
@@ -229,7 +229,17 @@ class Tracker_Field_Files extends \Tracker\Field\AbstractItemField implements \T
                             'n' => tr('No'),
                             'y' => tr('Yes'),
                         ],
-                    ]
+                    ],
+                    'changeFileNameOnUpload' => [
+                        'name' => tr('Change file name'),
+                        'description' => tr('Change file name on uploaded files. Upload In Modal required.'),
+                        'filter' => 'alpha',
+                        'default' => 'n',
+                        'options' => [
+                            'n' => tr('No'),
+                            'y' => tr('Yes'),
+                        ],
+                    ],
                 ],
             ],
         ];
@@ -419,6 +429,7 @@ class Tracker_Field_Files extends \Tracker\Field\AbstractItemField implements \T
         return $this->renderTemplate('trackerinput/files.tpl', $context, [
             'replaceFile' => 'y' == $this->getOption('replace', 'n'),
             'addDecriptionOnUpload' => $this->getOption('addDecriptionOnUpload') === 'y' ? 1 : 0,
+            'changeFileNameOnUpload' => $this->trackerField->getOption('changeFileNameOnUpload') === 'y' ? 1 : 0,
         ]);
     }
 


=====================================
lib/filegals/filegallib.php
=====================================
@@ -852,10 +852,19 @@ class FileGalLib extends TikiLib
      */
     public function update_file($id, $params)
     {
-        if (isset($params['name'])) {
+        if (! empty($params['name'])) {
             $params['name'] = strip_tags($params['name']);
         }
-        if (isset($params['description'])) {
+        // Change the file name when uploading via the Files type field of the Tracker
+        if (! empty($params['newfilename'])) {
+            $newfilename = strip_tags($params['newfilename']);
+            $params['name'] = $newfilename;
+            $extension = pathinfo($params['filename'], PATHINFO_EXTENSION);
+            $params['filename'] = $newfilename . '.' . $extension;
+            // Remove key newfilename
+            unset($params['newfilename']);
+        }
+        if (! empty($params['description'])) {
             $params['name'] = strip_tags($params['description']);
         }
         $params['lastModif'] = $this->now;


=====================================
lib/jquery_tiki/files.js
=====================================
@@ -66,10 +66,19 @@
             if (title) {
                 label = title;
             }
-            $("<div>").addClass("col-sm-12").text(label)
+            if ($list.data("changefilename")) {
+                $("<div>").addClass("col-2 change-file")
+                    .append($.fileTypeIcon(fileId, file).css("margin-right", "1em"))
+                    .appendTo($li);
+                var labelNewFileName = title ? title : label.replace(/\.[^.]*$/,''); //Remove extension from file name
+                $("<div>").addClass("col-10 input-text" + fileId + "").append($('<input type="text" class="form-control newfilename ' + fileId + '" name="newfilename[]">')
+                .attr('value', labelNewFileName))
+                    .appendTo($li);
+            } else {
+                $("<div>").addClass("col-sm-12").text(label)
                 .prepend($.fileTypeIcon(fileId, file).css("margin-right", "1em"))
                 .appendTo($li);
-
+            }
 
             if ($list.parents(".inline").length) {
                 var $fileInput = $list.parents(".files-field").find("> input");


=====================================
templates/file/uploader.tpl
=====================================
@@ -46,7 +46,7 @@
             </p>
         </form>
         <form class="file-uploader-result" method="post" action="{service controller=file action=uploader galleryId=$galleryId}">
-            <ul class="list-unstyled" data-adddescription="{$addDecriptionOnUpload}"></ul>
+            <ul class="list-unstyled" data-adddescription="{$addDecriptionOnUpload}" data-changefilename="{$changeFileNameOnUpload}"></ul>
 
             <div class="submit">
                 {ticket}


=====================================
templates/trackerinput/files.tpl
=====================================
@@ -62,7 +62,7 @@
             {wikiplugin _name='vimeo' fromFieldId=$field.fieldId|escape fromItemId=$item.itemId|escape galleryId=$field.galleryId|escape}{/wikiplugin}
         {else}
             {if $field.options_map.uploadInModal neq 'n'}
-                <a href="{service controller=file action=uploader uploadInModal=1 galleryId=$field.galleryId limit=$actual_limit type=$field.filter image_max_size_x=$field.image_x image_max_size_y=$field.image_y addDecriptionOnUpload=$data.addDecriptionOnUpload trackerId=$field.trackerId requireTitle=$field.requireTitle directoryPattern=$field.directoryPattern}" class="btn btn-primary upload-files">
+                <a href="{service controller=file action=uploader uploadInModal=1 galleryId=$field.galleryId limit=$actual_limit type=$field.filter image_max_size_x=$field.image_x image_max_size_y=$field.image_y addDecriptionOnUpload=$data.addDecriptionOnUpload changeFileNameOnUpload=$data.changeFileNameOnUpload trackerId=$field.trackerId requireTitle=$field.requireTitle directoryPattern=$field.directoryPattern}" class="btn btn-primary upload-files">
                     {if $actual_limit !== 1}{tr}Upload Files{/tr}{else}{tr}Upload File{/tr}{/if}
                 </a>
             {else}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/98344a0ddb1178d96b8fc66cce7fffe4389def1f

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