Add ability to rename torrent files from the WebUI

Renaming folders is not yet supported. Closes #8892.
This commit is contained in:
Thomas Piccirello
2019-08-06 00:36:13 -07:00
parent 9fecd18293
commit 2bce9f6179
6 changed files with 171 additions and 1 deletions

View File

@@ -197,7 +197,8 @@
<li class="separator"><a href="#banPeer"><img src="images/qbt-theme/user-group-delete.svg" alt="QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]"/> QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]</a></li>
</ul>
<ul id="torrentFilesMenu" class="contextMenu">
<li>
<li><a href="#Rename"><img src="images/qbt-theme/edit-rename.svg" alt="QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]"/> QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]</a></li>
<li class="separator">
<a href="#FilePrio" class="arrow-right"><span style="display: inline-block; width: 16px;"></span> QBT_TR(Priority)QBT_TR[CONTEXT=PropertiesWidget]</a>
<ul>
<li><a href="#FilePrioIgnore"><span style="display: inline-block; width: 16px;"></span> QBT_TR(Do not download)QBT_TR[CONTEXT=PropListDelegate]</a></li>

View File

@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html lang="${LANG}">
<head>
<meta charset="UTF-8" />
<title>QBT_TR(Renaming)QBT_TR[CONTEXT=TorrentContentTreeView]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css" />
<script src="scripts/lib/mootools-1.2-core-yc.js"></script>
<script src="scripts/lib/mootools-1.2-more.js"></script>
<script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
<script>
'use strict';
new Keyboard({
defaultEventType: 'keydown',
events: {
'Enter': function(event) {
$('renameButton').click();
event.preventDefault();
},
'Escape': function(event) {
window.parent.closeWindows();
event.preventDefault();
},
'Esc': function(event) {
window.parent.closeWindows();
event.preventDefault();
}
}
}).activate();
window.addEvent('domready', function() {
const hash = new URI().getData('hash');
const name = new URI().getData('name');
const id = new URI().getData('id');
if (!hash || !name || !id) return;
const decodedName = decodeURIComponent(name);
$('rename').value = decodedName;
$('rename').focus();
$('rename').setSelectionRange(0, decodedName.indexOf('.'));
$('renameButton').addEvent('click', function(e) {
new Event(e).stop();
// check field
const newName = $('rename').value.trim();
if (newName === '') {
alert('QBT_TR(Name cannot be empty)QBT_TR[CONTEXT=HttpServer]');
return;
}
if (newName === name) {
alert('QBT_TR(Name is unchanged)QBT_TR[CONTEXT=HttpServer]');
return;
}
$('renameButton').disabled = true;
new Request({
url: 'api/v2/torrents/renameFile',
method: 'post',
data: {
hash: hash,
id: id,
name: newName
},
onSuccess: function() {
window.parent.closeWindows();
},
onFailure: function() {
alert('QBT_TR(Failed to update name)QBT_TR[CONTEXT=HttpServer]');
$('renameButton').disabled = false;
}
}).send();
});
});
</script>
</head>
<body>
<div style="padding: 10px 10px 0px 10px;">
<p style="font-weight: bold;">QBT_TR(New name:)QBT_TR[CONTEXT=TorrentContentTreeView]</p>
<input type="text" id="rename" value="" maxlength="100" style="width: 220px;" />
<div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="renameButton" />
</div>
</div>
</body>
</html>

View File

@@ -520,6 +520,33 @@ window.qBittorrent.PropFiles = (function() {
targets: '#torrentFilesTableDiv tr',
menu: 'torrentFilesMenu',
actions: {
Rename: function(element, ref) {
const hash = torrentsTable.getCurrentTorrentHash();
if (!hash) return;
const rowId = torrentFilesTable.selectedRowsIds()[0];
if (!rowId) return;
const row = torrentFilesTable.rows[rowId];
if (!row) return;
const node = torrentFilesTable.getNode(rowId);
if (node.isFolder) return;
const name = row.full_data.name;
const fileId = row.full_data.fileId;
new MochaUI.Window({
id: 'renamePage',
title: "QBT_TR(Renaming)QBT_TR[CONTEXT=TorrentContentTreeView]",
loadMethod: 'iframe',
contentURL: 'rename_file.html?hash=' + hash + '&id=' + fileId + '&name=' + encodeURIComponent(name),
scrollbars: false,
resizable: false,
maximizable: false,
paddingVertical: 0,
paddingHorizontal: 0,
width: 250,
height: 100
});
},
FilePrioIgnore: function(element, ref) {
filesPriorityMenuClicked(FilePriority.Ignored);
@@ -543,6 +570,13 @@ window.qBittorrent.PropFiles = (function() {
this.hideItem('FilePrio');
else
this.showItem('FilePrio');
const rowId = torrentFilesTable.selectedRowsIds()[0];
const node = torrentFilesTable.getNode(rowId);
if (node.isFolder)
this.hideItem('Rename');
else
this.showItem('Rename');
}
});