WebUI: migrate to fetch API
[qBittorrent.git] / src / webui / www / private / rename_file.html
blob5333d4bb2dd52e365508c4d6460aef6d3ab3fac3
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
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/localpreferences.js?v=${CACHEID}"></script>
11 <script src="scripts/color-scheme.js?v=${CACHEID}"></script>
12 <script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
13 <script src="scripts/filesystem.js?v=${CACHEID}"></script>
14 <script>
15 "use strict";
17 window.addEventListener("DOMContentLoaded", () => {
18 window.addEventListener("keydown", (event) => {
19 switch (event.key) {
20 case "Enter":
21 event.preventDefault();
22 $("renameButton").click();
23 break;
24 case "Escape":
25 event.preventDefault();
26 window.parent.qBittorrent.Client.closeFrameWindow(window);
27 break;
29 });
31 const hash = new URI().getData("hash");
32 const oldPath = new URI().getData("path");
33 const isFolder = ((new URI().getData("isFolder")) === "true");
35 const oldName = window.qBittorrent.Filesystem.fileName(oldPath);
36 $("rename").value = oldName;
37 $("rename").focus();
38 if (!isFolder)
39 $("rename").setSelectionRange(0, oldName.lastIndexOf("."));
41 $("renameButton").addEventListener("click", (e) => {
42 e.preventDefault();
43 e.stopPropagation();
45 // check field
46 const newName = $("rename").value.trim();
47 if (newName === "") {
48 alert("QBT_TR(Name cannot be empty)QBT_TR[CONTEXT=HttpServer]");
49 return;
52 if (newName === oldName) {
53 alert("QBT_TR(Name is unchanged)QBT_TR[CONTEXT=HttpServer]");
54 return;
57 $("renameButton").disabled = true;
59 const parentPath = window.qBittorrent.Filesystem.folderName(oldPath);
60 const newPath = parentPath
61 ? parentPath + window.qBittorrent.Filesystem.PathSeparator + newName
62 : newName;
63 fetch((isFolder ? "api/v2/torrents/renameFolder" : "api/v2/torrents/renameFile"), {
64 method: "POST",
65 body: new URLSearchParams({
66 "hash": hash,
67 "oldPath": oldPath,
68 "newPath": newPath
71 .then((response) => {
72 if (!response.ok) {
73 alert("QBT_TR(Failed to update name)QBT_TR[CONTEXT=HttpServer]");
74 $("renameButton").disabled = false;
75 return;
78 window.parent.qBittorrent.Client.closeFrameWindow(window);
79 });
80 });
81 });
82 </script>
83 </head>
85 <body>
86 <div style="padding: 10px 10px 0px 10px;">
87 <label for="rename" style="font-weight: bold;">QBT_TR(New name:)QBT_TR[CONTEXT=TorrentContentTreeView]</label>
88 <input type="text" id="rename" style="width: 99%;">
89 <div style="text-align: center; padding-top: 10px;">
90 <input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="renameButton">
91 </div>
92 </div>
93 </body>
95 </html>