WebUI: migrate to fetch API
[qBittorrent.git] / src / webui / www / private / setlocation.html
blobfee8d2f09804c951a9c9dd90ef9d84088630d63e
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
4 <head>
5 <meta charset="UTF-8">
6 <title>QBT_TR(Set location)QBT_TR[CONTEXT=HttpServer]</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>
14 "use strict";
16 window.addEventListener("DOMContentLoaded", () => {
17 window.addEventListener("keydown", (event) => {
18 switch (event.key) {
19 case "Enter":
20 event.preventDefault();
21 $("setLocationButton").click();
22 break;
23 case "Escape":
24 event.preventDefault();
25 window.parent.qBittorrent.Client.closeFrameWindow(window);
26 break;
28 });
30 const path = new URI().getData("path");
32 // set text field to current value
33 if (path)
34 $("setLocation").value = decodeURIComponent(path);
36 $("setLocation").focus();
37 $("setLocationButton").addEventListener("click", (e) => {
38 e.preventDefault();
39 e.stopPropagation();
41 // check field
42 const location = $("setLocation").value.trim();
43 if ((location === null) || (location === "")) {
44 $("error_div").textContent = "QBT_TR(Save path is empty)QBT_TR[CONTEXT=TorrentsController]";
45 return;
48 fetch("api/v2/torrents/setLocation", {
49 method: "POST",
50 body: new URLSearchParams({
51 "hashes": new URI().getData("hashes"),
52 "location": location
55 .then(async (response) => {
56 if (!response.ok) {
57 $("error_div").textContent = await response.text();
58 return;
61 window.parent.qBittorrent.Client.closeFrameWindow(window);
62 });
63 });
64 });
65 </script>
66 </head>
68 <body>
69 <div style="padding: 10px 10px 0px 10px;">
70 <label for="setLocation" style="font-weight: bold;">QBT_TR(Location:)QBT_TR[CONTEXT=TransferListWidget]</label>
71 <input type="text" id="setLocation" autocorrect="off" autocapitalize="none" style="width: 99%;">
72 <div style="float: none; width: 99%;" id="error_div">&nbsp;</div>
73 <div style="text-align: center; padding-top: 10px;">
74 <input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="setLocationButton">
75 </div>
76 </div>
77 </body>
79 </html>