[TikiWiki-commits] [Git][tikiwiki/tiki][27.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 <68ba1ba2eeaa2_2c357be03146d@gitlab-sidekiq-low-urgency-cpu-bound-v2-5b8f789cf4-jr5cg.mail>

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


Commits:
6bb77f89 by Adrien Mbuya Maloba at 2025-09-05T02:00:25+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!8511

- - - - -


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
=====================================
@@ -214,7 +214,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'),
+                        ],
+                    ],
                 ],
             ],
         ];
@@ -391,6 +401,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/6bb77f8938fb6aa51096b81ddb703381eaaf7a4b

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