From ae5fb0f747cad73c612b8c98355d435ec5d18c67 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 13 Jun 2021 21:35:08 +1000 Subject: [PATCH] fixed 3 BUGS: BUG-31: can post move/del/restore DBoxes without highlighted files/content; BUG-33: can call move/del/restore on mixed content - prob. stop it? (e.g right-click from search with highlighted files in both Bin and non Bin locations); BUG-34: shift-clicking (left or right) from a non-highlighted state does not add the shift-clicked item. ALSO removed ability to right-click change sel... --- BUGs | 4 +-- templates/files.html | 78 +++++++++++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/BUGs b/BUGs index 513d5d6..5ac1131 100644 --- a/BUGs +++ b/BUGs @@ -1,3 +1 @@ -### Next: 34 -BUG-31: can post move/del/restore DBoxes without highlighted files/content -BUG-33: can call move/del/restore on mixed content - prob. stop it? (e.g right-click from search with highlighted files in both Bin and non Bin locations) +### Next: 35 diff --git a/templates/files.html b/templates/files.html index 6a0b1cb..73e6f68 100644 --- a/templates/files.html +++ b/templates/files.html @@ -46,12 +46,12 @@
- + {% if "files_rbp" in request.url %} - @@ -234,7 +234,6 @@ function GetSelnAsData() function DelDBox(del_or_undel) { - console.log(del_or_undel) to_del = GetSelnAsData() $('#dbox-title').html(del_or_undel+' Selected File(s)') div ='

' + del_or_undel + ' the following files?

' @@ -310,8 +309,6 @@ function ChangeSize(clicked_button,sz) // whether you click after highlight or before function DoSel(e, el) { - console.log(e) - console.log(el) if( e.ctrlKey ) { $(el).toggleClass('highlight') @@ -322,6 +319,12 @@ function DoSel(e, el) st=Number($('.highlight').first().attr('img')) end=Number($('.highlight').last().attr('img')) clicked=Number($(el).attr('img')) + // if we shift-click first element, then st/end are NaN, so just highlightthe one clicked + if( isNaN(st) ) + { + $('.figure').slice( clicked, clicked+1 ).addClass('highlight') + return + } if( clicked > end ) $('.figure').slice( end, clicked+1 ).addClass('highlight') else @@ -332,35 +335,58 @@ function DoSel(e, el) $(el).addClass('highlight') } -$('.figure').click( function(e) { DoSel(e, this ); return false; }); -$(document).on('click', function(e) { $('.highlight').removeClass('highlight') }); +function SetButtonState() { + var sel=false + $('.highlight').each(function( index ) { sel=true } ) + if( sel ) { + $('#move').attr('disabled', false ) + $('#del').attr('disabled', false ) + } else { + $('#move').attr('disabled', true ) + $('#del').attr('disabled', true ) + } +} + +function SelContainsBinAndNotBin() { + var bin=false + var not_bin=false + $('.highlight').each(function( index ) { + if( $(this).attr('path_type') == "Bin" ) { + bin=true + } else { + not_bin=true + } + } ) + if( bin && not_bin ) + return true + else + return false +} + +$('.figure').click( function(e) { DoSel(e, this ); SetButtonState(); return false; }); +$(document).on('click', function(e) { $('.highlight').removeClass('highlight') ; SetButtonState() }); $.contextMenu({ selector: '.figure', build: function($triggerElement, e){ - DoSel(e, e.currentTarget ) - if (e.currentTarget.getAttribute('path_type') == 'Bin' ) { - item_list = { - details: { name: "Details..." }, - view: { name: "View File" }, - sep: "---", - move: { name: "Move selected file(s) to new storage folder" }, - undel: { name: "Restore selected file(s)" } - } + var tst; + item_list = { + details: { name: "Details..." }, + view: { name: "View File" }, + sep: "---", + move: { name: "Move selected file(s) to new storage folder" } + } + if( SelContainsBinAndNotBin() ) { + item_list['both']= { name: 'Cannot delete and restore at same time', disabled: true } } else { - item_list = { - details: { name: "Details..." }, - view: { name: "View File" }, - sep: "---", - move: { name: "Move selected file(s) to new storage folder" }, - del: { name: "Delete Selected file(s)" } - } + if (e.currentTarget.getAttribute('path_type') == 'Bin' ) + item_list['undel']= { name: "Restore selected file(s)" } + else + item_list['del']= { name: "Delete Selected file(s)" } } return { callback: function( key, options) { - console.log( $(this).attr('id') ) - console.log( $(this).attr('path_type') ) if( key == "view" ) { document.location.href = $(this).find('a').attr('href'); } if( key == "move" ) { MoveDBox() } if( key == "del" ) { DelDBox('Delete') }