WebUI: Use Map instead of Mootools Hash in Torrents table
[qBittorrent.git] / src / webui / www / private / rename_file.html
blobbdb10aae33d735a26cab9e24fb0a83c742be5e04
1 <!DOCTYPE html>
2 <html lang="${LANG}">
4 <head>
5 <meta charset="UTF-8">
6 <title>QBT_TR(Renaming)QBT_TR[CONTEXT=TorrentContentTreeView]</title>
7 <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
8 <script src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
9 <script src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
10 <script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
11 <script src="scripts/filesystem.js?v=${CACHEID}"></script>
12 <script>
13 "use strict";
15 new Keyboard({
16 defaultEventType: "keydown",
17 events: {
18 "Enter": function(event) {
19 $("renameButton").click();
20 event.preventDefault();
22 "Escape": function(event) {
23 window.parent.qBittorrent.Client.closeWindows();
24 event.preventDefault();
26 "Esc": function(event) {
27 window.parent.qBittorrent.Client.closeWindows();
28 event.preventDefault();
31 }).activate();
33 window.addEventListener("DOMContentLoaded", () => {
34 const hash = new URI().getData("hash");
35 const oldPath = new URI().getData("path");
36 const isFolder = ((new URI().getData("isFolder")) === "true");
38 const oldName = window.qBittorrent.Filesystem.fileName(oldPath);
39 $("rename").value = oldName;
40 $("rename").focus();
41 if (!isFolder)
42 $("rename").setSelectionRange(0, oldName.lastIndexOf("."));
44 $("renameButton").addEventListener("click", (e) => {
45 e.preventDefault();
46 e.stopPropagation();
48 // check field
49 const newName = $("rename").value.trim();
50 if (newName === "") {
51 alert("QBT_TR(Name cannot be empty)QBT_TR[CONTEXT=HttpServer]");
52 return;
55 if (newName === oldName) {
56 alert("QBT_TR(Name is unchanged)QBT_TR[CONTEXT=HttpServer]");
57 return;
60 $("renameButton").disabled = true;
62 const parentPath = window.qBittorrent.Filesystem.folderName(oldPath);
63 const newPath = parentPath
64 ? parentPath + window.qBittorrent.Filesystem.PathSeparator + newName
65 : newName;
66 new Request({
67 url: isFolder ? "api/v2/torrents/renameFolder" : "api/v2/torrents/renameFile",
68 method: "post",
69 data: {
70 hash: hash,
71 oldPath: oldPath,
72 newPath: newPath
74 onSuccess: function() {
75 window.parent.qBittorrent.Client.closeWindows();
77 onFailure: function() {
78 alert("QBT_TR(Failed to update name)QBT_TR[CONTEXT=HttpServer]");
79 $("renameButton").disabled = false;
81 }).send();
82 });
83 });
84 </script>
85 </head>
87 <body>
88 <div style="padding: 10px 10px 0px 10px;">
89 <label for="rename" style="font-weight: bold;">QBT_TR(New name:)QBT_TR[CONTEXT=TorrentContentTreeView]</label>
90 <input type="text" id="rename" style="width: 99%;">
91 <div style="text-align: center; padding-top: 10px;">
92 <input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="renameButton">
93 </div>
94 </div>
95 </body>
97 </html>