mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-09 09:02:31 -06:00
Add ability to rename torrent files from the WebUI
Renaming folders is not yet supported. Closes #8892.
This commit is contained in:
90
src/webui/www/private/rename_file.html
Normal file
90
src/webui/www/private/rename_file.html
Normal 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>
|
||||
Reference in New Issue
Block a user