From 91e172802ce32883c584c9ea13565c1a4266747f Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Tue, 4 Aug 2020 22:07:24 +0200 Subject: [PATCH] Add overwrite hint when uploading via drag&drop, make it configurable Signed-off-by: Marco Dickert --- src/ifm.js | 22 +++++++++++++--------- src/main.php | 4 +++- src/style.css | 4 +--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/ifm.js b/src/ifm.js index 4616de4..7edf868 100644 --- a/src/ifm.js +++ b/src/ifm.js @@ -947,12 +947,12 @@ function IFM(params) { e.preventDefault(); var newfilename = form.elements.newfilename.value; var files = Array.prototype.slice.call( form.elements.files.files ); - var existing_files = []; + var existing_files; if (files.length > 1) existing_files = files.map(x => x.name).filter(item => self.fileCache.map(x => x.name).includes(item)); else - existing_files = self.fileCache.map(x => x.name).includes(newfilename); - if (existing_files.length > 0) + existing_files = self.fileCache.map(x => x.name).indexOf(newfilename) ? [newfilename] : []; + if (existing_files.length > 0 && self.config.confirmoverwrite) self.showUploadConfirmOverwrite(files, existing_files, newfilename); else { if (files.length == 1) @@ -970,13 +970,13 @@ function IFM(params) { }); }; - this.showUploadConfirmOverwrite = function(files, existing_files, newfilename="") { + this.showUploadConfirmOverwrite = function(files, existing_files, newfilename=undefined) { self.showModal(Mustache.render(self.templates.uploadconfirmoverwrite, {files: existing_files, i18n: self.i18n})); var form = document.forms.formUploadConfirmOverwrite; form.addEventListener('click', function(e) { if (e.target.id == "buttonConfirm") { e.preventDefault(); - if (files.length == 1) + if (files.length == 1 && newfilename) self.uploadFile(files[0], newfilename); else files.forEach(function(file) { @@ -1889,10 +1889,14 @@ function IFM(params) { div.ondrop = function( e ) { e.preventDefault(); e.stopPropagation(); - var files = e.dataTransfer.files; - for( var i = 0; i < files.length; i++ ) { - self.uploadFile( files[i] ); - } + var files = Array.from(e.dataTransfer.files); + var existing_files = files.map(x => x.name).filter(item => self.fileCache.map(x => x.name).includes(item)); + if (existing_files.length > 0 && self.config.confirmoverwrite) + self.showUploadConfirmOverwrite(files, existing_files); + else + files.forEach(function(file) { + self.uploadFile(file); + }); if( e.target.id == 'filedropoverlay' ) e.target.style.display = 'none'; else if( e.target.parentElement.id == 'filedropoverlay' ) { diff --git a/src/main.php b/src/main.php index f92b79a..b8fe4a7 100644 --- a/src/main.php +++ b/src/main.php @@ -56,7 +56,8 @@ class IFM { "contextmenu" => 1, "disable_mime_detection" => 0, "showrefresh" => 1, - "forceproxy" => 0 + "forceproxy" => 0, + "confirmoverwrite" => 1 ); private $config = array(); @@ -106,6 +107,7 @@ class IFM { $this->config['search'] = getenv('IFM_API_SEARCH') !== false ? intval( getenv('IFM_API_SEARCH') ) : $this->config['search'] ; $this->config['showrefresh'] = getenv('IFM_GUI_REFRESH') !== false ? intval( getenv('IFM_GUI_REFRESH') ) : $this->config['showrefresh'] ; $this->config['forceproxy'] = getenv('IFM_GUI_FORCEPROXY') !== false ? intval( getenv('IFM_GUI_FORCEPROXY') ) : $this->config['forceproxy'] ; + $this->config['confirmoverwrite'] = getenv('IFM_GUI_CONFIRMOVERWRITE') !== false ? intval( getenv('IFM_GUI_CONFIRMOVERWRITE') ) : $this->config['confirmoverwrite'] ; // optional settings if( getenv('IFM_SESSION_LIFETIME') !== false ) diff --git a/src/style.css b/src/style.css index 4afffc1..3c199d2 100644 --- a/src/style.css +++ b/src/style.css @@ -1,6 +1,7 @@ body { padding-top: 70px; overflow-y: scroll !important; + padding-right: 0px !important; } main { @@ -188,9 +189,6 @@ table.dataTable thead th.sorting_desc:after { overflow: auto; } -.modal-open { - padding-right: 0px !important; -} @media (min-width: 576px) { .modal-dialog {