From 40705815affc99f86d4415b81cd0d8373333f081 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Thu, 16 Feb 2017 16:20:05 +0100 Subject: [PATCH 1/4] multiselect: add ability to select rows with ctrl+click --- ifm.php | 5 +++-- src/ifm.js | 8 ++++++-- src/style.css | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ifm.php b/ifm.php index 2a48a0f..5aad42c 100644 --- a/ifm.php +++ b/ifm.php @@ -289,6 +289,7 @@ div#content { width: 100%; height: 350px; } input[name=newperms] { width: 7em; } #filetable tr th.buttons { min-width: 95px; } +#filetable tr.clickable-row.active td { background-color: lightblue; } #navbar { max-width: 100%; } @@ -483,7 +484,7 @@ function IFM() { this.rebuildFileTable = function( data ) { var newRows = $(document.createElement('tbody')); for(i=0;i Date: Thu, 16 Feb 2017 16:28:33 +0100 Subject: [PATCH 2/4] consider multiselect permission --- ifm.php | 10 ++++++---- src/ifm.js | 14 ++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ifm.php b/ifm.php index 5aad42c..9a3a8c1 100644 --- a/ifm.php +++ b/ifm.php @@ -559,16 +559,18 @@ function IFM() { } $("#filetable tbody").remove(); $("#filetable").append(newRows); - // bind multiselect handler - if(self.config.multiselect == 1) { - $("input[name=multisel]").on("change", function(){ ifm.handleMultiSelect(); }); + if( self.config.multiselect == 1 ) { + $('.clickable-row').click(function(event) { + if( event.ctrlKey ) { + $(this).toggleClass('active'); + } + }); } $('a[data-toggle="tooltip"]').tooltip({ animated: 'fade', placement: 'right', html: true }); - $('.clickable-row').click(function(event) { if( event.ctrlKey ) $(this).toggleClass('active'); }); }; this.changeDirectory = function( newdir, options={ absolute: false, pushState: true } ) { diff --git a/src/ifm.js b/src/ifm.js index 5a00222..f45948f 100644 --- a/src/ifm.js +++ b/src/ifm.js @@ -131,20 +131,18 @@ function IFM() { } $("#filetable tbody").remove(); $("#filetable").append(newRows); - // bind multiselect handler - if(self.config.multiselect == 1) { - $("input[name=multisel]").on("change", function(){ ifm.handleMultiSelect(); }); + if( self.config.multiselect == 1 ) { + $('.clickable-row').click(function(event) { + if( event.ctrlKey ) { + $(this).toggleClass('active'); + } + }); } $('a[data-toggle="tooltip"]').tooltip({ animated: 'fade', placement: 'right', html: true }); - $('.clickable-row').click(function(event) { - if( event.ctrlKey ) { - $(this).toggleClass('active'); - } - }); }; this.changeDirectory = function( newdir, options={ absolute: false, pushState: true } ) { From aa21250a756046c02318c775958cea537968af96 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Thu, 16 Feb 2017 16:29:43 +0100 Subject: [PATCH 3/4] set allow to multiselect permission --- ifm.php | 2 +- src/config.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ifm.php b/ifm.php index 9a3a8c1..070978e 100644 --- a/ifm.php +++ b/ifm.php @@ -29,7 +29,7 @@ class IFMConfig { const zipnload = 1; // allow to zip and download directorys // view controls - const multiselect = 0; // implement multiselect of files and directories + const multiselect = 1; // implement multiselect of files and directories const showlastmodified = 0; // show the last modified date? const showfilesize = 1; // show filesize? const showowner = 1; // show file owner? diff --git a/src/config.php b/src/config.php index 6e16708..68c0d4d 100644 --- a/src/config.php +++ b/src/config.php @@ -29,7 +29,7 @@ class IFMConfig { const zipnload = 1; // allow to zip and download directorys // view controls - const multiselect = 0; // implement multiselect of files and directories + const multiselect = 1; // implement multiselect of files and directories const showlastmodified = 0; // show the last modified date? const showfilesize = 1; // show filesize? const showowner = 1; // show file owner? From 6264b33c019ec71f4bea8ec4c02954b0681ca4d1 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Thu, 16 Feb 2017 17:40:58 +0100 Subject: [PATCH 4/4] implemented multiselect (ctrl+click) and delete (del on keyboard) --- ifm.php | 64 ++++++++++++++++++++++-------------------------------- src/ifm.js | 64 ++++++++++++++++++++++-------------------------------- 2 files changed, 52 insertions(+), 76 deletions(-) diff --git a/ifm.php b/ifm.php index 070978e..6ae697e 100644 --- a/ifm.php +++ b/ifm.php @@ -453,13 +453,9 @@ function IFM() { .append( content ); modalDialog.append( modalContent ); modal.append( modalDialog ); - $( document.body ).prepend( modal ); + $( document.body ).append( modal ); modal.modal(); - modal.on( 'hide.bs.modal', function () { - self.fileChanged = false; - self.editor = null; - $( this ).remove(); - }); + modal.on('hide.bs.modal', function () { $(this).remove(); }); }; this.hideModal = function() { @@ -467,7 +463,6 @@ function IFM() { }; this.refreshFileTable = function () { - if(document.getElementById("multiseloptions"))$("#multiseloptions").remove(); var id=ifm.generateGuid(); ifm.task_add("Refresh", id); $.ajax({ @@ -484,19 +479,13 @@ function IFM() { this.rebuildFileTable = function( data ) { var newRows = $(document.createElement('tbody')); for(i=0;i'; if(data[i].type=="file") { - newrow += ''+multisel+'"'; newrow += '> '+data[i].name+''; } else { - newrow += ''+multisel+' '; + newrow += ' '; if( data[i].name == ".." ) newrow += "[ up ]"; else newrow += data[i].name; newrow += ''; @@ -959,16 +948,6 @@ function IFM() { { message: m }, { type: msgType, delay: 5000, mouse_over: 'pause', offset: { x: 15, y: 65 } } ); -// var message = '
'; -// $(document.body).prepend(message); -// $("#mess").delay(2000).fadeOut('slow'); -// setTimeout(function() { // remove the message from the DOM after 3 seconds -// $('#mess').remove(); -// }, 3000); }; this.pathCombine = function(a, b) { if(a == "" && b == "") return ""; @@ -990,8 +969,8 @@ function IFM() { this.hideSaveQuestion = function() { $("#savequestion").remove(); }; - this.handleMultiSelect = function() { - var amount = $("input[name=multisel]:checked").length; + this.handleMultiselect = function() { + var amount = $("#filetable tr.active").length; if(amount > 0) { if(document.getElementById("multiseloptions")===null) { $(document.body).prepend('
\ @@ -1010,21 +989,23 @@ function IFM() { $("#multiseloptions").remove(); } }; + this.multiDeleteDialog = function() { + var form = '
'; + self.showModal( form ); + }; this.multiDelete = function() { - var jel = $("input[name=multisel]:checked"); - if(jel.length == 0) { - ifm.showMessage("No files chosen"); - return; - } - var ids = []; - for(var i = 0; i < jel.length; i++) ids.push(jel[i].id); + var elements = $('#filetable tr.active'); + var filenames = []; + for(var i=0;typeof(elements[i])!='undefined';filenames.push(elements[i++].getAttribute('data-filename'))); $.ajax({ - url: ifm.IFM_SCFN, + url: self.IFM_SCFN, type: "POST", data: ({ api: "deleteMultipleFiles", - dir: ifm.currentDir, - filenames: ids + dir: self.currentDir, + filenames: filenames }), dataType: "json", success: function(data) { @@ -1077,6 +1058,12 @@ function IFM() { if( event.state && event.state.dir ) dir = event.state.dir; self.changeDirectory( dir, { pushState: false, absolute: true } ); }; + this.handleKeystrokes = function( event ) { + // bind 'del' key + if( event.keyCode == 127 && $('#filetable tr.active').length > 0 ) { + self.multiDeleteDialog(); + } + } // static button bindings and filetable initial filling this.init = function() { // bind static buttons @@ -1092,6 +1079,7 @@ function IFM() { $("#upload").click(function(){ self.uploadFileDialog(); }); + $(document).on( 'keypress', self.handleKeystrokes ); // handle history manipulation window.onpopstate = self.historyPopstateHandler; diff --git a/src/ifm.js b/src/ifm.js index f45948f..d07fa31 100644 --- a/src/ifm.js +++ b/src/ifm.js @@ -25,13 +25,9 @@ function IFM() { .append( content ); modalDialog.append( modalContent ); modal.append( modalDialog ); - $( document.body ).prepend( modal ); + $( document.body ).append( modal ); modal.modal(); - modal.on( 'hide.bs.modal', function () { - self.fileChanged = false; - self.editor = null; - $( this ).remove(); - }); + modal.on('hide.bs.modal', function () { $(this).remove(); }); }; this.hideModal = function() { @@ -39,7 +35,6 @@ function IFM() { }; this.refreshFileTable = function () { - if(document.getElementById("multiseloptions"))$("#multiseloptions").remove(); var id=ifm.generateGuid(); ifm.task_add("Refresh", id); $.ajax({ @@ -56,19 +51,13 @@ function IFM() { this.rebuildFileTable = function( data ) { var newRows = $(document.createElement('tbody')); for(i=0;i'; if(data[i].type=="file") { - newrow += ''+multisel+'"'; newrow += '> '+data[i].name+''; } else { - newrow += ''+multisel+' '; + newrow += ' '; if( data[i].name == ".." ) newrow += "[ up ]"; else newrow += data[i].name; newrow += ''; @@ -531,16 +520,6 @@ function IFM() { { message: m }, { type: msgType, delay: 5000, mouse_over: 'pause', offset: { x: 15, y: 65 } } ); -// var message = '
'; -// $(document.body).prepend(message); -// $("#mess").delay(2000).fadeOut('slow'); -// setTimeout(function() { // remove the message from the DOM after 3 seconds -// $('#mess').remove(); -// }, 3000); }; this.pathCombine = function(a, b) { if(a == "" && b == "") return ""; @@ -562,8 +541,8 @@ function IFM() { this.hideSaveQuestion = function() { $("#savequestion").remove(); }; - this.handleMultiSelect = function() { - var amount = $("input[name=multisel]:checked").length; + this.handleMultiselect = function() { + var amount = $("#filetable tr.active").length; if(amount > 0) { if(document.getElementById("multiseloptions")===null) { $(document.body).prepend('
\ @@ -582,21 +561,23 @@ function IFM() { $("#multiseloptions").remove(); } }; + this.multiDeleteDialog = function() { + var form = '
'; + self.showModal( form ); + }; this.multiDelete = function() { - var jel = $("input[name=multisel]:checked"); - if(jel.length == 0) { - ifm.showMessage("No files chosen"); - return; - } - var ids = []; - for(var i = 0; i < jel.length; i++) ids.push(jel[i].id); + var elements = $('#filetable tr.active'); + var filenames = []; + for(var i=0;typeof(elements[i])!='undefined';filenames.push(elements[i++].getAttribute('data-filename'))); $.ajax({ - url: ifm.IFM_SCFN, + url: self.IFM_SCFN, type: "POST", data: ({ api: "deleteMultipleFiles", - dir: ifm.currentDir, - filenames: ids + dir: self.currentDir, + filenames: filenames }), dataType: "json", success: function(data) { @@ -649,6 +630,12 @@ function IFM() { if( event.state && event.state.dir ) dir = event.state.dir; self.changeDirectory( dir, { pushState: false, absolute: true } ); }; + this.handleKeystrokes = function( event ) { + // bind 'del' key + if( event.keyCode == 127 && $('#filetable tr.active').length > 0 ) { + self.multiDeleteDialog(); + } + } // static button bindings and filetable initial filling this.init = function() { // bind static buttons @@ -664,6 +651,7 @@ function IFM() { $("#upload").click(function(){ self.uploadFileDialog(); }); + $(document).on( 'keypress', self.handleKeystrokes ); // handle history manipulation window.onpopstate = self.historyPopstateHandler;