mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-10 01:22:31 -06:00
Improve content file/folder names handling
Move files/folders renaming functions to core classes. Query file/folder for renaming by its current path. Add ability to rename content folders from WebAPI/WebUI.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<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 src="scripts/filesystem.js?v=${CACHEID}"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
@@ -31,14 +32,15 @@
|
||||
|
||||
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 path = new URI().getData('path');
|
||||
const isFolder = ((new URI().getData('isFolder')) === 'true');
|
||||
|
||||
const decodedName = decodeURIComponent(name);
|
||||
$('rename').value = decodedName;
|
||||
const oldPath = decodeURIComponent(path);
|
||||
const oldName = window.qBittorrent.Filesystem.fileName(oldPath);
|
||||
$('rename').value = oldName;
|
||||
$('rename').focus();
|
||||
$('rename').setSelectionRange(0, decodedName.lastIndexOf('.'));
|
||||
if (!isFolder)
|
||||
$('rename').setSelectionRange(0, oldName.lastIndexOf('.'));
|
||||
|
||||
$('renameButton').addEvent('click', function(e) {
|
||||
new Event(e).stop();
|
||||
@@ -49,20 +51,24 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName === name) {
|
||||
if (newName === oldName) {
|
||||
alert('QBT_TR(Name is unchanged)QBT_TR[CONTEXT=HttpServer]');
|
||||
return;
|
||||
}
|
||||
|
||||
$('renameButton').disabled = true;
|
||||
|
||||
const parentPath = window.qBittorrent.Filesystem.folderName(oldPath)
|
||||
const newPath = parentPath
|
||||
? parentPath + window.qBittorrent.Filesystem.PathSeparator + newName
|
||||
: newName;
|
||||
new Request({
|
||||
url: 'api/v2/torrents/renameFile',
|
||||
url: isFolder ? 'api/v2/torrents/renameFolder' : 'api/v2/torrents/renameFile',
|
||||
method: 'post',
|
||||
data: {
|
||||
hash: hash,
|
||||
id: id,
|
||||
name: newName
|
||||
oldPath: oldPath,
|
||||
newPath: newPath
|
||||
},
|
||||
onSuccess: function() {
|
||||
window.parent.closeWindows();
|
||||
|
||||
Reference in New Issue
Block a user