]> _ Git - cubist_cms-back.git/commitdiff
wip #7592 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Jun 2025 14:41:39 +0000 (16:41 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Jun 2025 14:41:39 +0000 (16:41 +0200)
src/app/Magic/Fields/FilesOrURL.php
src/resources/views/fields/filesorurl.blade.php

index 1899d8277e064903e66281ea2b48925894d0342a..4db1772cd3a65c5ddb2c94f0dca5ca92ea2660ed 100644 (file)
@@ -9,10 +9,11 @@ class FilesOrURL extends Field
     protected $_adminType = 'filesorurl';
     protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
     protected $_destination = '';
+    protected $_downloadbase = false;
 
     public function getDefaultAttributes()
     {
-        return array_merge(parent::getDefaultAttributes(), ['destination' => $this->_destination]);
+        return array_merge(parent::getDefaultAttributes(), ['destination' => $this->_destination, 'downloadbase' => $this->_downloadbase]);
     }
 
     protected function _postSetAttributes()
index 2b6f524e02c07ef55c44b59487c61d18cffccaae..54cf32c14c193568f4e44990eb9e1e9f55ff0eaa 100644 (file)
@@ -21,7 +21,9 @@
 @endpush
 
 {{-- Show the file picker on CREATE form. --}}
-<div class="freefile-file">
+<div class="freefile-file  @if($field['downloadbase'])
+hasdownload
+@endif">
     <input type="file" multiple name="upload[]"
            @if(isset($field['accept']) && $field['accept'])
                accept="{{$field['accept']}}"
@@ -30,7 +32,8 @@
     @if(isset($field['accept']) && $field['accept'] && stristr($field['accept'],'.zip'))
         <input type="file" multiple directory webkitdirectory name="directory[]" class="freefile-file-input-directory"
                form="{{$form_id}}">
-        <a class="upload" href="#" data-tooltip="{{__('Clic pour charger un ou plusieurs fichiers, Ctrl+Clic pour charger un dossier')}}"></a>
+        <a class="upload" href="#"
+           data-tooltip="{{__('Clic pour charger un ou plusieurs fichiers, Ctrl+Clic pour charger un dossier')}}"></a>
     @endif
 
     <input type="text" name="{{ $field['name'] }}"
         @include('crud::fields.inc.attributes', ['default_class' =>  'form-control freefile-text-input'])
     >
     <label class="freefile-file-label" for="customFile"></label>
+    @if($field['downloadbase'])
+        <a href="#" class="freefile-file-download" data-downloadbase="{{$field['downloadbase']}}"><i
+                class="las la-download"></i></a>
+    @endif
 </div>
 
 {{-- HINT --}}
                 margin: 0;
                 left: 0;
                 width: 85%;
-                top:2px;
+                top: 2px;
                 border-color: transparent;
                 background-color: transparent;
             }
                 width: calc(100% - 87px);
             }
 
+            .freefile-file.hasdownload .freefile-text-input:lang(en) {
+                width: calc(100% - 74px - 38px);
+            }
+
+            .freefile-file.hasdownload .freefile-text-input:lang(fr) {
+                width: calc(100% - 87px - 38px);
+            }
+
             .freefile-file-input:lang(en) {
                 width: 74px;
             }
                 width: 87px;
             }
 
+            .freefile-file-download {
+                position: absolute;
+                display: none;
+                top: 0;
+                height: 100%;
+                width: 38px;
+                cursor: pointer;
+                background-color: #f0f3f9;
+                border: 1px solid #e4e7ea;
+                border-right-width: 0;
+                color: #5c6873;
+                z-index: 3;
+                line-height: 38px;
+                text-align: center;
+                font-size: 19px;
+
+            }
+
+            .freefile-file.hasdownload .freefile-file-download {
+                display: block;
+            }
+
+            .freefile-text-input:focus ~ .freefile-file-download {
+                border-color: #2f66b3;
+            }
+
+            .freefile-file-download:lang(en) {
+                right: 74px;
+            }
+
+            .freefile-file-download:lang(fr) {
+                right: 87px;
+            }
+
             .freefile-text-input:focus ~ .freefile-file-label {
                 border-color: #2f66b3;
                 box-shadow: 0 0 0 0rem rgba(70, 127, 208, 0.25);
                 crossorigin="anonymous" referrerpolicy="no-referrer"></script>
         <script>
             jQuery(document).ready(function ($) {
+                function updateDownload() {
+                    $('.freefile-file').each(function () {
+                        if ($(this).find('.freefile-file-download').length === 0) {
+                            return;
+                        }
+                        let v = $(this).find('.freefile-text-input').val();
+                        if (v === '' || v.indexOf('http') === 0) {
+                            $(this).removeClass('hasdownload');
+                        } else {
+                            $(this).addClass('hasdownload');
+                        }
+                    });
+                }
+
                 $(document).on('change', '.freefile-file-input', function () {
                     var parent = $(this).closest('.freefile-file');
                     $(parent).addClass('loading');
                         tf.val(data[0]);
                         tf.trigger('change');
                         $(parent).removeClass('loading');
+                        updateDownload();
                     });
                 });
+
+                $(document).on('change', '.freefile-text-input', function () {
+                    updateDownload();
+                });
+
+                $(document).on('click', '.freefile-file-download', function () {
+                    let v = $(this).closest('.freefile-file').find('.freefile-text-input').val();
+                    let url = $(this).data('downloadbase');
+                    url += v;
+                    url=url.replace(/(\$id)/g, $('input[name="id"]').val());
+                    $('<a href="' + url + '" download="' + v + '"></a>').get('0').click();
+                    return false;
+                });
+
+                updateDownload();
             });
         </script>
     @endpush