Skip to content

Commit

Permalink
Fix torrent deleted without confirmation (Novik#2724)
Browse files Browse the repository at this point in the history
* Fix torrent deleted without confirmation

- This commit fixes an error that torrent(s) get deleted without
  confirmation, even if the option is checked in the options.
  Previously, the delete action worked as expected using the delete
  button in the top menu, asking for confirmation before taking
  actual action. However, using the "remove" option in the context
  menu or the `DEL` key on the keyboard would got the torrent(s)
  removed immediately. They were just not calling the correct
  remove function.
- Besides the correction of delete events handler, two other things
  were carried out by the way, although not on the scope of the
  entire app but just around the functions that were adjusted in
  this fix.
  1. Some ident related issues were picked out by the way, like
  mixing spaces with tabs on the same line.
  2. Documentations were added to some of the JS functions, according
  to my own understanding of the function. They might be incorrect,
  but can be polished while the project grows.

* Fix typo
  • Loading branch information
jevenski authored and koblack committed Nov 24, 2024
1 parent 84a98bf commit 281161f
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 226 deletions.
29 changes: 16 additions & 13 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ $.fn.extend(
}));
},

enableSysMenu: function()
{
return(this.on("contextmenu",function(e) { e.stopImmediatePropagation(); }).
on("selectstart",function(e) { e.stopImmediatePropagation(); return(true); }));
enableSysMenu: function() {
return this
.on("contextmenu", (e) => e.stopImmediatePropagation())
.on("selectstart", (e) => {e.stopImmediatePropagation(); return true;});
},

setCursorPosition: function(pos)
Expand Down Expand Up @@ -246,16 +246,19 @@ function escapeHTML(str)
return( String(str).split('&').join('&amp;').split('<').join('&lt;').split('>').join('&gt;') );
}

function askYesNo( title, content, funcYesName )
{
$("#yesnoDlg-header").html(title);
$("#yesnoDlg-content").html(content);
$("#yesnoOK").off('click');
$("#yesnoOK").on('click', function()
{
typeof(funcYesName)==="function" ? funcYesName() : eval(funcYesName);
/**
* Confirm again before taking action.
* @param {string} title Title of the dialog.
* @param {string} content Hint of the action to be confirmed.
* @param {Function | string} funcYesName Function to be executed if confirmed.
*/
function askYesNo(title, content, funcYesName) {
$("#yesnoDlg-header").text(title);
$("#yesnoDlg-content").text(content);
$("#yesnoOK").off('click').on('click', () => {
$type(funcYesName) === "function" ? funcYesName() : eval(funcYesName);
theDialogManager.hide("yesnoDlg");
return(false);
return false;
});
theDialogManager.show("yesnoDlg");
}
Expand Down
87 changes: 46 additions & 41 deletions js/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ var theContextMenu =
});
return(ret);
},
add: function()
{
add: function() {
var args = new Array();
$.each(arguments, function(ndx,val) { args.push(val); });
var aft = null;
Expand All @@ -355,55 +354,61 @@ var theContextMenu =
args.splice(0, 1);
}
var self = this;
$.each(args, function(ndx,val)
{
if($type(val))
{
var li = $("<li>").addClass("menuitem");
if(val[0] == CMENU_SEP)
$.each(args, function(ndx,val) {
if ($type(val)) {
const li = $("<li>").addClass("menuitem");
if (val[0] == CMENU_SEP)
li.append($("<hr>").addClass("menu-line"));
else
if(val[0] == CMENU_CHILD)
{
li.append( $("<a></a>").addClass("exp").text(val[1]) );
else if(val[0] == CMENU_CHILD) {
li.append( $("<a>").addClass("exp").text(val[1]) );
var ul = $("<ul>").addClass("CMenu");
for(var j = 0, len = val[2].length; j < len; j++)
{
for (var j = 0, len = val[2].length; j < len; j++) {
self.add(ul, val[2][j]);
}
li.append(ul);
}
else
if(val[0] == CMENU_SEL)
{
var a = $("<a></a>").addClass("sel menu-cmd").text(val[1]);
switch($type(val[2]))
{
case "string": a.attr("href","javascript://void();").on('click', function() { eval(val[2]) } ); break;
case "function": a.attr("href","javascript://void();").on('click', val[2]); break;
} else if(val[0] == CMENU_SEL) {
const a = $("<a>").addClass("sel menu-cmd").attr({href: "#"}).text(val[1]);
switch ($type(val[2])) {
case "string": {
a.on('click', () => eval(val[2]));
break;
}
case "function": {
a.on('click', val[2]);
break;
}
default: {
return;
}
}
li.append(a.on('focus', function() { this.blur(); } ));
}
else
{
if($type(val[0]))
{
var a = $("<a></a>").addClass("menu-cmd").text(val[0]);
switch($type(val[1]))
{
case false: a.addClass("dis"); break;
case "string": a.attr("href","javascript://void();").on('click', function() { eval(val[1]) } ); break;
case "function": a.attr("href","javascript://void();").on('click', val[1]); break;
li.append(
a.on('focus', (ev) => ev.target.blur()),
);
} else {
if ($type(val[0])) {
const a = $("<a>").addClass("menu-cmd").text(val[0]);
switch ($type(val[1])) {
case false: {
a.addClass("dis");
break;
}
case "string": {
a.attr({href:"#"}).on('click', () => eval(val[1]));
break;
}
case "function": {
a.attr({href:"#"}).on('click', val[1]);
break;
}
}
li.append(a.on('focus', function() { this.blur(); } ));
li.append(
a.on('focus', (ev) => ev.target.blur()),
);
}
}
if(aft)
aft.after(li);
else
o.append(li);
aft ? aft.after(li) : o.append(li);
}
});
});
},
clear: function()
{
Expand Down
11 changes: 4 additions & 7 deletions js/stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,11 @@ dxSTable.prototype.keyEvents = function(e)
if(!e.fromTextCtrl && !theDialogManager.isModalState())
{
var c = e.which;
if((browser.isKonqueror && c == 127) || (c == 46))
{
if($type(self.ondelete) == "function")
if((browser.isKonqueror && c == 127) || (c == 46)) {
// Delete key
if ($type(self.ondelete) === "function")
self.ondelete();
}
else
if(e.metaKey)
{
} else if (e.metaKey) {
switch(c)
{
case 65:
Expand Down
Loading

0 comments on commit 281161f

Please sign in to comment.